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));
            }
        }