コード例 #1
0
        private void BuildDataMap()
        {
            _stringDic.Clear();
            _dicMap.Clear();
            foreach (int enumI in Enum.GetValues(typeof(TValue)))
            {
                string stringKey = ((int)enumI).ToString();
                string stringVal = Enum.GetName(typeof(TValue), enumI);
                TValue enumVal   = (TValue)Enum.ToObject(typeof(TValue), enumI);

                if (Exclude != null && Exclude.Contains(enumVal))
                {
                    continue;
                }

                if (DisplayNames != null && DisplayNames.ContainsKey(enumVal))
                {
                    _stringDic.Add(stringKey, DisplayNames[enumVal]);
                }
                else
                {
                    _stringDic.Add(stringKey, stringVal);
                }

                _dicMap.Add(stringKey, enumVal);
            }
        }
コード例 #2
0
ファイル: EventManager.cs プロジェクト: park66665/ck2gen
        private bool TestRemove(ScriptScope scriptScope)
        {
            var c = (scriptScope.Find("id") as ScriptCommand);

            if (c != null)
            {
                ScriptReference val = c.Value as ScriptReference;
                if (c.Value is ScriptReference)
                {
                    if (val != null && Exclude.Contains(val.Referenced))
                    {
                        return(true);
                    }
                }
                else if (c.Value is int)
                {
                    int val2 = (int)c.Value;
                    if (val2 != null && ExcludeID.Contains(val2))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
コード例 #3
0
        protected void GenerateImplBody(IndentingTextWriter w, CmdParser.ArgInfo.Arg arg, string argSuffix)
        {
            if (Exclude.Contains(arg.LongName))
            {
                return;
            }

            if (arg.IsCollection)
            {
                if (IsColumnType(arg))
                {
                    w.WriteLine("args{0}.{1} = {1}.Select({2}.Parse).ToArray();", argSuffix, arg.LongName, GetCSharpTypeName(arg.ItemType));
                }
                else if (IsStringColumnType(arg))
                {
                    w.WriteLine("args{0}.{1} = {2};", argSuffix, arg.LongName, arg.LongName + argSuffix);
                }
                else
                {
                    w.WriteLine("args{0}.{1} = new[] {{ {2} }};", argSuffix, arg.LongName, arg.LongName + argSuffix);
                }
            }
            else
            {
                w.WriteLine("args{0}.{1} = {2};", argSuffix, arg.LongName, arg.LongName + argSuffix);
            }
        }
コード例 #4
0
        protected void GenerateMethodSignature(IndentingTextWriter w, CmdParser.ArgInfo.Arg arg, string parent, string parentType, string parentValue, ref string linePrefix, string argSuffix)
        {
            if (Exclude.Contains(arg.LongName))
            {
                return;
            }

            if (arg.IsSubComponentItemType)
            {
                // We need to create a tree with all the subcomponents, unless the subcomponent is a Trainer.
                Contracts.Assert(arg.ItemType.GetGenericTypeDefinition() == typeof(SubComponent <,>));
                var types    = arg.ItemType.GetGenericArguments();
                var baseType = types[0];
                var sigType  = types[1];
                if (sigType == typeof(SignatureDataLoader))
                {
                    return;
                }
                w.WriteLine(linePrefix);
                linePrefix = ",";
                if (IsTrainer(sigType))
                {
                    w.WriteLine("[DataLabInputPort(FriendlyName = \"Untrained model\", DisplayName = \"Untrained model\", IsOptional = false, DataTypes = WellKnownDataTypeIds.ILearnerDotNet, Description = \"An untrained model\")]");
                    GenerateParameter(w, "ILearner", arg.LongName + argSuffix);
                    return;
                }
                var typeName = EnumName(arg, sigType);
                GenerateDataLabParameterAttribute(w, arg.LongName, false, arg.LongName, arg.DefaultValue != null ? typeName + "." + arg.DefaultValue : null, arg.HelpText, parent, parentType, parentValue);
                GenerateParameter(w, typeName, arg.LongName + argSuffix);
                var infos = ComponentCatalog.GetAllDerivedClasses(baseType, sigType);
                foreach (var info in infos)
                {
                    var args = info.CreateArguments();
                    if (args == null)
                    {
                        continue;
                    }
                    var argInfo = CmdParser.GetArgInfo(args.GetType(), args);
                    foreach (var a in argInfo.Args)
                    {
                        GenerateMethodSignature(w, a, arg.LongName, typeName, info.LoadNames[0], ref linePrefix, argSuffix + info.LoadNames[0]);
                    }
                }
            }
            else
            {
                w.WriteLine(linePrefix);
                linePrefix = ",";
                if (IsColumnType(arg))
                {
                    GenerateDataLabParameterAttribute(w, arg.LongName, false, arg.LongName, null, arg.HelpText, parent, parentType, parentValue);
                    GenerateParameter(w, "string", arg.LongName + argSuffix);
                }
                else
                {
                    GenerateDataLabParameterAttribute(w, arg.LongName, IsOptional(arg), arg.LongName, Stringify(arg.DefaultValue), arg.HelpText, parent, parentType, parentValue);
                    GenerateParameter(w, GetCSharpTypeName(arg.ItemType), arg.LongName + argSuffix);
                }
            }
        }
コード例 #5
0
        private void GenerateImplCall(IndentingTextWriter w, CmdParser.ArgInfo.Arg arg, string parent, string parentType, string parentValue, string argSuffix)
        {
            if (Exclude.Contains(arg.LongName))
            {
                return;
            }

            if (arg.IsSubComponentItemType)
            {
                // We need to create a tree with all the subcomponents, unless the subcomponent is a Trainer.
                Contracts.Assert(arg.ItemType.GetGenericTypeDefinition() == typeof(SubComponent <,>));
                var types    = arg.ItemType.GetGenericArguments();
                var baseType = types[0];
                var sigType  = types[1];
                if (sigType == typeof(SignatureDataLoader))
                {
                    return;
                }
                if (IsTrainer(sigType))
                {
                    return;
                }
                var typeName = EnumName(arg, sigType);
                GenerateImplCall(w, typeName, arg.LongName + argSuffix);
                var infos = ComponentCatalog.GetAllDerivedClasses(baseType, sigType);
                foreach (var info in infos)
                {
                    var args = info.CreateArguments();
                    if (args == null)
                    {
                        continue;
                    }
                    var argInfo = CmdParser.GetArgInfo(args.GetType(), args);
                    foreach (var a in argInfo.Args)
                    {
                        GenerateImplCall(w, a, arg.LongName, typeName, info.LoadNames[0], argSuffix + info.LoadNames[0]);
                    }
                }
            }
            else
            {
                if (IsColumnType(arg) || IsStringColumnType(arg))
                {
                    string name = arg.LongName + argSuffix;
                    if (arg.IsCollection)
                    {
                        w.WriteLine("builder.{0} = ((string)parameters[\"{1}\"]).Split('|');", Capitalize(name), name);
                    }
                    else
                    {
                        w.WriteLine("builder.{0} = (string)parameters[\"{1}\"];", Capitalize(name), name);
                    }
                }
                else
                {
                    GenerateImplCall(w, GetCSharpTypeName(arg.ItemType), arg.LongName + argSuffix);
                }
            }
        }
コード例 #6
0
 public override IEnumerable <object[]> GetData(MethodInfo testMethod)
 {
     return(Enum.GetValues(Type)
            .Cast <object>()
            .Where(v => !Exclude.Contains(v))
            .Select(v => new[] { v })
            .ToList());
 }
コード例 #7
0
        protected void GenerateSummaryComment(IndentedTextWriter w, CmdParser.ArgInfo.Arg arg, string argSuffix)
        {
            if (Exclude.Contains(arg.LongName))
            {
                return;
            }

            GenerateParameterComment(w, arg.LongName + argSuffix, arg.HelpText);
        }
コード例 #8
0
 /// <summary>
 /// Deletes a specific range of sections.
 /// </summary>
 /// <param name="Exclude">Sections to exclude.</param>
 public void DeleteRange(params string[] Exclude)
 {
     foreach (string s in GetSectionNames(255))
     {
         if (!Exclude.Contains(s))
         {
             DeleteSection(s);
         }
     }
 }
コード例 #9
0
        private void GenerateMethodSignature(IndentingTextWriter w, CmdParser.ArgInfo.Arg arg, string parent, string parentType, string parentValue, string argSuffix)
        {
            if (Exclude.Contains(arg.LongName))
            {
                return;
            }

            if (arg.IsSubComponentItemType)
            {
                // We need to create a tree with all the subcomponents, unless the subcomponent is a Trainer.
                Contracts.Assert(arg.ItemType.GetGenericTypeDefinition() == typeof(SubComponent <,>));
                var types    = arg.ItemType.GetGenericArguments();
                var baseType = types[0];
                var sigType  = types[1];
                if (sigType == typeof(SignatureDataLoader))
                {
                    return;
                }
                if (IsTrainer(sigType))
                {
                    return;
                }
                var typeName = EnumName(arg, sigType);
                GenerateParameterAttribute(w, arg.LongName, arg.DefaultValue != null ? typeName + "." + arg.DefaultValue : null, arg.HelpText, parent, parentType, parentValue);
                GenerateParameter(w, typeName, arg.LongName + argSuffix);
                var infos = ComponentCatalog.GetAllDerivedClasses(baseType, sigType);
                foreach (var info in infos)
                {
                    var args = info.CreateArguments();
                    if (args == null)
                    {
                        continue;
                    }
                    var argInfo = CmdParser.GetArgInfo(args.GetType(), args);
                    foreach (var a in argInfo.Args)
                    {
                        GenerateMethodSignature(w, a, arg.LongName, typeName, info.LoadNames[0], argSuffix + info.LoadNames[0]);
                    }
                }
            }
            else
            {
                if (IsColumnType(arg))
                {
                    GenerateParameterAttribute(w, arg.LongName, null, arg.HelpText, parent, parentType, parentValue);
                    GenerateParameter(w, "string", arg.LongName + argSuffix);
                }
                else
                {
                    GenerateParameterAttribute(w, arg.LongName, Stringify(arg.DefaultValue), arg.HelpText, parent, parentType, parentValue);
                    GenerateParameter(w, GetCSharpTypeName(arg.ItemType), arg.LongName + argSuffix);
                }
            }
        }
コード例 #10
0
        /// <summary>
        /// Generates private fields and public properties for all the fields in the arguments.
        /// Recursively generate fields and properties for subcomponents.
        /// </summary>
        protected void GenerateFieldsOrProperties(IndentingTextWriter w, CmdParser.ArgInfo.Arg arg, string argSuffix,
                                                  Action <IndentingTextWriter, string, string, string, bool, string> oneFieldGenerator)
        {
            if (Exclude.Contains(arg.LongName))
            {
                return;
            }

            if (arg.IsSubComponentItemType)
            {
                Contracts.Assert(arg.ItemType.GetGenericTypeDefinition() == typeof(SubComponent <,>));
                var types    = arg.ItemType.GetGenericArguments();
                var baseType = types[0];
                var sigType  = types[1];
                if (sigType == typeof(SignatureDataLoader))
                {
                    return;
                }
                if (IsTrainer(sigType))
                {
                    oneFieldGenerator(w, "Tuple<string, string>", arg.LongName + argSuffix, "", false, arg.HelpText);
                    return;
                }
                var    typeName = EnumName(arg, sigType);
                string defVal   = arg.DefaultValue != null?string.Format(" = {0}.{1}", typeName, arg.DefaultValue) : "";

                oneFieldGenerator(w, typeName, arg.LongName + argSuffix, defVal, arg.ItemType == typeof(bool),
                                  arg.HelpText);
                var infos = ComponentCatalog.GetAllDerivedClasses(baseType, sigType);
                foreach (var info in infos)
                {
                    var args = info.CreateArguments();
                    if (args == null)
                    {
                        continue;
                    }
                    var argInfo = CmdParser.GetArgInfo(args.GetType(), args);
                    foreach (var a in argInfo.Args)
                    {
                        GenerateFieldsOrProperties(w, a, argSuffix + info.LoadNames[0], oneFieldGenerator);
                    }
                }
            }
            else
            {
                object val      = Stringify(arg.DefaultValue);
                string defVal   = val == null ? "" : string.Format(" = {0}", val);
                var    typeName = IsColumnType(arg) ? "string[]" : IsStringColumnType(arg) ? GetCSharpTypeName(arg.Field.FieldType) : GetCSharpTypeName(arg.ItemType);
                oneFieldGenerator(w, typeName, arg.LongName + argSuffix, defVal, arg.ItemType == typeof(bool), arg.HelpText);
            }
        }
コード例 #11
0
        /// <summary>
        /// Generates private fields and public properties for all the fields in the arguments.
        /// Recursively generate fields and properties for subcomponents.
        /// </summary>
        protected void GenerateFieldsOrProperties(IndentingTextWriter w, CmdParser.ArgInfo.Arg arg, string argSuffix,
                                                  Action <IndentingTextWriter, string, string, string, bool, string> oneFieldGenerator)
        {
            if (Exclude.Contains(arg.LongName))
            {
                return;
            }

            object val      = Stringify(arg.DefaultValue);
            string defVal   = val == null ? "" : string.Format(" = {0}", val);
            var    typeName = IsColumnType(arg) ? "string[]" : IsStringColumnType(arg) ? GetCSharpTypeName(arg.Field.FieldType) : GetCSharpTypeName(arg.ItemType);

            oneFieldGenerator(w, typeName, arg.LongName + argSuffix, defVal, arg.ItemType == typeof(bool), arg.HelpText);
        }
コード例 #12
0
        protected void GenerateImplCall(IndentingTextWriter w, CmdParser.ArgInfo.Arg arg, string argSuffix)
        {
            if (Exclude.Contains(arg.LongName))
            {
                return;
            }

            if (arg.IsSubComponentItemType)
            {
                Contracts.Assert(arg.ItemType.GetGenericTypeDefinition() == typeof(SubComponent <,>));
                var types    = arg.ItemType.GetGenericArguments();
                var baseType = types[0];
                var sigType  = types[1];
                if (sigType == typeof(SignatureDataLoader))
                {
                    return;
                }
                if (IsTrainer(sigType))
                {
                    w.WriteLine("builder.{0} = {1};", Capitalize(arg.LongName + argSuffix), arg.LongName + argSuffix);
                    return;
                }
                w.WriteLine("builder.{0} = {1};", Capitalize(arg.LongName + argSuffix), arg.LongName + argSuffix);
                var infos = ComponentCatalog.GetAllDerivedClasses(baseType, sigType);
                foreach (var info in infos)
                {
                    var args = info.CreateArguments();
                    if (args == null)
                    {
                        continue;
                    }
                    var argInfo = CmdParser.GetArgInfo(args.GetType(), args);
                    foreach (var a in argInfo.Args)
                    {
                        GenerateImplCall(w, a, argSuffix + info.LoadNames[0]);
                    }
                }
            }
            else
            {
                if (IsColumnType(arg))
                {
                    w.WriteLine("builder.{0} = {1}.Split('|');", Capitalize(arg.LongName + argSuffix), arg.LongName + argSuffix);
                }
                else
                {
                    w.WriteLine("builder.{0} = {1}{2};", Capitalize(arg.LongName + argSuffix), CastIfNeeded(arg), arg.LongName + argSuffix);
                }
            }
        }
コード例 #13
0
        private void GenerateDictionaryEntry(IndentedTextWriter w, CmdParser.ArgInfo.Arg arg, string argSuffix)
        {
            if (Exclude.Contains(arg.LongName))
            {
                return;
            }

            if (IsColumnType(arg))
            {
                GenerateDictionaryEntry(w, "string", arg.LongName + argSuffix);
            }
            else
            {
                GenerateDictionaryEntry(w, GetCSharpTypeName(arg.ItemType), arg.LongName + argSuffix);
            }
        }
コード例 #14
0
        protected void GenerateImplCall(IndentedTextWriter w, CmdParser.ArgInfo.Arg arg, string argSuffix)
        {
            if (Exclude.Contains(arg.LongName))
            {
                return;
            }

            if (IsColumnType(arg))
            {
                w.WriteLine("builder.{0} = {1}.Split('|');", Capitalize(arg.LongName + argSuffix), arg.LongName + argSuffix);
            }
            else
            {
                w.WriteLine("builder.{0} = {1}{2};", Capitalize(arg.LongName + argSuffix), CastIfNeeded(arg), arg.LongName + argSuffix);
            }
        }
コード例 #15
0
        private void GenerateMethodSignature(IndentedTextWriter w, CmdParser.ArgInfo.Arg arg, string parent, string parentType, string parentValue, string argSuffix)
        {
            if (Exclude.Contains(arg.LongName))
            {
                return;
            }

            if (IsColumnType(arg))
            {
                GenerateParameterAttribute(w, arg.LongName, null, arg.HelpText, parent, parentType, parentValue);
                GenerateParameter(w, "string", arg.LongName + argSuffix);
            }
            else
            {
                GenerateParameterAttribute(w, arg.LongName, Stringify(arg.DefaultValue), arg.HelpText, parent, parentType, parentValue);
                GenerateParameter(w, GetCSharpTypeName(arg.ItemType), arg.LongName + argSuffix);
            }
        }
コード例 #16
0
        protected void GenerateSummaryComment(IndentingTextWriter w, CmdParser.ArgInfo.Arg arg, string argSuffix)
        {
            if (Exclude.Contains(arg.LongName))
            {
                return;
            }

            if (arg.IsSubComponentItemType)
            {
                // We need to create a tree with all the subcomponents, unless the subcomponent is a Trainer.
                Contracts.Assert(arg.ItemType.GetGenericTypeDefinition() == typeof(SubComponent <,>));
                var types    = arg.ItemType.GetGenericArguments();
                var baseType = types[0];
                var sigType  = types[1];
                if (sigType == typeof(SignatureDataLoader))
                {
                    return;
                }
                GenerateParameterComment(w, arg.LongName + argSuffix, arg.HelpText);
                if (IsTrainer(sigType))
                {
                    return;
                }
                var infos = ComponentCatalog.GetAllDerivedClasses(baseType, sigType);
                foreach (var info in infos)
                {
                    var args = info.CreateArguments();
                    if (args == null)
                    {
                        continue;
                    }
                    var argInfo = CmdParser.GetArgInfo(args.GetType(), args);
                    foreach (var a in argInfo.Args)
                    {
                        GenerateSummaryComment(w, a, argSuffix + info.LoadNames[0]);
                    }
                }
            }
            else
            {
                GenerateParameterComment(w, arg.LongName + argSuffix, arg.HelpText);
            }
        }
コード例 #17
0
ファイル: FileInputSource.cs プロジェクト: kikkoi/flipleaf
        private IEnumerable <IInput> GetDirectoryFiles(IStaticSite context, DirectoryInfo dir, DirectoryInfo rootDir, bool root)
        {
            for (var i = 0; i < _patterns.Length; i++)
            {
                foreach (var file in dir.GetFiles(_patterns[i]))
                {
                    if (root)
                    {
                        if (Exclude != null && Exclude.Contains(file.Name, StringComparer.Ordinal))
                        {
                            continue;
                        }

                        yield return(new FileInput(file.Name, file.FullName));
                    }
                    else
                    {
                        var relativeDir = dir.FullName.Substring(rootDir.FullName.Length + 1);
                        yield return(new FileInput(Path.Combine(relativeDir, file.Name), file.FullName));
                    }
                }
            }

            if (Recursive)
            {
                foreach (var subDir in dir.GetDirectories())
                {
                    if (root)
                    {
                        if (Exclude != null && Exclude.Contains(subDir.Name, StringComparer.Ordinal))
                        {
                            continue;
                        }
                    }

                    foreach (var file in GetDirectoryFiles(context, subDir, rootDir, false))
                    {
                        yield return(file);
                    }
                }
            }
        }
コード例 #18
0
        protected void GenerateMethodSignature(IndentedTextWriter w, CmdParser.ArgInfo.Arg arg, string parent, string parentType, string parentValue, ref string linePrefix, string argSuffix)
        {
            if (Exclude.Contains(arg.LongName))
            {
                return;
            }

            w.WriteLine(linePrefix);
            linePrefix = ",";
            if (IsColumnType(arg))
            {
                GenerateDataLabParameterAttribute(w, arg.LongName, false, arg.LongName, null, arg.HelpText, parent, parentType, parentValue);
                GenerateParameter(w, "string", arg.LongName + argSuffix);
            }
            else
            {
                GenerateDataLabParameterAttribute(w, arg.LongName, IsOptional(arg), arg.LongName, Stringify(arg.DefaultValue), arg.HelpText, parent, parentType, parentValue);
                GenerateParameter(w, GetCSharpTypeName(arg.ItemType), arg.LongName + argSuffix);
            }
        }
コード例 #19
0
        private void GenerateImplCall(IndentedTextWriter w, CmdParser.ArgInfo.Arg arg, string parent, string parentType, string parentValue, string argSuffix)
        {
            if (Exclude.Contains(arg.LongName))
            {
                return;
            }

            if (IsColumnType(arg) || IsStringColumnType(arg))
            {
                string name = arg.LongName + argSuffix;
                if (arg.IsCollection)
                {
                    w.WriteLine("builder.{0} = ((string)parameters[\"{1}\"]).Split('|');", Capitalize(name), name);
                }
                else
                {
                    w.WriteLine("builder.{0} = (string)parameters[\"{1}\"];", Capitalize(name), name);
                }
            }
            else
            {
                GenerateImplCall(w, GetCSharpTypeName(arg.ItemType), arg.LongName + argSuffix);
            }
        }
        public IEnumerable <TagData> GetTags(IEnumerable <TaggableContent> taggableContents)
        {
            try
            {
                var credentials = new AzureCognitiveServicesTextAnalyticsClientCredentials(Key);
                var client      = new TextAnalyticsClient(credentials)
                {
                    Endpoint = Endpoint
                };

                //All of the Text Analytics API endpoints accept raw text data.The current limit is 5,120 characters for each document;
                //Limit Value
                //Maximum size of a single document   5,120 characters as measured by StringInfo.LengthInTextElements.
                //Maximum size of entire request  1 MB
                //Maximum number of documents in a request    1,000 documents
                var documents = new List <MultiLanguageInput>();
                int id        = 0;
                foreach (StringContent taggableContent in taggableContents)
                {
                    var text = (taggableContent != null) ? taggableContent.Content : null;
                    if (string.IsNullOrEmpty(text))
                    {
                        continue;
                    }

                    if (text.Length > 5100)
                    {
                        text = text.Substring(0, 5100);
                    }

                    //just skip it if description is 500 characters or less, not enough content to process
                    //if (text.Length > 500)
                    documents.Add(new MultiLanguageInput()
                    {
                        Id = id.ToString(), Text = text
                    });
                    id++;
                }

                if (!documents.Any())
                {
                    return(new List <TagData>());
                }

                var inputDocuments = new MultiLanguageBatchInput(documents);
                var results        = client.EntitiesBatch(inputDocuments);

                if (results.Errors.Count > 0)
                {
                    var messageBus = MessageBus;
                    if (messageBus != null)
                    {
                        foreach (var error in results.Errors)
                        {
                            messageBus.SendMessage(new Message()
                            {
                                Body  = string.Format("Azure Cogntive Services Text Analytics Error: {0} Message: {1}", error.Id, error.Message),
                                Level = MessageLevel.Error
                            });
                        }
                    }
                }

                var tagData     = new List <TagData>();
                var entityNames = new List <string>();
                foreach (var document in results.Documents)
                {
                    foreach (var entity in document.Entities)
                    {
                        if (!Exclude.Contains(entity.Name.ToLower()) &&
                            (entity.Type == "Organization" || entity.Type == "Location" ||
                             (entity.Type == "Other" && IncludeOther.Contains(entity.Name.ToLower())) ||
                             (entity.Type == "Quantity" && IncludeQuantity.Contains(entity.Name))))
                        {
                            var name = NormalizeEntityName(entity.Name);
                            if (entity.SubType != null)
                            {
                                entityNames.Add(string.Format("{0} - {1} - {2}", entity.Type, entity.SubType, name));
                            }
                            else
                            {
                                entityNames.Add(string.Format("{0} - {1}", entity.Type, name));
                            }
                        }
                    }
                }

                return(entityNames.Distinct().Select(x => new TagData()
                {
                    TagName = x
                }));
            }
            catch (Exception ex)
            {
                var messageBus = MessageBus;
                if (messageBus != null)
                {
                    messageBus.SendMessage(new Message()
                    {
                        Body  = string.Format("Azure Cogntive Services Text Analytics Error: {0}", ex.Message),
                        Level = MessageLevel.Error
                    });
                }
            }

            return(new List <TagData>());
        }
コード例 #21
0
        protected void GenerateImplBody(IndentingTextWriter w, CmdParser.ArgInfo.Arg arg, string argSuffix)
        {
            if (Exclude.Contains(arg.LongName))
            {
                return;
            }

            if (arg.IsSubComponentItemType)
            {
                // We need to create a tree with all the subcomponents, unless the subcomponent is a Trainer.
                Contracts.Assert(arg.ItemType.GetGenericTypeDefinition() == typeof(SubComponent <,>));
                var types    = arg.ItemType.GetGenericArguments();
                var baseType = types[0];
                var sigType  = types[1];
                if (IsTrainer(sigType))
                {
                    if (arg.IsCollection)
                    {
                        w.WriteLine("args{0}.{1} = new[] {{ new SubComponent<{2}, {3}>({4}.Item1, {4}.Item2) }};",
                                    argSuffix, arg.LongName, GetCSharpTypeName(baseType), GetCSharpTypeName(sigType),
                                    arg.LongName + argSuffix);
                    }
                    else
                    {
                        w.WriteLine("args{0}.{1} = new SubComponent<{2}, {3}>({4}.Item1, {4}.Item2);", argSuffix,
                                    arg.LongName, GetCSharpTypeName(baseType), GetCSharpTypeName(sigType),
                                    arg.LongName + argSuffix);
                    }
                    return;
                }
                if (sigType == typeof(SignatureDataLoader))
                {
                    return;
                }
                var typeName = EnumName(arg, sigType);
                w.WriteLine("switch ({0})", arg.LongName + argSuffix);
                w.WriteLine("{");
                using (w.Nest())
                {
                    if (arg.NullName != null)
                    {
                        w.WriteLine("case {0}.None:", typeName);
                        using (w.Nest())
                        {
                            w.WriteLine("args{0}.{1} = null;", argSuffix, arg.LongName);
                            w.WriteLine("break;");
                        }
                    }
                    var infos = ComponentCatalog.GetAllDerivedClasses(baseType, sigType);
                    foreach (var info in infos)
                    {
                        w.WriteLine("case {0}.{1}:", typeName, info.LoadNames[0]);
                        using (w.Nest())
                        {
                            if (info.ArgType != null)
                            {
                                var newArgSuffix = argSuffix + info.LoadNames[0];
                                w.WriteLine("var args{0} = new {1}();", newArgSuffix, GetCSharpTypeName(info.ArgType));
                                w.WriteLine("var defs{0} = new {1}();", newArgSuffix, GetCSharpTypeName(info.ArgType));
                                var args = info.CreateArguments();
                                if (args != null)
                                {
                                    var argInfo = CmdParser.GetArgInfo(args.GetType(), args);
                                    foreach (var a in argInfo.Args)
                                    {
                                        GenerateImplBody(w, a, newArgSuffix);
                                    }
                                }
                                w.WriteLine(
                                    "args{0}.{1} = new {2}(\"{3}\", CmdParser.GetSettings(args{4}, defs{4}));",
                                    argSuffix, arg.LongName, GetCSharpTypeName(arg.ItemType), info.LoadNames[0],
                                    newArgSuffix);
                            }
                            else
                            {
                                w.WriteLine("args{0}.{1} = new {2}(\"{3}\");", argSuffix, arg.LongName, GetCSharpTypeName(arg.ItemType), info.LoadNames[0]);
                            }
                            w.WriteLine("break;");
                        }
                    }
                }
                w.WriteLine("}");
            }
            else if (arg.IsCollection)
            {
                if (IsColumnType(arg))
                {
                    w.WriteLine("args{0}.{1} = {1}.Select({2}.Parse).ToArray();", argSuffix, arg.LongName, GetCSharpTypeName(arg.ItemType));
                }
                else if (IsStringColumnType(arg))
                {
                    w.WriteLine("args{0}.{1} = {2};", argSuffix, arg.LongName, arg.LongName + argSuffix);
                }
                else
                {
                    w.WriteLine("args{0}.{1} = new[] {{ {2} }};", argSuffix, arg.LongName, arg.LongName + argSuffix);
                }
            }
            else
            {
                w.WriteLine("args{0}.{1} = {2};", argSuffix, arg.LongName, arg.LongName + argSuffix);
            }
        }