コード例 #1
0
        /// <summary>
        /// Create a property reference from an object target and reflection PropertyInfo.
        /// This represents a property on an object.
        /// </summary>
        public PropertyReference(object target, PropertyInfo property)
        {
            SRDebugUtil.AssertNotNull(target);
            SRDebugUtil.AssertNotNull(property);

            PropertyType = property.PropertyType;
            _property    = property;
            _target      = target;

#if NETFX_CORE
            if (_property.GetMethod != null && _property.GetMethod.IsPublic)
#else
            if (property.GetGetMethod() != null)
#endif
            {
                _getter = () => SRReflection.GetPropertyValue(target, property);
            }


#if NETFX_CORE
            if (_property.SetMethod != null && _property.SetMethod.IsPublic)
#else
            if (property.GetSetMethod() != null)
#endif
            {
                _setter = (v) => SRReflection.SetPropertyValue(target, property, v);
            }
        }
コード例 #2
0
 public void SetValue(object value)
 {
     if (_property.CanWrite)
     {
         SRReflection.SetPropertyValue(_target, _property, value);
     }
     else
     {
         throw new InvalidOperationException("Can not write to property");
     }
 }