private static object GetConverterFromAttribute(Type destinationType)
 {
     object[] customAttributes = destinationType.GetCustomAttributes(typeof(TypeConverterAttribute), true);
     if ((customAttributes != null) && (customAttributes.Length > 0))
     {
         TypeConverterAttribute attribute = customAttributes[0] as TypeConverterAttribute;
         if (attribute != null)
         {
             return(CreateConverterInstance(SystemInfo.GetTypeFromString(destinationType, attribute.ConverterTypeName, false, true)));
         }
     }
     return(null);
 }
Beispiel #2
0
 /// <summary>
 /// Lookups the type converter to use as specified by the attributes on the
 /// destination type.
 /// </summary>
 /// <param name="destinationType">The type being converted to.</param>
 /// <returns>
 /// The type converter instance to use for type conversions or <c>null</c>
 /// if no type converter is found.
 /// </returns>
 private static object GetConverterFromAttribute(Type destinationType)
 {
     object[] customAttributes = CompatibilityExtensions.GetCustomAttributes(destinationType, typeof(TypeConverterAttribute), inherit: true);
     if (customAttributes != null && customAttributes.Length != 0)
     {
         TypeConverterAttribute typeConverterAttribute = customAttributes[0] as TypeConverterAttribute;
         if (typeConverterAttribute != null)
         {
             return(CreateConverterInstance(SystemInfo.GetTypeFromString(destinationType, typeConverterAttribute.ConverterTypeName, throwOnError: false, ignoreCase: true)));
         }
     }
     return(null);
 }
Beispiel #3
0
        /// <summary>
        /// Lookups the type converter to use as specified by the attributes on the
        /// destination type.
        /// </summary>
        /// <param name="destinationType">The type being converted to.</param>
        /// <returns>
        /// The type converter instance to use for type conversions or <c>null</c>
        /// if no type converter is found.
        /// </returns>
        private static object GetConverterFromAttribute(Type destinationType)
        {
            // Look for an attribute on the destination type
            object[] attributes = destinationType.GetCustomAttributes(typeof(TypeConverterAttribute), true);
            if (attributes != null && attributes.Length > 0)
            {
                TypeConverterAttribute tcAttr = attributes[0] as TypeConverterAttribute;
                if (tcAttr != null)
                {
                    Type converterType = SystemInfo.GetTypeFromString(destinationType, tcAttr.ConverterTypeName, false, true);
                    return(CreateConverterInstance(converterType));
                }
            }

            // Not found converter using attributes
            return(null);
        }