public bool TryGetStrongGetterSetter <TOwner, TValue>(out IValueGetterSetter <TOwner, TValue> result) { if (this.PropertyType != PropertyType.Value) { result = null; return(false); } result = this.getterSetter as IValueGetterSetter <TOwner, TValue>; if (result != null) { return(true); } if (this.getterSetter.OwnerType.IsAssignableFrom(typeof(TOwner)) && this.getterSetter.ValueType.IsAssignableFrom(typeof(TValue))) { var type = typeof(AliasGetterSetter <, , ,>).MakeGenericType(typeof(TOwner), typeof(TValue), this.getterSetter.OwnerType, this.getterSetter.ValueType); result = (IValueGetterSetter <TOwner, TValue>)Activator.CreateInstance(type, this.getterSetter); return(true); } result = null; return(false); }
/// <summary> /// Initializes a new instance of the <see cref="AliasGetterSetter{TOwner, TValue, TPropertyOwner, TPropertyValue}"/> class. /// </summary> /// <param name="aliasedGetterSetter">The information.</param> /// <exception cref="System.ArgumentNullException">info</exception> public AliasGetterSetter(IValueGetterSetter <TPropertyOwner, TPropertyValue> aliasedGetterSetter) { if (aliasedGetterSetter == null) { throw new ArgumentNullException("info"); } this.aliasedGetterSetter = aliasedGetterSetter; }
/// <summary> /// <para>Tries to convert this property to a strongly typed <see cref="IValueGetterSetter{TOwner, TValue}" />.</para> /// <para>A polymorphic alias <see cref="AliasGetterSetter{TOwner, TValue, TPropertyOwner, TPropertyValue}" /> will be created if necessary.</para> /// </summary> /// <typeparam name="TOwner2">The type of the owner.</typeparam> /// <typeparam name="TValue2">The type of the value.</typeparam> /// <param name="getterSetter">The converted getter setter.</param> /// <returns>True if the conversion succeeded, otherwise false.</returns> public override bool TryConvertToGetterSetter <TOwner2, TValue2>(out IValueGetterSetter <TOwner2, TValue2> getterSetter) { if (typeof(TOwner) == typeof(TOwner2) && typeof(TValue) == typeof(TValue2)) { getterSetter = this as IValueGetterSetter <TOwner2, TValue2>; return(true); } if (typeof(TOwner).IsAssignableFrom(typeof(TOwner2)) && typeof(TValue).IsAssignableFrom(typeof(TValue2))) { getterSetter = new AliasGetterSetter <TOwner2, TValue2, TOwner, TValue>(this); return(true); } getterSetter = null; return(false); }
public static InspectorPropertyInfo CreateValue(string name, int order, SerializationBackend serializationBackend, IValueGetterSetter getterSetter, IEnumerable <Attribute> attributes) { if (name == null) { throw new ArgumentNullException("name"); } if (getterSetter == null) { throw new ArgumentNullException("getterSetter"); } if (name.Contains('.')) { throw new ArgumentException("Property names may not contain '.'; was given the name '" + name + "'."); } var result = new InspectorPropertyInfo(); result.memberInfos = new MemberInfo[0]; result.typeOfOwner = getterSetter.OwnerType; result.typeOfValue = getterSetter.ValueType; if (attributes == null) { result.attributes = new List <Attribute>(); } else { result.attributes = attributes.Where(attr => attr != null).ToList(); } result.PropertyName = name; result.PropertyType = PropertyType.Value; result.SerializationBackend = serializationBackend; result.IsEditable = !getterSetter.IsReadonly; result.getterSetter = getterSetter; return(result); }
public static InspectorPropertyInfo CreateValue(string name, int order, SerializationBackend serializationBackend, IValueGetterSetter getterSetter, params Attribute[] attributes) { return(CreateValue(name, order, serializationBackend, getterSetter, (IEnumerable <Attribute>)attributes)); }
/// <summary> /// Returns false and a null getter setter. /// </summary> /// <typeparam name="TOwner1">The type of the owner2.</typeparam> /// <typeparam name="TValue1">The type of the value.</typeparam> /// <param name="getterSetter">The getter setter.</param> /// <returns></returns> public override bool TryConvertToGetterSetter <TOwner1, TValue1>(out IValueGetterSetter <TOwner1, TValue1> getterSetter) { getterSetter = null; return(false); }