public AutomapperProfilerBuilder ForType(FullTypeNameInfo dst, FullTypeNameInfo src) { _sourceType = src; _destinationType = dst; this._name = src.IsNullable ? src.GenericArguments.First().Name : src.Name + dst.Name.EndsWithSingleSuffix("Profile"); return(this); }
private static void ParseOnlyName(FullTypeNameInfo result, string text, int start, int dot, int end) { if (dot > 0) { result._namespace = text.Substring(start, dot - start); result._name = text.Substring(dot + 1, end - dot); } else { result._name = text; } }
private static int ParseAsFQN(FullTypeNameInfo result, string fullType, int startIndex = 0) { int lastDot = 0; int lastComma = 0; for (int i = startIndex; i < fullType.Length; i++) { switch (fullType[i]) { case '[': // this will be a generic if (fullType[i + 1] == '[') { i = i + 1; // start of arguments } var gArg = new FullTypeNameInfo(); result._genericArguments.Add(gArg); result.IsGeneric = true; startIndex = i = ParseAsFQN(gArg, fullType, i + 1); break; case '.': lastDot = i; break; case ',': if (result._name == null) // this is full-type-name { ParseOnlyName(result, fullType, startIndex, lastDot, i - 1); } lastComma = i; // we don't parse assembly name, version or culture. break; case ']': // this is end of generic return(i); case '`': ParseOnlyName(result, fullType, startIndex, lastDot, i - 1); break; default: continue; } } if (result._name == null) { ParseOnlyName(result, fullType, startIndex, lastDot, fullType.Length - 1); } return(fullType.Length); }
public static FullTypeNameInfo Parse(string fullType) { FullTypeNameInfo result = new FullTypeNameInfo(); if (fullType.Contains('<')) { ParseAsCSharpCode(result, fullType.Replace(" ", "")); } else { ParseAsFQN(result, fullType.Replace(" ", "")); } return(result); }
private static int ParseAsCSharpCode(FullTypeNameInfo result, string fullType, int startIndex = 0) { int lastDot = 0; for (int i = startIndex; i < fullType.Length; i++) { switch (fullType[i]) { case '<': // this will be a generic var gArg = new FullTypeNameInfo(); result._genericArguments.Add(gArg); result.IsGeneric = true; ParseOnlyName(result, fullType, startIndex, lastDot, i - 1); startIndex = i = ParseAsCSharpCode(gArg, fullType, i + 1); break; case '.': lastDot = i; break; case '>': // this is end of generic ParseOnlyName(result, fullType, startIndex, lastDot, i - 1); return(i); default: continue; } } if (result._name == null) { ParseOnlyName(result, fullType, startIndex, lastDot, fullType.Length - 1); } return(fullType.Length); }
public DataClassBuilder WithProperty(FullTypeNameInfo type, string name) { WithProperty(new Field(type.ToString(), name)); return(this); }
public Mapping(FullTypeNameInfo srcType, string dstMemberName) { SrcType = srcType; DstMemberName = dstMemberName; }
public AutomapperProfilerBuilder WithValueMapping(FullTypeNameInfo srcType, string dstMemberName) { Mappings.Add(new Mapping(srcType, dstMemberName)); return(this); }
public static FullTypeNameInfo ParseType(this string str) { return(FullTypeNameInfo.Parse(str)); }
public static Type GetPrimitiveType(this FullTypeNameInfo info) { if (info.Namespace != "System") { throw new NotSupportedException(); } if (info.IsNullable) { Type inner = info.GenericArguments.First().GetPrimitiveType(); return(typeof(Nullable <>).MakeGenericType(inner)); } else { switch (info.Name) { case "String": return(typeof(String)); case "Int16": return(typeof(Int16)); case "Int32": return(typeof(Int32)); case "Int64": return(typeof(Int64)); case "Single": return(typeof(Single)); case "Double": return(typeof(Double)); case "Decimal": return(typeof(Decimal)); case "Guid": return(typeof(Guid)); case "Boolean": return(typeof(Boolean)); case "Byte": return(typeof(Byte)); case "Char": return(typeof(Char)); case "TimeSpan": return(typeof(TimeSpan)); case "DateTime": return(typeof(DateTime)); case "DateTimeOffset": return(typeof(DateTimeOffset)); default: throw new NotSupportedException(); } } }