예제 #1
0
        /// <summary>
        /// Converts the given object to a <see cref="TypeAdapter"/>, 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="Type"/> 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 type = value as Type;

            if (type == null)
            {
                var message = string.Format("Cannot convert value from type '{0}' to type '{1}'.", value.GetType(), typeof(TypeAdapter));
                throw new NotSupportedException(message);
            }

            return(TypeAdapter.Create(type));
        }
        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);
        }
예제 #3
0
        private MethodInfoAdapter(MethodInfo methodInfo)
        {
            _methodInfo = methodInfo;

            _cachedDeclaringType = new Lazy <ITypeInformation> (
                () => Maybe.ForValue(_methodInfo.DeclaringType).Select(TypeAdapter.Create).ValueOrDefault(),
                LazyThreadSafetyMode.ExecutionAndPublication);

            _cachedOriginalDeclaringType = new Lazy <ITypeInformation> (
                () => TypeAdapter.Create(_methodInfo.GetOriginalDeclaringType()),
                LazyThreadSafetyMode.ExecutionAndPublication);

            _declaringProperty = new Lazy <IPropertyInformation> (
                () => Maybe.ForValue(_methodInfo.FindDeclaringProperty()).Select(PropertyInfoAdapter.Create).ValueOrDefault(),
                LazyThreadSafetyMode.ExecutionAndPublication);

            _interfaceDeclarations = new Lazy <IReadOnlyCollection <IMethodInformation> > (
                FindInterfaceDeclarationsImplementation,
                LazyThreadSafetyMode.ExecutionAndPublication);
        }
예제 #4
0
 private ITypeInformation[] ConvertToTypeAdapters(Type[] types)
 {
     return(Array.ConvertAll(types, t => (ITypeInformation)TypeAdapter.Create(t)));
 }
예제 #5
0
 public ITypeInformation GetGenericTypeDefinition()
 {
     return(TypeAdapter.Create(_type.GetGenericTypeDefinition()));
 }
예제 #6
0
 public ITypeInformation MakeByRefType()
 {
     return(TypeAdapter.Create(_type.MakeByRefType()));
 }
예제 #7
0
 public ITypeInformation MakeArrayType(int rank)
 {
     return(TypeAdapter.Create(_type.MakeArrayType(rank)));
 }