private protected override void InitializeByRef(PropertyInfo propertyInfo, XBindingFlags flags) { base.InitializeByRef(propertyInfo, flags); declaringType = propertyInfo.DeclaringType; if (_get == null || _set == null) { var getMethod = propertyInfo.GetGetMethod((flags & XBindingFlags.NonPublic) != 0); if (getMethod != null) { var _ref = MethodHelper.CreateDelegate <XClassRefValueHandler <TValue> >(getMethod, false); _get = (obj) => { return(_ref(obj)); }; _set = (obj, value) => { _ref(obj) = value; }; } } }
private protected override void InitializeByRef(PropertyInfo propertyInfo, XBindingFlags flags) { base.InitializeByRef(propertyInfo, flags); declaringType = propertyInfo.DeclaringType; if (_get == null || _set == null) { var getMethod = propertyInfo.GetGetMethod((flags & XBindingFlags.NonPublic) != 0); if (getMethod != null) { var _ref = MethodHelper.CreateDelegate <XStructRefValueHandler <TStruct, TValue> >(getMethod, SignatureLevels.Cast); _get = (ref TStruct obj) => { return(_ref(ref obj)); }; _set = (ref TStruct obj, TValue value) => { _ref(ref obj) = value; }; } } }
private protected override void InitializeByValue(PropertyInfo propertyInfo, XBindingFlags flags) { base.InitializeByValue(propertyInfo, flags); declaringType = propertyInfo.DeclaringType; if (_get == null) { var getMethod = propertyInfo.GetGetMethod((flags & XBindingFlags.NonPublic) != 0); if (getMethod != null) { _get = MethodHelper.CreateDelegate <XClassGetValueHandler <TValue> >(getMethod, false); } } if (_set == null) { var setMethod = propertyInfo.GetSetMethod((flags & XBindingFlags.NonPublic) != 0); if (setMethod != null) { _set = MethodHelper.CreateDelegate <XClassSetValueHandler <TValue> >(setMethod, false); } } }
public XAttributedFieldRW(IXFieldRW fieldRW, RWFieldAttribute attribute, object firstArg, MethodInfo read, MethodInfo write) : base(fieldRW, attribute) { if (read.IsStatic) { this.read = MethodHelper.CreateDelegate <Func <IValueReader, T> >(read, SignatureLevels.Cast); } else { var _read = MethodHelper.CreateDelegate <Func <object, IValueReader, T> >(read, SignatureLevels.Cast); this.read = valueReader => _read(firstArg, valueReader); } if (write.IsStatic) { this.write = MethodHelper.CreateDelegate <Action <IValueWriter, T> >(write, SignatureLevels.Cast); } else { var _write = MethodHelper.CreateDelegate <Action <object, IValueWriter, T> >(write, SignatureLevels.Cast); this.write = (valueWriter, value) => _write(firstArg, valueWriter, value); } }
public XDelegateAttributedFieldRW(IXFieldRW fieldRW, RWFieldAttribute attribute, XBindingFlags flags, object firstArg, MethodInfo read, MethodInfo write) : base(fieldRW, attribute, flags) { if (read.IsStatic) { this.read = MethodHelper.CreateDelegate <Func <IValueReader, T> >(read, false); } else { var _read = MethodHelper.CreateDelegate <Func <object, IValueReader, T> >(read, false); this.read = valueReader => _read(firstArg, valueReader); } if (write.IsStatic) { this.write = MethodHelper.CreateDelegate <Action <IValueWriter, T> >(write, false); } else { var _write = MethodHelper.CreateDelegate <Action <object, IValueWriter, T> >(write, false); this.write = (valueWriter, value) => _write(firstArg, valueWriter, value); } }
internal XMethodInfo(MethodInfo methodInfo, XBindingFlags flags) { MethodInfo = methodInfo; Delegate = MethodHelper.CreateDelegate(methodInfo); declaringType = methodInfo.DeclaringType; }
internal XMethodInfo(MethodInfo methodInfo, XBindingFlags flags) { MethodInfo = methodInfo; Delegate = MethodHelper.CreateDelegate(methodInfo); declaringType = methodInfo.DeclaringType; declaringTypeHandle = TypeHelper.GetTypeHandle(declaringType); declaringTypeIsValueType = declaringType.IsValueType; }
XMethodInfo(MethodInfo methodInfo, XBindingFlags flags) { MethodInfo = methodInfo; Delegate = MethodHelper.CreateDelegate(methodInfo); firstParameterType = MethodInfo.IsStatic ? MethodInfo.GetParameters().FirstOrDefault()?.ParameterType : MethodInfo.DeclaringType; }
XIndexerInfo(PropertyInfo propertyInfo, XBindingFlags flags) { Flags = flags; PropertyInfo = propertyInfo; if (propertyInfo.GetGetMethod((flags & XBindingFlags.NonPublic) != 0) is var getMethod) { GetValueDelegate = MethodHelper.CreateDelegate(getMethod); } if (propertyInfo.GetSetMethod((flags & XBindingFlags.NonPublic) != 0) is var setMethod) { SetValueDelegate = MethodHelper.CreateDelegate(setMethod); } }
internal override void Initialize(PropertyInfo propertyInfo, XBindingFlags flags) { base.Initialize(propertyInfo, flags); var getMethod = propertyInfo.GetGetMethod((flags & XBindingFlags.NonPublic) != 0); var setMethod = propertyInfo.GetSetMethod((flags & XBindingFlags.NonPublic) != 0); if (getMethod != null) { _get = MethodHelper.CreateDelegate <XStaticGetValueHandler <TValue> >(getMethod, SignatureLevels.Cast); } if (setMethod != null) { _set = MethodHelper.CreateDelegate <XStaticSetValueHandler <TValue> >(setMethod, SignatureLevels.Cast); } }
internal override void InitializeByRef(PropertyInfo propertyInfo, XBindingFlags flags) { base.InitializeByRef(propertyInfo, flags); var getMethod = propertyInfo.GetGetMethod((flags & XBindingFlags.NonPublic) != 0); if (getMethod != null) { var _ref = MethodHelper.CreateDelegate <XStaticRefValueHandler <TValue> >(getMethod, SignatureLevels.Cast); _get = () => { return(_ref()); }; _set = (value) => { _ref() = value; }; } }
XIndexerInfo(PropertyInfo propertyInfo, XBindingFlags flags) { this.flags = flags; declaringType = propertyInfo.DeclaringType; PropertyInfo = propertyInfo; var getMethod = propertyInfo.GetGetMethod((flags & XBindingFlags.NonPublic) != 0); var setMethod = propertyInfo.GetSetMethod((flags & XBindingFlags.NonPublic) != 0); if (getMethod != null) { GetValueDelegate = MethodHelper.CreateDelegate(getMethod); } if (setMethod != null) { SetValueDelegate = MethodHelper.CreateDelegate(getMethod); } }
private protected override void InitializeByValue(PropertyInfo propertyInfo, XBindingFlags flags) { base.InitializeByValue(propertyInfo, flags); if ((flags & XBindingFlags.RWAutoPropertyDirectRW) != 0 && TypeHelper.IsAutoProperty(propertyInfo, out var fieldInfo) && fieldInfo != null) { try { var offset = TypeHelper.OffsetOf(fieldInfo); _get = (obj) => Underlying.AddByteOffset(ref TypeHelper.Unbox <TValue>(obj), offset); _set = (obj, value) => Underlying.AddByteOffset(ref TypeHelper.Unbox <TValue>(obj), offset) = value; return; } catch { } } if (_get is null) { var getMethod = propertyInfo.GetGetMethod((flags & XBindingFlags.NonPublic) != 0); if (getMethod != null) { _get = MethodHelper.CreateDelegate <XClassGetValueHandler <TClass, TValue> >(getMethod, false); } } if (_set is null) { var setMethod = propertyInfo.GetSetMethod((flags & XBindingFlags.NonPublic) != 0); if (setMethod != null) { _set = MethodHelper.CreateDelegate <XClassSetValueHandler <TClass, TValue> >(setMethod, false); } } }
internal override void InitializeByRef(PropertyInfo propertyInfo, XBindingFlags flags) { base.InitializeByRef(propertyInfo, flags); declaringType = propertyInfo.DeclaringType; declaringTypeHandle = TypeHelper.GetTypeHandle(declaringType); var getMethod = propertyInfo.GetGetMethod((flags & XBindingFlags.NonPublic) != 0); if (getMethod != null) { var _ref = MethodHelper.CreateDelegate <XClassRefValueHandler <TValue> >(getMethod, SignatureLevels.Cast); _get = (obj) => { return(_ref(obj)); }; _set = (obj, value) => { _ref(obj) = value; }; } }
private protected override void InitializeByValue(PropertyInfo propertyInfo, XBindingFlags flags) { base.InitializeByValue(propertyInfo, flags); if ((flags & XBindingFlags.RWAutoPropertyDirectRW) != 0 /* || !VersionDifferences.IsSupportEmit */) { if (TypeHelper.IsAutoProperty(propertyInfo, out var fieldInfo) && fieldInfo != null) { try { var offset = TypeHelper.OffsetOf(fieldInfo); _get = (ref TStruct obj) => Underlying.AddByteOffset(ref Underlying.As <TStruct, TValue>(ref obj), offset); _set = (ref TStruct obj, TValue value) => Underlying.AddByteOffset(ref Underlying.As <TStruct, TValue>(ref obj), offset) = value; return; } catch { } } } if (_get is null) { var getMethod = propertyInfo.GetGetMethod((flags & XBindingFlags.NonPublic) != 0); if (getMethod != null) { var __get = MethodHelper.CreateDelegate <GetValueHandler>(getMethod); _get = VersionDifferences.IsSupportEmit ? __get : AOTCheck; TValue AOTCheck(ref TStruct obj) { try { return(__get(ref obj)); } catch (ExecutionEngineException) { __get = AOT; return(AOT(ref obj)); } finally { _get = __get; } } TValue AOT(ref TStruct obj) { fixed(byte *ptr = &Underlying.As <TStruct, byte>(ref obj)) { return((TValue)getMethod.Invoke(TypeHelper.CamouflageBox(ptr), null)); } } } } if (_set is null) { var setMethod = propertyInfo.GetSetMethod((flags & XBindingFlags.NonPublic) != 0); if (setMethod != null) { var __set = (SetValueHandler)Delegate.CreateDelegate(typeof(SetValueHandler), setMethod); _set = VersionDifferences.IsSupportEmit ? __set : AOTCheck; void AOTCheck(ref TStruct obj, TValue value) { try { __set(ref obj, value); } catch (ExecutionEngineException) { __set = AOT; AOT(ref obj, value); } finally { _set = __set; } } void AOT(ref TStruct obj, TValue value) { fixed(byte *ptr = &Underlying.As <TStruct, byte>(ref obj)) { setMethod.Invoke(TypeHelper.CamouflageBox(ptr), new object[] { value }); } } } } }