public override object[] Call(params object[] args) { if (args != null && args.Length > 0) { var del = args[0]; ClrEventWrapper.RemoveHandler(_Binder, del); return(new[] { this }); } return(null); }
public object GetFieldFor(object tar, object key) { if (_BindingType == null) { return(null); } tar = tar.UnwrapDynamic(); key = key.UnwrapDynamic(); var fields = _ExpandedFields; if (tar == null) { fields = _StaticFields; } object finfo = null; if (key is string) { finfo = GetFieldDescFor(tar, key as string); if (finfo is PropertyInfo) { var pmethod = ((PropertyInfo)finfo).GetGetMethod(); if (pmethod != null) { try { //return ((PropertyInfo)finfo).GetValue(tar, null).WrapDynamic(); var args = ObjectPool.GetParamsFromPool(0); var rv = pmethod.Invoke(tar, args); ObjectPool.ReturnParamsToPool(args); return(rv); } catch { if (GLog.IsLogErrorEnabled) { GLog.LogError("Unable to get property: " + key); } throw; } } else { return(null); } } else if (finfo is FieldInfo) { return(((FieldInfo)finfo).GetValue(tar)); } else if (finfo is ICallableCore) { var core = finfo as ICallableCore; var callable = ClrCallable.GetFromPool(core, tar); return(callable); } else if (finfo is EventInfo) { return(ClrEventWrapper.GetFromPool(finfo as EventInfo, tar)); } } if (finfo == null) { object indexmethod = null; if (fields.TryGetValue("get_Item", out indexmethod)) { if (indexmethod is ICallableCore) { var callable = ClrCallable.GetFromPool((ICallableCore)indexmethod, tar); var rv = callable.Call(key); callable.ReturnToPool(); if (rv != null && rv.Length > 0) { return(rv[0]); } } } else if (tar is IList) { // special treat to array. var ikey = key.ConvertType(typeof(int)); if (ikey != null) { try { var rv = ((IList)tar)[(int)ikey]; return(rv); } catch { } } } } return(finfo); }