/// <summary> /// Converts the given object to a <see cref="PropertyInfoAdapter"/>, using the specified context and culture information. /// </summary> /// <param name="context">An <see cref="System.ComponentModel.ITypeDescriptorContext"/> that provides a format context. Ignored by this /// implementation</param> /// <param name="culture">The <see cref="System.Globalization.CultureInfo"/> to use as the current culture. Ignored by this implementation</param> /// <param name="value">The <see cref="System.Object"/> to convert. Must be a <see cref="PropertyInfo"/> value.</param> /// <returns> /// An <see cref="System.Object"/> that represents the converted value. /// </returns> /// <exception cref="System.NotSupportedException"> /// The conversion cannot be performed. /// </exception> public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value == null) { return(null); } var propertyInfo = value as PropertyInfo; if (propertyInfo == null) { var message = string.Format("Cannot convert value from type '{0}' to type '{1}'.", value.GetType(), typeof(PropertyInfoAdapter)); throw new NotSupportedException(message); } return(PropertyInfoAdapter.Create(propertyInfo)); }
private PropertyInfoAdapter(PropertyInfo propertyInfo) { _propertyInfo = propertyInfo; _publicGetMethod = new Lazy <IMethodInformation> ( () => Maybe.ForValue(_propertyInfo.GetGetMethod(false)).Select(MethodInfoAdapter.Create).ValueOrDefault(), LazyThreadSafetyMode.ExecutionAndPublication); _publicOrNonPublicGetMethod = new Lazy <IMethodInformation> ( () => Maybe.ForValue(_propertyInfo.GetGetMethod(true)).Select(MethodInfoAdapter.Create).ValueOrDefault(), LazyThreadSafetyMode.ExecutionAndPublication); _publicSetMethod = new Lazy <IMethodInformation> ( () => Maybe.ForValue(_propertyInfo.GetSetMethod(false)).Select(MethodInfoAdapter.Create).ValueOrDefault(), LazyThreadSafetyMode.ExecutionAndPublication); _publicOrNonPublicSetMethod = new Lazy <IMethodInformation> ( () => Maybe.ForValue(_propertyInfo.GetSetMethod(true)).Select(MethodInfoAdapter.Create).ValueOrDefault(), LazyThreadSafetyMode.ExecutionAndPublication); _publicAccessors = new Lazy <IReadOnlyCollection <IMethodInformation> > ( () => _propertyInfo.GetAccessors(false).Select(MethodInfoAdapter.Create).ToArray(), LazyThreadSafetyMode.ExecutionAndPublication); _publicOrNonPublicAccessors = new Lazy <IReadOnlyCollection <IMethodInformation> > ( () => _propertyInfo.GetAccessors(true).Select(MethodInfoAdapter.Create).ToArray(), LazyThreadSafetyMode.ExecutionAndPublication); _cachedDeclaringType = new Lazy <ITypeInformation> ( () => Maybe.ForValue(_propertyInfo.DeclaringType).Select(TypeAdapter.Create).ValueOrDefault(), LazyThreadSafetyMode.ExecutionAndPublication); _cachedOriginalDeclaringType = new Lazy <ITypeInformation> ( () => TypeAdapter.Create(_propertyInfo.GetOriginalDeclaringType()), LazyThreadSafetyMode.ExecutionAndPublication); _cachedOriginalDeclaration = new Lazy <IPropertyInformation> ( () => PropertyInfoAdapter.Create(_propertyInfo.GetBaseDefinition()), LazyThreadSafetyMode.ExecutionAndPublication); _interfaceDeclarations = new Lazy <IReadOnlyCollection <IPropertyInformation> > ( FindInterfaceDeclarationsImplementation, LazyThreadSafetyMode.ExecutionAndPublication); }