コード例 #1
0
        public int LoadDocData(string pszMkDocument)
        {
            _document = new XinqDocument();
            _document.Load(pszMkDocument);

            _editor.Document = _document;
            _editor.LoadDocument();

            AdviseFileChanges(pszMkDocument);

            return(VSConstants.S_OK);
        }
コード例 #2
0
ファイル: Query.cs プロジェクト: ans-ashkan/Xinq
        public Query(XinqDocument document, XmlNode node)
            : this(document)
        {
            if (node.Attributes["name"] == null)
                throw new XmlException("Missing required attribute 'name'!");

            _name = node.Attributes["name"].Value;

            if (node.SelectSingleNode("comment") != null)
                _comment = node.SelectSingleNode("comment").InnerText;

            if (node.SelectSingleNode("text") == null)
                throw new XmlException("Missing required element 'text'!");

            _text = node.SelectSingleNode("text").InnerText;
        }
コード例 #3
0
        protected override byte[] GenerateCode(string inputFileContent)
        {
            var stream = new MemoryStream();
            var writer = new StreamWriter(stream, Encoding.UTF8);

            var document = new XinqDocument();

            document.Load(InputFilePath);

            var compileUnit = GenerateCode(document);

            var generatorOptions = new CodeGeneratorOptions();

            GetCodeProvider().GenerateCodeFromCompileUnit(compileUnit, writer, generatorOptions);
            writer.Flush();

            return(stream.ToArray());
        }
コード例 #4
0
ファイル: Query.cs プロジェクト: faridprogrammer/Xinq
        public Query(XinqDocument document, XmlNode node) : this(document)
        {
            if (node.Attributes["name"] == null)
            {
                throw new XmlException("Missing required attribute 'name'!");
            }

            _name = node.Attributes["name"].Value;

            if (node.SelectSingleNode("comment") != null)
            {
                _comment = node.SelectSingleNode("comment").InnerText;
            }

            if (node.SelectSingleNode("text") == null)
            {
                throw new XmlException("Missing required element 'text'!");
            }

            _text = node.SelectSingleNode("text").InnerText;
        }
コード例 #5
0
ファイル: Query.cs プロジェクト: faridprogrammer/Xinq
 public Query(XinqDocument document)
 {
     _document = document;
 }
コード例 #6
0
ファイル: Query.cs プロジェクト: ans-ashkan/Xinq
 public Query(XinqDocument document)
 {
     _document = document;
 }
コード例 #7
0
ファイル: XinqEditorPane.cs プロジェクト: ans-ashkan/Xinq
        public int LoadDocData(string pszMkDocument)
        {
            _document = new XinqDocument();
            _document.Load(pszMkDocument);

            _editor.Document = _document;
            _editor.LoadDocument();

            AdviseFileChanges(pszMkDocument);

            return VSConstants.S_OK;
        }
コード例 #8
0
        public CodeCompileUnit GenerateCode(XinqDocument document)
        {
            var codeUnit = new CodeCompileUnit();

            codeUnit.UserData.Add("AllowLateBound", false);
            codeUnit.UserData.Add("RequireVariableDeclaration", true);

            var namespaceCode = new CodeNamespace();

            namespaceCode.Name = !string.IsNullOrEmpty(FileNameSpace) ? FileNameSpace : null;
            namespaceCode.Imports.Add(new CodeNamespaceImport("System"));
            codeUnit.Namespaces.Add(namespaceCode);

            var mainClassCode = new CodeTypeDeclaration();

            mainClassCode.IsClass        = true;
            mainClassCode.Name           = GetValidLanguageIndependentIdentifier(Path.GetFileNameWithoutExtension(InputFilePath));
            mainClassCode.Attributes     = MemberAttributes.Static;
            mainClassCode.TypeAttributes = TypeAttributes.NotPublic;

            var generatedCodeAttributeCode = new CodeAttributeDeclaration(new CodeTypeReference(typeof(GeneratedCodeAttribute)), new CodeAttributeArgument(new CodePrimitiveExpression("XinqClassGenerator")), new CodeAttributeArgument(new CodePrimitiveExpression(GetType().Assembly.GetName().Version.ToString())));

            generatedCodeAttributeCode.AttributeType.Options = CodeTypeReferenceOptions.GlobalReference;
            mainClassCode.CustomAttributes.Add(generatedCodeAttributeCode);

            var debuggerNonUserCodeAttributeCode = new CodeAttributeDeclaration(new CodeTypeReference(typeof(DebuggerNonUserCodeAttribute)));

            debuggerNonUserCodeAttributeCode.AttributeType.Options = CodeTypeReferenceOptions.GlobalReference;
            mainClassCode.CustomAttributes.Add(debuggerNonUserCodeAttributeCode);

            var compilerGeneratedAttributeCode = new CodeAttributeDeclaration(new CodeTypeReference(typeof(CompilerGeneratedAttribute)));

            compilerGeneratedAttributeCode.AttributeType.Options = CodeTypeReferenceOptions.GlobalReference;
            mainClassCode.CustomAttributes.Add(compilerGeneratedAttributeCode);

            mainClassCode.Members.Add(GenerateQueryClassCode());

            foreach (var query in document.Queries)
            {
                var queryName = GetValidLanguageIndependentIdentifier(query.Name);

                var fieldCode = new CodeMemberField();
                fieldCode.Name = string.Format("_{0}{1}", queryName.Substring(0, 1).ToLower(), queryName.Substring(1));

                fieldCode.Type           = new CodeTypeReference("Query");
                fieldCode.Attributes     = MemberAttributes.Private | MemberAttributes.Static;
                fieldCode.InitExpression = new CodeObjectCreateExpression("Query", new CodePrimitiveExpression(query.NormalizedText));
                mainClassCode.Members.Add(fieldCode);

                var propertyCode = new CodeMemberProperty();
                propertyCode.Name       = queryName;
                propertyCode.Type       = new CodeTypeReference("Query");
                propertyCode.Attributes = MemberAttributes.Assembly | MemberAttributes.Final | MemberAttributes.Static;

                var commentCode = new CodeCommentStatement(string.Format("<summary>{1} {0}{1} </summary>", query.Comment, Environment.NewLine), true);
                propertyCode.Comments.Add(commentCode);

                var returnCode = new CodeMethodReturnStatement(new CodeFieldReferenceExpression(null, fieldCode.Name));
                propertyCode.GetStatements.Add(returnCode);

                mainClassCode.Members.Add(propertyCode);
            }

            namespaceCode.Types.Add(mainClassCode);

            return(codeUnit);
        }
