1: /// <summary>
2: /// Invokes the ex.
3: /// </summary>
4: /// <param name="so">The so.</param>
5: /// <param name="methodPath">The method path.</param>
6: /// <param name="args">The args.</param>
7: /// <returns></returns>
8: public static object InvokeEx(this ScriptObject so, string methodPath, params object [] args)
9: {
10: IEnumerable<string> parts = Parse(methodPath);
11:
12: foreach (string part in parts)
13: {
14: if (part != parts.Last())
15: so = (ScriptObject)so.GetProperty(part);
16: else
17: return so.Invoke(part, args);
18: }
19:
20: throw new ArgumentException("methodPath");
21: }
22:
23: /// <summary>
24: /// Gets the property ex.
25: /// </summary>
26: /// <param name="so">The so.</param>
27: /// <param name="propertyPath">The property path.</param>
28: /// <returns></returns>
29: public static ScriptObject GetPropertyEx(this ScriptObject so, string propertyPath)
30: {
31: IEnumerable<string> parts = Parse(propertyPath);
32:
33: foreach (string part in parts)
34: so = (ScriptObject)so.GetProperty(part);
35:
36: return so;
37: }
38:
39: /// <summary>
40: /// Parses the specified path.
41: /// </summary>
42: /// <param name="path">The path.</param>
43: /// <returns></returns>
44: private static IEnumerable<string> Parse(string path)
45: {
46: Match match = Regex.Match(path, @"(?<part>[^\.]*)(\.(?<part>[^\.]*))*");
47:
48: if (match.Success)
52: return from Capture cp in match.Groups["part"].Captures
53: select cp.Value;
55:
56: throw new ApplicationException(string.Format("Unable to parse path '{0}'}", path));
57: }