コード例 #1
0
        private CodeTypeDeclaration CreateClass(string fileName, IFileMetaData fileMetaData)
        {
            var classType = new CodeTypeDeclaration(CodeDomUtils.ExtractClassName(fileName, capitalize) + "Type")
            {
                IsClass = true
            };
            CodeConstructor constructor = new CodeConstructor()
            {
                Attributes = MemberAttributes.Public | MemberAttributes.Final
            };

            constructor.Parameters.Add(new CodeParameterDeclarationExpression(typeof(IRow), "row"));
            constructor.Statements.Add(new CodeSnippetExpression("this.row = row"));
            classType.Members.Add(constructor);
            var row = new CodeMemberField()
            {
                Type       = new CodeTypeReference(typeof(IRow)),
                Attributes = MemberAttributes.Private | MemberAttributes.Final,
                Name       = "row",
            };

            classType.Members.Add(row);
            usedNames.Clear();
            foreach (var field in fileMetaData.Fields)
            {
                classType.Members.Add(CreateProperty(field));
            }
            return(classType);
        }
コード例 #2
0
        private ExplorerItem GetFileReaderItem(IFileMetaData fileMetaData, bool isCoreFile)
        {
            var explorerIcon = isCoreFile ? ExplorerIcon.View : ExplorerIcon.Table;
            var explorerItem = new ExplorerItem(CodeDomUtils.ExtractClassName(fileMetaData.FileName, capitalize),
                                                ExplorerItemKind.QueryableObject, explorerIcon)
            {
                Children     = new List <ExplorerItem>(),
                IsEnumerable = true
            };

            usedNames.Clear();
            foreach (var field in fileMetaData.Fields)
            {
                var fieldName = CodeDomUtils.ModifyKeywords(field.Term, capitalize);
                int i         = 1;
                while (usedNames.Contains(fieldName))
                {
                    fieldName += i.ToString();
                    i++;
                }
                usedNames.Add(fieldName);
                var icon      = GetFieldIcon(fileMetaData, field);
                var fieldItem = new ExplorerItem(fieldName, ExplorerItemKind.Property, icon);
                explorerItem.Children.Add(fieldItem);
            }
            return(explorerItem);
        }
コード例 #3
0
        public string GenerateSource(string fileName, IFileMetaData fileMetaData)
        {
            var DwCArchive = CreateNamespace();
            var classType  = CreateClass(fileName, fileMetaData);

            DwCArchive.Types.Add(classType);

            return(CodeDomUtils.GenerateSourceFromCodeDom(DwCArchive));
        }
コード例 #4
0
        public string GenerateSource(IFileMetaData coreFileMetaData,
                                     IEnumerable <IFileMetaData> extensionFileMetaData)
        {
            var DwCArchive = CreateNamespace();
            var classType  = CreateClass(coreFileMetaData, extensionFileMetaData);

            DwCArchive.Types.Add(classType);

            return(CodeDomUtils.GenerateSourceFromCodeDom(DwCArchive));
        }
コード例 #5
0
        private CodeMemberProperty CreateExtensionFileProperty(IFileMetaData fileMetaData)
        {
            var propertyName     = CodeDomUtils.ExtractClassName(fileMetaData.FileName, capitalize);
            var propertyTypeName = propertyName + "Type";
            var fieldProperty    = new CodeMemberProperty()
            {
                Type       = new CodeTypeReference($"IEnumerable<{propertyTypeName}>"),
                Attributes = MemberAttributes.Public | MemberAttributes.Final,
                Name       = propertyName,
                HasGet     = true
            };

            fieldProperty.GetStatements.Add(new CodeSnippetExpression($"return archive.Extensions.GetFileReaderByFileName(\"{fileMetaData.FileName}\").DataRows.Select( row => new {propertyTypeName}(row) )"));
            return(fieldProperty);
        }
コード例 #6
0
        private CodeMemberProperty CreateProperty(FieldType field)
        {
            var fieldName = CodeDomUtils.ModifyKeywords(field.Term, capitalize);
            int i         = 1;

            while (usedNames.Contains(fieldName))
            {
                fieldName += i.ToString();
                i++;
            }
            var fieldProperty = new CodeMemberProperty()
            {
                Type       = new CodeTypeReference(typeof(string)),
                Attributes = MemberAttributes.Public | MemberAttributes.Final,
                Name       = fieldName,
                HasGet     = true
            };

            usedNames.Add(fieldProperty.Name);
            fieldProperty.GetStatements.Add(new CodeSnippetExpression($"return row[\"{field.Term}\"]"));
            return(fieldProperty);
        }