static public TEntity GenEntityProxy2 <TEntity>(Func <string, object> getPropertyValue, Action <string, object> setPropertyValue) { GetPropertyDelegate getDelegate = new GetPropertyDelegate((methodInfo, propertyName) => CommonExtension.ToObject(getPropertyValue(propertyName), methodInfo.ReturnType)); SetPropertyDelegate setDelegate = new SetPropertyDelegate((methodInfo, propertyName, value) => setPropertyValue(propertyName, value)); return(GenEntityProxy <TEntity>(getDelegate, setDelegate)); }
static public TEntity GenEntityProxy <TEntity>(GetPropertyDelegate getPropertyValue, SetPropertyDelegate setPropertyValue) { RealProxy <TEntity> realProxy = new RealProxy <TEntity>(); realProxy.GetPropertyEvent += getPropertyValue; realProxy.SetPropertyEvent += setPropertyValue; return(realProxy.Entity); }
private CustomViewRegistry() { _createCallback = new CreateControlDelegate(CreateControl); _getPropertyCallback = new GetPropertyDelegate(GetProperty); _setPropertyCallback = new SetPropertyDelegate(SetProperty); _constructorMap = new Dictionary <string, Func <CustomView> >(); _propertyRangeManager = new PropertyRangeManager(); }
public PropertyInvoker(object obj, string propertyName) { name = propertyName; string getter = "get_" + propertyName; string setter = "set_" + propertyName; Get = (GetPropertyDelegate <T>)Delegate.CreateDelegate(typeof(GetPropertyDelegate <T>), obj, getter); Set = (SetPropertyDelegate <T>)Delegate.CreateDelegate(typeof(SetPropertyDelegate <T>), obj, setter); }
static public TEntity GenEntityProxy <TEntity>(this DataRow it) { GetPropertyDelegate getMethod = (x, y) => y; return(RealProxyGen.GenEntityProxy <TEntity> ( (methodInfo, name) => DoGetPropertyValue(methodInfo, it[name]), (methodInfo, name, value) => it[name] = value )); }
/// <summary> /// 从目标中获取属性的值 /// </summary> /// <param name="target">目标对象.</param> /// <returns>属性值</returns> public object Get(object target) { if (_PropertyInfo.CanRead) { if (_GetDelegate == null) { _GetDelegate = getPropertyorValue(_PropertyInfo); } return(_GetDelegate.Invoke(target)); } else { throw new DynamicPropertyAccessorException( string.Format("属性 \"{0}\" 不存在一个 GET 方法.", _PropertyInfo.Name)); } }
/// <summary> /// Does magic cross thread stuff, mostly used for to get property values in background threads. /// </summary> /// <param name="control">Control that might be on a different Thread</param> /// <param name="propertyName">Method or Property to get the value of</param> /// <returns></returns> public static object GetProperty(Control control, string propertyName) { if (control.InvokeRequired) { GetPropertyDelegate d = GetProperty; return(control.Invoke(d, control, propertyName)); } var property = control.GetType().GetProperty(propertyName); if (property == null) { throw new Exception( $"Could not find Property {propertyName} on {control.GetType()}"); } //Get Property return(property.GetValue(control)); }
static SecuredReflectionMethods() { if (!SecuredReflection.HasReflectionPermission) { if (!ProfilerInterceptor.IsProfilerAttached) { ProfilerInterceptor.ThrowElevatedMockingException(); } ProfilerInterceptor.CreateDelegateFromBridge("ReflectionInvoke", out Invoke); ProfilerInterceptor.CreateDelegateFromBridge("ReflectionGetProperty", out GetProperty); ProfilerInterceptor.CreateDelegateFromBridge("ReflectionSetProperty", out SetProperty); ProfilerInterceptor.CreateDelegateFromBridge("ReflectionGetField", out GetField); ProfilerInterceptor.CreateDelegateFromBridge("ReflectionSetField", out SetField); } else { Invoke = (method, instance, args) => method.Invoke(instance, args); GetProperty = (prop, instance, indexArgs) => prop.GetValue(instance, indexArgs); SetProperty = (prop, instance, value, indexArgs) => prop.SetValue(instance, value, indexArgs); GetField = (field, instance) => field.GetValue(instance); SetField = (field, instance, value) => field.SetValue(instance, value); } }
static SecuredReflectionMethods() { if (!SecuredReflection.HasReflectionPermission) { if (!ProfilerInterceptor.IsProfilerAttached) ProfilerInterceptor.ThrowElevatedMockingException(); ProfilerInterceptor.CreateDelegateFromBridge("ReflectionInvoke", out Invoke); ProfilerInterceptor.CreateDelegateFromBridge("ReflectionGetProperty", out GetProperty); ProfilerInterceptor.CreateDelegateFromBridge("ReflectionSetProperty", out SetProperty); ProfilerInterceptor.CreateDelegateFromBridge("ReflectionGetField", out GetField); ProfilerInterceptor.CreateDelegateFromBridge("ReflectionSetField", out SetField); } else { Invoke = (method, instance, args) => method.Invoke(instance, args); GetProperty = (prop, instance, indexArgs) => prop.GetValue(instance, indexArgs); SetProperty = (prop, instance, value, indexArgs) => prop.SetValue(instance, value, indexArgs); GetField = (field, instance) => field.GetValue(instance); SetField = (field, instance, value) => field.SetValue(instance, value); } }
static extern void gtksharp_override_property_handlers(IntPtr type, GetPropertyDelegate get_cb, SetPropertyDelegate set_cb);
public GetPropertyFunction(GetPropertyDelegate del) { Property = del; }
public bool AddField <TMember>(int hash, SetPropertyDelegate <T, TMember> set, GetPropertyDelegate <T, TMember> get) { if (set == null) { throw new ArgumentNullException(nameof(set)); } if (get == null) { throw new ArgumentNullException(nameof(get)); } var memberType = typeof(TMember); if (Serializer.TryGetDataSerializer(memberType, out var methods, false) == false) { _serializer.Logger.Error($"{typeof(T)} custom serializer, cannot get serialization methods for field of type {memberType}"); return(false); } var toAdd = new MemberSerializerStruct(hash, new PropertyWriter <T, TMember>(methods, set, get)); Add(toAdd); return(true); }
public PropertyWriter(DataSerializer dataSerializer, SetPropertyDelegate <T, TMember> set, GetPropertyDelegate <T, TMember> get) { _set = set; _get = get; _dataSerializer = dataSerializer; }
static extern void gtksharp_override_property_handlers (IntPtr type, GetPropertyDelegate get_cb, SetPropertyDelegate set_cb);
static void OverridePropertyHandlers(GType gtype, GetPropertyDelegate get_cb, SetPropertyDelegate set_cb) { IntPtr class_ptr = gtype.ClassPtr; GObjectClass klass = (GObjectClass) Marshal.PtrToStructure (class_ptr, typeof (GObjectClass)); klass.get_prop_cb = get_cb; klass.set_prop_cb = set_cb; Marshal.StructureToPtr (klass, class_ptr, false); }
public GetPropertyInstance(SkryptEngine engine, GetPropertyDelegate property) : base(engine) { Property = new GetPropertyFunction(property); }