コード例 #9
0
ファイル: XinqClassGenerator.cs プロジェクト: ans-ashkan/Xinq
        protected override byte[] GenerateCode(string inputFileContent)
        {
            var stream = new MemoryStream();
            var writer = new StreamWriter(stream, Encoding.UTF8);

            var document = new XinqDocument();
            document.Load(InputFilePath);

            var compileUnit = GenerateCode(document);

            var generatorOptions = new CodeGeneratorOptions();
            GetCodeProvider().GenerateCodeFromCompileUnit(compileUnit, writer, generatorOptions);
            writer.Flush();

            return stream.ToArray();
        }
コード例 #10
0
ファイル: XinqClassGenerator.cs プロジェクト: ans-ashkan/Xinq
        public CodeCompileUnit GenerateCode(XinqDocument document)
        {
            var codeUnit = new CodeCompileUnit();
            codeUnit.UserData.Add("AllowLateBound", false);
            codeUnit.UserData.Add("RequireVariableDeclaration", true);

            var namespaceCode = new CodeNamespace();
            namespaceCode.Name = !string.IsNullOrEmpty(FileNameSpace) ? FileNameSpace : null;
            namespaceCode.Imports.Add(new CodeNamespaceImport("System"));
            codeUnit.Namespaces.Add(namespaceCode);

            var mainClassCode = new CodeTypeDeclaration();
            mainClassCode.IsClass = true;
            mainClassCode.Name = GetValidLanguageIndependentIdentifier(Path.GetFileNameWithoutExtension(InputFilePath));
            mainClassCode.Attributes = MemberAttributes.Static;
            mainClassCode.TypeAttributes = TypeAttributes.NotPublic;

            var generatedCodeAttributeCode = new CodeAttributeDeclaration(new CodeTypeReference(typeof(GeneratedCodeAttribute)), new CodeAttributeArgument(new CodePrimitiveExpression("XinqClassGenerator")), new CodeAttributeArgument(new CodePrimitiveExpression(GetType().Assembly.GetName().Version.ToString())));
            generatedCodeAttributeCode.AttributeType.Options = CodeTypeReferenceOptions.GlobalReference;
            mainClassCode.CustomAttributes.Add(generatedCodeAttributeCode);

            var debuggerNonUserCodeAttributeCode = new CodeAttributeDeclaration(new CodeTypeReference(typeof(DebuggerNonUserCodeAttribute)));
            debuggerNonUserCodeAttributeCode.AttributeType.Options = CodeTypeReferenceOptions.GlobalReference;
            mainClassCode.CustomAttributes.Add(debuggerNonUserCodeAttributeCode);

            var compilerGeneratedAttributeCode = new CodeAttributeDeclaration(new CodeTypeReference(typeof(CompilerGeneratedAttribute)));
            compilerGeneratedAttributeCode.AttributeType.Options = CodeTypeReferenceOptions.GlobalReference;
            mainClassCode.CustomAttributes.Add(compilerGeneratedAttributeCode);

            mainClassCode.Members.Add(GenerateQueryClassCode());

            foreach (var query in document.Queries)
            {
                var queryName = GetValidLanguageIndependentIdentifier(query.Name);

                var fieldCode = new CodeMemberField();
                fieldCode.Name = string.Format("_{0}{1}", queryName.Substring(0, 1).ToLower(), queryName.Substring(1));

                fieldCode.Type = new CodeTypeReference("Query");
                fieldCode.Attributes = MemberAttributes.Private | MemberAttributes.Static;
                fieldCode.InitExpression = new CodeObjectCreateExpression("Query", new CodePrimitiveExpression(query.NormalizedText));
                mainClassCode.Members.Add(fieldCode);

                var propertyCode = new CodeMemberProperty();
                propertyCode.Name = queryName;
                propertyCode.Type = new CodeTypeReference("Query");
                propertyCode.Attributes = MemberAttributes.Assembly | MemberAttributes.Final | MemberAttributes.Static;

                var commentCode = new CodeCommentStatement(string.Format("<summary>{1} {0}{1} </summary>", query.Comment, Environment.NewLine), true);
                propertyCode.Comments.Add(commentCode);

                var returnCode = new CodeMethodReturnStatement(new CodeFieldReferenceExpression(null, fieldCode.Name));
                propertyCode.GetStatements.Add(returnCode);

                mainClassCode.Members.Add(propertyCode);
            }

            namespaceCode.Types.Add(mainClassCode);

            return codeUnit;
        }
コード例 #11
0
 public QueryCollection(XinqDocument document)
 {
     _document = document;
 }