Example #1
0
 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);
 }
Example #2
0
 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;
     }
 }
Example #3
0
        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);
        }
Example #4
0
        public static FullTypeNameInfo Parse(string fullType)
        {
            FullTypeNameInfo result = new FullTypeNameInfo();

            if (fullType.Contains('<'))
            {
                ParseAsCSharpCode(result, fullType.Replace(" ", ""));
            }
            else
            {
                ParseAsFQN(result, fullType.Replace(" ", ""));
            }
            return(result);
        }
Example #5
0
        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);
 }
Example #7
0
 public Mapping(FullTypeNameInfo srcType, string dstMemberName)
 {
     SrcType       = srcType;
     DstMemberName = dstMemberName;
 }
Example #8
0
 public AutomapperProfilerBuilder WithValueMapping(FullTypeNameInfo srcType, string dstMemberName)
 {
     Mappings.Add(new Mapping(srcType, dstMemberName));
     return(this);
 }
Example #9
0
 public static FullTypeNameInfo ParseType(this string str)
 {
     return(FullTypeNameInfo.Parse(str));
 }
Example #10
0
        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();
                }
            }
        }