Esempio n. 1
0
        /// <summary>Initialize</summary>
        public void Initialize(ClassToDataTableConverterAttribute attribute)
        {
            // No data needed from the attribute
            if (attribute.TargetPropertyType == null)
            {
                throw new ArgumentException($"The {nameof(ChangeTypeCtodTypeConverter)} converter will not work unless you specify a TargetPropertyType");
            }

            OutputType     = attribute.TargetPropertyType;
            ConversionType = Nullable.GetUnderlyingType(attribute.TargetPropertyType) ?? attribute.TargetPropertyType;
        }
 /// <summary>Initialize</summary>
 public void Initialize(ClassToDataTableConverterAttribute attribute)
 {
     // No data needed from the attribute
 }
 public void Initialize(ClassToDataTableConverterAttribute attribute)
 {
 }
Esempio n. 4
0
        /// <summary>Adds one converter to the column map.</summary>
        /// <param name="newMap">The column map</param>
        /// <param name="oneCustomAttribute">The attribute that specified the type converter.  We need to use it to initialize the converter.</param>
        private void AddOneConverterToTheMap(ClassPropertyToDataTableColumnMap newMap, ClassToDataTableConverterAttribute oneCustomAttribute)
        {
            newMap.Converter = oneCustomAttribute.TypeConverter.HelpCreateAndCastToInterface <IClassToDataTableTypeConverter>(
                $"The '{newMap.PropInformation.Name}' property on the {_theClassType.Name} class specified a converter, but there is a problem!");

            newMap.Converter.Initialize(oneCustomAttribute);
            newMap.OutputType = newMap.Converter.OutputType;

            if (_validDataTableDataTypes.IsValidType(newMap.OutputType) == false)
            {
                throw new ArgumentException($"The {newMap.PropInformation.Name} property on the {_theClassType.Name} class is using a converter " +
                                            $"with an output type of  {newMap.OutputType.Name}, which is NOT supported by DataTable.  Please refer to this link " +
                                            "for more information about valid DataTable types: " +
                                            "https://docs.microsoft.com/en-us/dotnet/api/system.data.datacolumn.datatype?view=net-5.0#remarks");
            }

            if (newMap.Converter.CanConvert(newMap.PropInformation.PropertyType) == false)
            {
                throw new ArgumentException($"The {newMap.PropInformation.Name} property on the {_theClassType.Name} class " +
                                            $"has a {nameof(ClassToDataTableConverterAttribute)}, but it cannot convert a data of the " +
                                            $"{newMap.PropInformation.PropertyType.Name} type!");
            }
        }