/// <summary> /// Initializes a new instance of the <see cref="FieldAccessor"/> class. /// </summary> /// <param name="fieldInfo">The <see cref="FieldInfo"/> instance to use for this accessor.</param> public FieldAccessor(FieldInfo fieldInfo) { _fieldInfo = fieldInfo; _name = fieldInfo.Name; _memberType = fieldInfo.FieldType; _hasGetter = true; _lateBoundGet = new Lazy <LateBoundGet>(() => DelegateFactory.CreateGet(_fieldInfo)); _hasSetter = !fieldInfo.IsInitOnly && !fieldInfo.IsLiteral; if (_hasSetter) { _lateBoundSet = new Lazy <LateBoundSet>(() => DelegateFactory.CreateSet(_fieldInfo)); } }
/// <summary> /// Initializes a new instance of the <see cref="PropertyAccessor"/> class. /// </summary> /// <param name="propertyInfo">The <see cref="PropertyInfo"/> instance to use for this accessor.</param> public PropertyAccessor(PropertyInfo propertyInfo) { if (propertyInfo == null) { throw new ArgumentNullException(nameof(propertyInfo)); } _propertyInfo = propertyInfo; Name = _propertyInfo.Name; MemberType = _propertyInfo.PropertyType; HasGetter = _propertyInfo.CanRead; _getter = new Lazy <Func <object, object> >(() => DelegateFactory.CreateGet(_propertyInfo)); HasSetter = _propertyInfo.CanWrite; _setter = new Lazy <Action <object, object> >(() => DelegateFactory.CreateSet(_propertyInfo)); }
/// <summary> /// Initializes a new instance of the <see cref="PropertyAccessor"/> class. /// </summary> /// <param name="propertyInfo">The <see cref="PropertyInfo"/> instance to use for this accessor.</param> public PropertyAccessor(PropertyInfo propertyInfo) { _propertyInfo = propertyInfo; _name = _propertyInfo.Name; _memberType = _propertyInfo.PropertyType; _hasGetter = _propertyInfo.CanRead; if (_hasGetter) { _lateBoundGet = new Lazy <LateBoundGet>(() => DelegateFactory.CreateGet(_propertyInfo)); } _hasSetter = _propertyInfo.CanWrite; if (_hasSetter) { _lateBoundSet = new Lazy <LateBoundSet>(() => DelegateFactory.CreateSet(_propertyInfo)); } }
/// <summary> /// Initializes a new instance of the <see cref="FieldAccessor"/> class. /// </summary> /// <param name="fieldInfo">The <see cref="FieldInfo"/> instance to use for this accessor.</param> public FieldAccessor(FieldInfo fieldInfo) { if (fieldInfo == null) { throw new ArgumentNullException(nameof(fieldInfo)); } _fieldInfo = fieldInfo; Name = fieldInfo.Name; MemberType = fieldInfo.FieldType; _getter = new Lazy <Func <object, object> >(() => DelegateFactory.CreateGet(_fieldInfo)); HasGetter = true; bool isReadonly = !fieldInfo.IsInitOnly && !fieldInfo.IsLiteral; if (!isReadonly) { _setter = new Lazy <Action <object, object> >(() => DelegateFactory.CreateSet(_fieldInfo)); } HasSetter = !isReadonly; }