public override string Convert(IReturnType returnType) { if (returnType == null) { return(String.Empty); } StringBuilder builder = new StringBuilder(); string fullName = returnType.FullyQualifiedName; string shortName; if (fullName != null && TypeConversionTable.TryGetValue(fullName, out shortName)) { builder.Append(shortName); } else { if (UseFullyQualifiedNames) { builder.Append(fullName); } else { builder.Append(returnType.Name); } } UnpackNestedType(builder, returnType); return(builder.ToString()); }
public override string GetIntrinsicTypeName(string dotNetTypeName) { string shortName; if (TypeConversionTable.TryGetValue(dotNetTypeName, out shortName)) { return(shortName); } return(dotNetTypeName); }
internal TypeConversionTable GetTypeConversionTable() { // Extract the conversion table. Must do this within the iteration since upstream components may use yield. if (_typeConversionTable == null) { var typeConverter = _pipeline.FindComponentType <TypeConverter>(); if (typeConverter != null) { _typeConversionTable = typeConverter.TypeConversionTable; } } return(_typeConversionTable); }
/// <summary> /// Creates a new TypeConversionTable with some general defaults and then apply /// source/target specific configurations. /// </summary> protected void CreateTypeConversionTable() { TypeConversionTable = new TypeConversionTable(); // Extract source schema information. var schemaTable = _reader.GetSchemaTable(); int columnIndex = 0; foreach (DataRow row in schemaTable.Rows) { // Default each source column's conversion to the data reader's schema table. var map = new TypeConversionMap(); map.Source.ColumnName = row["ColumnName"].ToString(); map.Source.DataType = Type.GetType(row["DataType"].ToString()); map.Source.DataTypeName = row["DataTypeName"].ToString(); map.Source.ColumnSize = Cast <int>(row["ColumnSize"]); map.Source.NumericPrecision = Cast <Int16>(row["NumericPrecision"]); map.Source.NumericScale = Cast <Int16>(row["NumericScale"]); map.Source.AllowNull = Cast <bool>(row["AllowDBNull"]); map.TransportAsBinary = false; // If column names are missing, derive based on index. if (map.Source.ColumnName == "") { map.Source.ColumnName = $"Column{columnIndex}"; } map.Source.DataTypeName = StripNamespace(map.Source.DataTypeName); // Default target to source (special conversion rules for target apply next). map.Target = map.Source.Clone(); // Allow source, formatters, and target to apply their conversion (in that order). Map(map, _source); Map(map, _readFormatter); Map(map, _writeFormatter); Map(map, _target); TypeConversionTable.Add(map); columnIndex++; } }
public IEnumerable <MappingPair> PerformMapping() { if (mappingProperties != null) { return(mappingProperties); } mappingProperties = ( from PropertyInfo sourceProperty in typeof(TSource).GetProperties(flags) join PropertyInfo destinationProperty in typeof(TDestination).GetProperties(flags) on sourceProperty.Name equals destinationProperty.Name where sourceProperty.CanRead && destinationProperty.CanWrite && TypeConversionTable.TypeCanBeCast(sourceProperty.PropertyType, destinationProperty.PropertyType) select new MappingPair() { Source = sourceProperty, Destination = destinationProperty } ). ToList(); return(mappingProperties); }