/// <summary> /// Gets the source converters defined by the specified attribute set. /// </summary> /// <param name="property">Property information</param> /// <param name="attrSet">Attribute set</param> /// <returns>List of source converters</returns> private static List <ISourceConverter> GetSourceConverters(PropertyInfo property, AttributeSet attrSet) { var sourceConvertersAttrs = attrSet.All <SourceConverterAttribute>(); var sourceConverters = new List <ISourceConverter>(); foreach (var attr in sourceConvertersAttrs) { if (attr.SourceType == null || attr.ConverterType == null) { throw new NullReferenceException( "The Source and ConverterType properties of SourceConverterAttribute cannot be null."); } if (!typeof(ISourceConverter).IsAssignableFrom(attr.ConverterType)) { throw new InvalidCastException( $"{attr.ConverterType} cannot be used as the value for the ConverterType property " + "of SourceConverterAttribute, because it cannot be cast to IDataConverter."); } var converter = (ISourceConverter)Activator.CreateInstance(attr.ConverterType); if (!property.PropertyType.IsAssignableFrom(converter.GetClrType())) { throw new InvalidCastException( $"The {attr.ConverterType} converter does not support conversion to type {property.PropertyType}."); } sourceConverters.Add(converter); } return(sourceConverters); }