Exemplo n.º 1
0
        public ImmutableDictionary <TypePair, CodeFile> CreateCodeFilesDictionary(
            ImmutableDictionary <TypePair, CodeFile> parentFiles)
        {
            var files = new Dictionary <TypePair, CodeFile>();
            var cv    = NameConventionsStorage.Map;

            foreach (var kvp in ExplicitTypeMaps)
            {
                TypePair typePair = kvp.Key;

                var mapCodeFile = parentFiles[typePair];

                string srcType  = typePair.SourceType.FullName.NormalizeTypeName();
                string destType = typePair.DestinationType.FullName.NormalizeTypeName();

                string arg1 = $"{cv.SrcParam} as {srcType}";
                string arg2 = StatementTemplates.New(destType);

                var methodCall = StatementTemplates.MethodCall(mapCodeFile.GetClassAndMethodName(), arg1, arg2);

                string methodCode = StatementTemplates.Method(string.Empty,
                                                              new MethodDeclarationContext(cv.Method,
                                                                                           new VariableContext(destType, methodCall),
                                                                                           new VariableContext(typeof(object).Name, cv.SrcParam)));

                var file = TextBuilderHelper.CreateFile(typePair, methodCode, cv.Method);

                files.Add(typePair, file);
            }

            return(files.ToImmutableDictionary());
        }
Exemplo n.º 2
0
        private ImmutableDictionary <TypePair, CodeFile> CreateCodeFilesDictionary()
        {
            var files = new Dictionary <TypePair, CodeFile>();
            var cv    = NameConventionsStorage.Map;

            foreach (var kvp in ExplicitTypeMaps)
            {
                TypePair typePair = kvp.Key;
                TypeMap  map      = kvp.Value;

                string srcType  = typePair.SourceType.FullName.NormalizeTypeName();
                string destType = typePair.DestinationType.FullName.NormalizeTypeName();

                var assignment = MethodInnerCodeBuilder.GetAssignment(map);

                string methodInnerCode = assignment.GetCode(cv.SrcParam, cv.DestParam);

                string methodCode = StatementTemplates.Method(methodInnerCode,
                                                              new MethodDeclarationContext(cv.Method,
                                                                                           new VariableContext(destType, cv.DestParam),
                                                                                           new VariableContext(srcType, cv.SrcParam),
                                                                                           new VariableContext(destType, cv.DestParam)));

                var file = TextBuilderHelper.CreateFile(typePair, methodCode, cv.Method, assignment);

                files.Add(typePair, file);
            }

            return(files.ToImmutableDictionary());
        }
Exemplo n.º 3
0
        public ImmutableDictionary <TypePair, CodeFile> CreateCodeFilesDictionary(
            ImmutableDictionary <TypePair, CodeFile> parentFiles)
        {
            var files = new Dictionary <TypePair, CodeFile>();
            var cv    = NameConventionsStorage.MapCollection;

            foreach (var kvp in ExplicitTypeMaps)
            {
                TypePair typePair = kvp.Key;

                var mapCodeFile = parentFiles[typePair];

                string srcCollType  = cv.GetCollectionType(typePair.SourceType.FullName);
                string destCollType = cv.GetCollectionType(typePair.DestinationType.FullName);

                string methodInnerCode = mapCodeFile.InnerMethodAssignment
                                         .GetCode(cv.SrcParam, cv.DestParam)
                                         .RemoveDoubleBraces();

                var forCode = StatementTemplates.For(methodInnerCode,
                                                     new ForDeclarationContext(cv.SrcCollection, cv.DestCollection, cv.SrcParam, cv.DestParam));

                string methodCode = StatementTemplates.Method(forCode,
                                                              new MethodDeclarationContext(cv.Method,
                                                                                           new VariableContext(destCollType, cv.DestCollection),
                                                                                           new VariableContext(srcCollType, cv.SrcCollection),
                                                                                           new VariableContext(destCollType, cv.DestCollection)));

                var file = TextBuilderHelper.CreateFile(typePair, methodCode, cv.Method);

                files.Add(typePair, file);
            }

            return(files.ToImmutableDictionary());
        }
        public ImmutableDictionary <TypePair, CodeFile> CreateCodeFilesDictionary(
            ImmutableDictionary <TypePair, CodeFile> parentFiles)
        {
            var files = new Dictionary <TypePair, CodeFile>();
            var cv    = NameConventionsStorage.MapCollection;

            foreach (var kvp in ExplicitTypeMaps)
            {
                TypePair typePair = kvp.Key;

                var mapCodeFile = parentFiles[typePair];

                string srcCollType  = cv.GetCollectionType(typePair.SourceType.FullName);
                string destCollType = cv.GetCollectionType(typePair.DestinationType.FullName);

                //string filler = CreationTemplates.NewObject(typePair.DestinationType);
                var builder = new StringBuilder();
                builder.AppendLine($"var {cv.SrcParam} = {cv.SrcCollection} as {srcCollType};");
                builder.AppendLine($"var {cv.DestParam} = {cv.DestCollection} as {destCollType};");
                //builder.AppendLine($"{cv.DestParam}.Add({cv.SrcParam}.Count, () => {filler});");
                builder.AppendLine(CreationTemplates.Add(cv.DestParam, $"{cv.SrcParam}.Count", typePair.DestinationType));

                string methodCall = StatementTemplates.MethodCall(
                    mapCodeFile.GetClassAndMethodName(), cv.SrcParam, cv.DestParam);

                builder.AppendLine(methodCall);

                string methodCode = StatementTemplates.Method(builder.ToString(),
                                                              new MethodDeclarationContext(cv.Method,
                                                                                           null,
                                                                                           new VariableContext(typeof(object).Name, cv.SrcCollection),
                                                                                           new VariableContext(typeof(object).Name, cv.DestCollection))
                                                              );

                var file = TextBuilderHelper.CreateFile(typePair, methodCode, cv.Method);

                files.Add(typePair, file);
            }

            return(files.ToImmutableDictionary());
        }