public virtual IList<MethodDefinition> GetAccessors(object instance) { List<MethodDefinition> methods = new List<MethodDefinition>(); MethodInfo[] minfos = Type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (MethodInfo mi in minfos) { if (mi.Name.StartsWith("_get_") || mi.Name.StartsWith("_set_")) { MethodDefinition md = new MethodDefinition(mi.Name.Substring(1)); if (instance != null) { FastMethodCallDelegate d = FastMethodCallBuilder.Current.Build(mi); md.Body = delegate(IObject obj, object[] args) { // TODO: нужно этот делегат как-то вынести в метод, // только не понятно, как instance заморозить... object o = args[0] ?? instance; object[] args1 = (object[])args[1]; return d(o, args1); }; } methods.Add(md); } } return methods; }
protected virtual MethodDefinition InnerAddMethod(MethodDefinition method, bool riseEvent, bool replace) { if (method == null) return null; InnerMethods[method.Name] = method; if (method.DeclaredClass == null || method.DeclaredClass == "") method.DeclaredClass = (CopyExtensions) ? Name : InnerFullName; MethodDefinition res = InnerBehavior.AttachMethod(this, method); if (riseEvent) OnMethodListChanged(ListChangeType.Add, method); return res; }
public virtual MethodDefinition AddMethod(MethodDefinition method) { return InnerAddMethod(method, true, true); }