void InitializeAccessor() { if (Member is PropertyInfo) { pInfo = (PropertyInfo)Member; #if NET472 || NETCOREAPP2_1 getter = EmitHelper.CreatePropertyGetterHandler(pInfo); if (pInfo.SetMethod != null) { setter = EmitHelper.CreatePropertySetterHandler(pInfo); } #endif } else { fInfo = (FieldInfo)Member; if (fInfo.IsLiteral) { #if NET472 || NETCOREAPP2_1 var value = fInfo.GetValue(null); getter = (x) => value; #endif } else { #if NET472 || NETCOREAPP2_1 getter = EmitHelper.CreateFieldGetterHandler(fInfo); setter = EmitHelper.CreateFieldSetterHandler(fInfo); #endif } } }
internal void SetMember(MemberInfo mi) { if (mi is PropertyInfo) { var pi = (PropertyInfo)mi; #if __NET__ || __NETCORE__ getter = EmitHelper.CreatePropertyGetterHandler(pi); if (pi.SetMethod != null) { setter = EmitHelper.CreatePropertySetterHandler(pi); switch (Type.Kind) { case PrimitiveType.Guid: hasFastSetter = true; setterGuid = EmitHelper.CreatePropertySetter <Guid>(pi); break; case PrimitiveType.Bool: hasFastSetter = true; setterBool = EmitHelper.CreatePropertySetter <bool>(pi); break; case PrimitiveType.Char: hasFastSetter = true; setterChar = EmitHelper.CreatePropertySetter <char>(pi); break; case PrimitiveType.Byte: hasFastSetter = true; setterByte = EmitHelper.CreatePropertySetter <byte>(pi); break; case PrimitiveType.SByte: hasFastSetter = true; setterSByte = EmitHelper.CreatePropertySetter <sbyte>(pi); break; case PrimitiveType.Int16: hasFastSetter = true; setterInt16 = EmitHelper.CreatePropertySetter <short>(pi); break; case PrimitiveType.UInt16: hasFastSetter = true; setterUInt16 = EmitHelper.CreatePropertySetter <ushort>(pi); break; case PrimitiveType.Int32: hasFastSetter = true; setterInt32 = EmitHelper.CreatePropertySetter <int>(pi); break; case PrimitiveType.UInt32: hasFastSetter = true; setterUInt32 = EmitHelper.CreatePropertySetter <uint>(pi); break; case PrimitiveType.Int64: hasFastSetter = true; setterInt64 = EmitHelper.CreatePropertySetter <long>(pi); break; case PrimitiveType.UInt64: hasFastSetter = true; setterUInt64 = EmitHelper.CreatePropertySetter <ulong>(pi); break; case PrimitiveType.Single: hasFastSetter = true; setterSingle = EmitHelper.CreatePropertySetter <float>(pi); break; case PrimitiveType.Double: hasFastSetter = true; setterDouble = EmitHelper.CreatePropertySetter <double>(pi); break; case PrimitiveType.Decimal: hasFastSetter = true; setterDecimal = EmitHelper.CreatePropertySetter <decimal>(pi); break; } } #else pInfo = pi; #endif } else { var fi = (FieldInfo)mi; if (fi.IsLiteral) { #if __NET__ || __NETCORE__ var value = fi.GetValue(null); getter = (x) => value; #else fInfo = fi; #endif } else { #if __NET__ || __NETCORE__ getter = EmitHelper.CreateFieldGetterHandler(fi); setter = EmitHelper.CreateFieldSetterHandler(fi); switch (Type.Kind) { case PrimitiveType.Guid: hasFastSetter = true; setterGuid = EmitHelper.CreateFieldSetter <Guid>(fi); break; case PrimitiveType.Bool: hasFastSetter = true; setterBool = EmitHelper.CreateFieldSetter <bool>(fi); break; case PrimitiveType.Char: hasFastSetter = true; setterChar = EmitHelper.CreateFieldSetter <char>(fi); break; case PrimitiveType.Byte: hasFastSetter = true; setterByte = EmitHelper.CreateFieldSetter <byte>(fi); break; case PrimitiveType.SByte: hasFastSetter = true; setterSByte = EmitHelper.CreateFieldSetter <sbyte>(fi); break; case PrimitiveType.Int16: hasFastSetter = true; setterInt16 = EmitHelper.CreateFieldSetter <short>(fi); break; case PrimitiveType.UInt16: hasFastSetter = true; setterUInt16 = EmitHelper.CreateFieldSetter <ushort>(fi); break; case PrimitiveType.Int32: hasFastSetter = true; setterInt32 = EmitHelper.CreateFieldSetter <int>(fi); break; case PrimitiveType.UInt32: hasFastSetter = true; setterUInt32 = EmitHelper.CreateFieldSetter <uint>(fi); break; case PrimitiveType.Int64: hasFastSetter = true; setterInt64 = EmitHelper.CreateFieldSetter <long>(fi); break; case PrimitiveType.UInt64: hasFastSetter = true; setterUInt64 = EmitHelper.CreateFieldSetter <ulong>(fi); break; case PrimitiveType.Single: hasFastSetter = true; setterSingle = EmitHelper.CreateFieldSetter <float>(fi); break; case PrimitiveType.Double: hasFastSetter = true; setterDouble = EmitHelper.CreateFieldSetter <double>(fi); break; case PrimitiveType.Decimal: hasFastSetter = true; setterDecimal = EmitHelper.CreateFieldSetter <decimal>(fi); break; } #else fInfo = fi; #endif } } }