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); }
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); }
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); }