/// <summary>
        /// Initializes a new instance of the <see cref="InspectorValuePropertyInfo{TOwner, TValue}"/> class.
        /// </summary>
        /// <param name="propertyInfo">The property to represent.</param>
        /// <param name="serializationBackend">The serialization backend.</param>
        /// <param name="allowEditable">Whether the property can be editable.</param>
        public InspectorValuePropertyInfo(PropertyInfo propertyInfo, SerializationBackend serializationBackend, bool allowEditable)
            : base(propertyInfo, propertyInfo.PropertyType.IsValueType ? PropertyType.ValueType : PropertyType.ReferenceType, serializationBackend, allowEditable)

        {
            MemberAliasPropertyInfo aliasPropertyInfo = propertyInfo as MemberAliasPropertyInfo;

            if (aliasPropertyInfo != null)
            {
                propertyInfo = aliasPropertyInfo.AliasedProperty;
            }

            this.getter = EmitUtilities.CreateInstancePropertyGetter <TOwner, TValue>(propertyInfo);

            if (propertyInfo.CanWrite)
            {
                this.setter = EmitUtilities.CreateInstancePropertySetter <TOwner, TValue>(propertyInfo);
            }
        }
Beispiel #2
0
        private static ValueSetter <TOwner, TValue> GetCachedSetter(MemberInfo member)
        {
            Delegate del;

            if (GetterSetterCaches <TOwner> .Setters.TryGetInnerValue(member, typeof(TValue), out del))
            {
                return((ValueSetter <TOwner, TValue>)del);
            }
            else
            {
                ValueSetter <TOwner, TValue> result = null;

                var fieldInfo    = member as FieldInfo;
                var propertyInfo = member as PropertyInfo;

                if (fieldInfo != null)
                {
                    if (!fieldInfo.IsLiteral)
                    {
                        result = EmitUtilities.CreateInstanceFieldSetter <TOwner, TValue>(fieldInfo);
                    }
                }
                else if (propertyInfo != null)
                {
                    if (propertyInfo.CanWrite)
                    {
                        result = EmitUtilities.CreateInstancePropertySetter <TOwner, TValue>(propertyInfo);
                    }
                }
                else
                {
                    throw new ArgumentException("Cannot create a GetterSetter for a member of type + " + member.GetType().Name + "!");
                }

                GetterSetterCaches <TOwner> .Setters.AddInner(member, typeof(TValue), result);

                return(result);
            }
        }