Example #1
0
        /// <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));
            }
        }
Example #2
0
        /// <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));
            }
        }