当前位置: 首页>>代码示例>>C#>>正文


C# ICodeGenerator.GenerateCodeFromNamespace方法代码示例

本文整理汇总了C#中ICodeGenerator.GenerateCodeFromNamespace方法的典型用法代码示例。如果您正苦于以下问题:C# ICodeGenerator.GenerateCodeFromNamespace方法的具体用法?C# ICodeGenerator.GenerateCodeFromNamespace怎么用?C# ICodeGenerator.GenerateCodeFromNamespace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ICodeGenerator的用法示例。


在下文中一共展示了ICodeGenerator.GenerateCodeFromNamespace方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GenerateMIDICode

 public static void GenerateMIDICode(ICodeGenerator generator, MidiSequence sequence, string midiName, TextWriter writer)
 {
     CodeNamespace e = new CodeNamespace("AutoGenerated");
     CodeTypeDeclaration declaration = new CodeTypeDeclaration(midiName);
     declaration.Members.Add(CreateSequenceMethod(sequence));
     for (int i = 0; i < sequence.NumberOfTracks; i++)
     {
         int num2 = i + 1;
         declaration.Members.Add(CreateTrackMethod("CreateTrack" + num2.ToString(), sequence[i]));
     }
     e.Types.Add(declaration);
     generator.GenerateCodeFromNamespace(e, writer, new CodeGeneratorOptions());
 }
开发者ID:RickeyWard,项目名称:Rockband-DrumKit-for-Windows,代码行数:13,代码来源:MidiCodeGenerator.cs

示例2: GenerateMIDICode

        /// <summary>Creates code from a MIDI sequence.</summary>
        /// <param name="generator">Generator used to generate the actual code.</param>
        /// <param name="sequence">The sequence to translate.</param>
        /// <param name="midiName">The name of the MIDI sequence to be used as the class name.</param>
        /// <param name="writer">The writer to which the text is written.</param>
        public static void GenerateMIDICode(
			ICodeGenerator generator, MidiSequence sequence, 
			string midiName, TextWriter writer)
        {
            // Create a new namespace
            CodeNamespace ns = new CodeNamespace("AutoGenerated");

            // Create the new class
            CodeTypeDeclaration midiType = new CodeTypeDeclaration(midiName);

            // Add a method to it to create the sequence
            midiType.Members.Add(CreateSequenceMethod(sequence));
            for(int i=0; i<sequence.NumberOfTracks; i++)
            {
                midiType.Members.Add(CreateTrackMethod("CreateTrack" + (i+1).ToString(), sequence[i]));
            }

            // Add the class to the namespace
            ns.Types.Add(midiType);

            // Generate the code
            generator.GenerateCodeFromNamespace(ns, writer, new CodeGeneratorOptions());
        }
开发者ID:alpensturm,项目名称:windows,代码行数:28,代码来源:MidiCodeGenerator.cs

示例3: PopulateNamespace

        private static void PopulateNamespace(ICodeGenerator itfCG, TextWriter w)
        {
            // Add a code comment.
            CodeCommentStatement c = new CodeCommentStatement("This is the wicked cool Hello class");
            itfCG.GenerateCodeFromStatement(c, w, null);

            // Build root namespace.
            CodeNamespace cnamespace = new CodeNamespace("SimpleCodeDOMHelloClass");

            // Reference other namespaces.
            cnamespace.Imports.Add(new CodeNamespaceImport ("System") );
            cnamespace.Imports.Add(new CodeNamespaceImport ("System.Windows.Forms") );

            // Insert the HelloClass.
            CodeTypeDeclaration co = new CodeTypeDeclaration ("HelloClass");
            co.IsClass = true;
            cnamespace.Types.Add(co);
            co.BaseTypes.Add (typeof (System.Object) );
            co.TypeAttributes  = TypeAttributes.Public;

            // Make a custom construcor.
            CodeConstructor ctor = new CodeConstructor();
            ctor.Attributes = MemberAttributes.Public;
            ctor.Parameters.Add(new CodeParameterDeclarationExpression
                (new CodeTypeReference(typeof(string)), "msg"));
            ctor.Statements.Add((new CodeAssignStatement(new CodeArgumentReferenceExpression("mMsg"),
                new CodeArgumentReferenceExpression("msg"))));
            co.Members.Add(ctor);

            // Add the default construcor.
            ctor = new CodeConstructor();
            ctor.Attributes = MemberAttributes.Public;
            co.Members.Add(ctor);

            // Insert a String field (mMsg).
            CodeMemberField cf = new CodeMemberField("System.String", "mMsg");
            cf.Comments.Add(new CodeCommentStatement("The state data..."));
            cf.Attributes = MemberAttributes.Private;
            co.Members.Add(cf);

            // Add the Message property.
            CodeMemberProperty  cp = new CodeMemberProperty();
            cp.Name = "Message";
            cp.Attributes = MemberAttributes.Public | MemberAttributes.Final ;
            cp.Type = new CodeTypeReference("System.String");
            cp.Comments.Add(new CodeCommentStatement("The Message property"));
            // Getter.
            cp.GetStatements.Add(new CodeMethodReturnStatement
                (new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "mMsg")));
            // Setter.
            cp.SetStatements.Add(new CodeAssignStatement(new CodeArgumentReferenceExpression("mMsg"),
                new CodeArgumentReferenceExpression("value")));
            co.Members.Add (cp);

            // Add the Display() message.
            CodeMemberMethod cm = new CodeMemberMethod();
            cm.Name = "Display";
            cm.Attributes = MemberAttributes.Public | MemberAttributes.Final ;
            cm.Comments.Add(new CodeCommentStatement("Show 'em what we got!"));
            cm.Statements.Add (new CodeMethodInvokeExpression
                (new CodeTypeReferenceExpression("MessageBox"), "Show",
                new CodeExpression []
                {new CodeArgumentReferenceExpression  ("mMsg")}));
            co.Members.Add(cm);

            // Generate the code!
            itfCG.GenerateCodeFromNamespace (cnamespace, w, null);
        }
开发者ID:rojac07,项目名称:COM,代码行数:68,代码来源:HelloWorldGenApp.cs

示例4: SpitList


//.........这里部分代码省略.........


//Generates: public <TYPE> this[int index] {
    //      get {
    //         return ((<TYPE>)List[index]);
    //      }
    //      set {
    //          List[index] = value;
    //      }
    //  }
    CodeMemberProperty  cp = new CodeMemberProperty ();
    cp.Name = "Item";
    cp.Attributes = MemberAttributes.Public | MemberAttributes.Final ;
    cp.Type = new CodeTypeReference(typeName);
    cp.Parameters.Add (new CodeParameterDeclarationExpression (new CodeTypeReference(typeof(int)), "index"));
    cp.GetStatements.Add (new CodeMethodReturnStatement (new CodeCastExpression (typeName, new CodeIndexerExpression (new CodeFieldReferenceExpression  (new CodeThisReferenceExpression(), "List"), new CodeArgumentReferenceExpression   ("index")))));
    cp.SetStatements.Add (new CodeAssignStatement (new CodeIndexerExpression (new CodeFieldReferenceExpression  (new CodeThisReferenceExpression(),"List"), new CodeArgumentReferenceExpression   ("index")), new CodeArgumentReferenceExpression  ("value")));
    co.Members.Add (cp);


    //Gen: public int Add(<TYPE> value) {
    //        return List.Add(value);
    //      }
    CodeMemberMethod cm = new CodeMemberMethod ();
    cm.Name = "Add";
    cm.ReturnType = new CodeTypeReference(typeof(int));
    cm.Parameters.Add (new CodeParameterDeclarationExpression (typeName, "value"));
    cm.Attributes = MemberAttributes.Public | MemberAttributes.Final ;
    cm.Statements.Add (new CodeMethodReturnStatement (new CodeMethodInvokeExpression (new CodeFieldReferenceExpression  (new CodeThisReferenceExpression(),"List"), "Add", 
      new CodeArgumentReferenceExpression  ("value"))));
    co.Members.Add (cm);

    //Gen: public void Insert(int index, <TYPE> value)
    //    {
    //         List.Insert(index, info);
    //     }
    cm = new CodeMemberMethod ();
    cm.Name = "Insert";
    cm.ReturnType = new CodeTypeReference(typeof(void));
    cm.Parameters.Add (new CodeParameterDeclarationExpression (new CodeTypeReference(typeof(int)), "index"));
    cm.Parameters.Add (new CodeParameterDeclarationExpression (typeName, "value"));
    cm.Attributes = MemberAttributes.Public | MemberAttributes.Final ;
    cm.Statements.Add (new CodeMethodInvokeExpression (new CodeFieldReferenceExpression  (new CodeThisReferenceExpression(),"List"), "Insert", 
      new CodeArgumentReferenceExpression  ("index"), new CodeArgumentReferenceExpression  ("value")));
    co.Members.Add (cm);


    //Gen: public int IndexOf(<TYPE> value) 
    //      {
    //        return List.IndexOf(value);
    //      }
    cm = new CodeMemberMethod ();
    cm.Name = "IndexOf";
    cm.ReturnType = new CodeTypeReference(typeof(int));
    cm.Parameters.Add (new CodeParameterDeclarationExpression (typeName, "value"));
    cm.Attributes = MemberAttributes.Public | MemberAttributes.Final ;
    cm.Statements.Add (new CodeMethodReturnStatement (new CodeMethodInvokeExpression (new CodeFieldReferenceExpression  (new CodeThisReferenceExpression(),"List"), "IndexOf", new CodeExpression []
                {new CodeArgumentReferenceExpression  ("value")})));
    co.Members.Add (cm);

    //Gen: public bool Contains(<TYPE> value) 
    //      {
    //        return List.Contains(value);
    //      }
    cm = new CodeMemberMethod ();
    cm.Name = "Contains";
    cm.ReturnType = new CodeTypeReference(typeof(bool));
    cm.Parameters.Add (new CodeParameterDeclarationExpression (typeName, "value"));
    cm.Attributes = MemberAttributes.Public | MemberAttributes.Final ;
    cm.Statements.Add (new CodeMethodReturnStatement (new CodeMethodInvokeExpression (new CodeFieldReferenceExpression  (new CodeThisReferenceExpression(),"List"), "Contains", new CodeExpression []
                {new CodeArgumentReferenceExpression  ("value")})));
    co.Members.Add (cm);

    //Gen: public void Remove(<TYPE> value) 
    //      {
    //       List.Remove(value);
    //      }
    cm = new CodeMemberMethod ();
    cm.Name = "Remove";
    cm.Parameters.Add (new CodeParameterDeclarationExpression (typeName, "value"));
    cm.Attributes = MemberAttributes.Public | MemberAttributes.Final ;
    cm.Statements.Add (new CodeMethodInvokeExpression (new CodeFieldReferenceExpression  (new CodeThisReferenceExpression(),"List"), "Remove", new CodeExpression []
                {new CodeArgumentReferenceExpression  ("value")}));
    co.Members.Add (cm);

    //Gen: public void CopyTo(<Type>[] array, int index) 
    //     {
    //         List.CopyTo(array, index);
    //     }
    cm = new CodeMemberMethod ();
    cm.Name = "CopyTo";
    cm.Parameters.Add (new CodeParameterDeclarationExpression (new CodeTypeReference(typeName, 1), "array"));
    cm.Parameters.Add (new CodeParameterDeclarationExpression (new CodeTypeReference(typeof(int)), "index"));
    cm.Attributes = MemberAttributes.Public | MemberAttributes.Final ;
    cm.Statements.Add (new CodeMethodInvokeExpression (new CodeFieldReferenceExpression  (new CodeThisReferenceExpression(),"List"), "CopyTo", new CodeExpression []
                {new CodeArgumentReferenceExpression  ("array"), new CodeArgumentReferenceExpression ("index")}));
    co.Members.Add (cm);

    baseCompiler.GenerateCodeFromNamespace (cnamespace, w, null);
  } //SpitList()
开发者ID:ArildF,项目名称:masters,代码行数:101,代码来源:listbuilder.cs

示例5: GenerateCode

 /// <summary>
 /// ���ɴ���
 /// </summary>
 /// <param name="CodeGenerator"></param>
 /// <param name="CurrentNameSpace"></param>
 /// <returns></returns>
 private static string GenerateCode(ICodeGenerator CodeGenerator,
     CodeNamespace CurrentNameSpace)
 {
     // CodeGeneratorOptions��������ָ�����ֹ�����������
     // ʹ�õĸ�ʽ��ѡ��
     CodeGeneratorOptions cop = new CodeGeneratorOptions();
     // ָ����ʽ�������ŵ�λ��
     cop.BracingStyle = "C";
     // ָ����ʽ��������������ʽ
     cop.IndentString = " ";
     StringBuilder sbCode = new StringBuilder();
     StringWriter sw = new StringWriter(sbCode);
     CodeGenerator.GenerateCodeFromNamespace(CurrentNameSpace, sw, cop);
     return sbCode.ToString();
 }
开发者ID:JaneBlue,项目名称:HeadacheInference,代码行数:21,代码来源:DataMapper.cs

示例6: CreationClassePersistable


//.........这里部分代码省略.........
                attr.Name="PersistDynamicSQL";
                attr.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(tab.Name)));

            }
            maClasse.CustomAttributes.Add(attr);
            monNamespace.Types.Add(maClasse); // ajout de la classe dans le namespace

            for(int n=1;n<=tab.Columns.Count;n++)
            {
                SQLDMO._Column col=tab.Columns.Item(n);

                Type dotNetType=GetDotNetType(col.PhysicalDatatype);

                // private string
                CodeMemberField priv_var = new CodeMemberField(dotNetType, "p_" + col.Name);
                maClasse.Members.Add(priv_var );

                // private bool si Nullable col
                CodeMemberField null_var=null;
                if (col.AllowNulls)
                {
                    null_var=new CodeMemberField(typeof(bool),col.Name + "ISNULL");
                    null_var.Attributes=MemberAttributes.Public | MemberAttributes.Final;
                    null_var.InitExpression=new CodePrimitiveExpression(true);
                    maClasse.Members.Add(null_var);
                }

                // definition d'une reference a une variable
                CodeFieldReferenceExpression ref_var = null;
                ref_var = new CodeFieldReferenceExpression();
                ref_var.TargetObject = new CodeThisReferenceExpression();
                ref_var.FieldName = priv_var.Name;

                CodeFieldReferenceExpression ref_null_var=null;
                if (col.AllowNulls)
                {
                    ref_null_var = new CodeFieldReferenceExpression();
                    ref_null_var.TargetObject = new CodeThisReferenceExpression();
                    ref_null_var.FieldName = null_var.Name;
                }

                CodeMemberProperty champDB = new CodeMemberProperty();
                champDB.Attributes = MemberAttributes.Public | MemberAttributes.Final;
                champDB.Type = new CodeTypeReference(dotNetType);
                champDB.Name = col.Name;
                champDB.HasGet = true;
                champDB.HasSet = true;
                CodeMethodReturnStatement returnRefThis = new CodeMethodReturnStatement(ref_var);
                champDB.GetStatements.Add(returnRefThis);

                CodeAssignStatement setField=new CodeAssignStatement(ref_var,new CodePropertySetValueReferenceExpression());
                champDB.SetStatements.Add(setField);
                if (col.AllowNulls)
                {
                    CodeAssignStatement setFieldIsNullToFalse=new CodeAssignStatement(ref_null_var,new CodePrimitiveExpression(false));
                    champDB.SetStatements.Add(setFieldIsNullToFalse);
                }

                // création de l'attribut pour la propriété en cours
                attr=new CodeAttributeDeclaration();
                attr.Name="DBField";
                attr.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(col.Name)));
                if (col.InPrimaryKey)
                {
                    attr.Arguments.Add(new CodeAttributeArgument("PrimaryKey", new CodePrimitiveExpression(true)));
                }
                if (col.Identity)
                {
                    attr.Arguments.Add(new CodeAttributeArgument("Identity", new CodePrimitiveExpression(true)));
                }
                if (col.AllowNulls)
                {
                    attr.Arguments.Add(new CodeAttributeArgument("IsNullable", new CodePrimitiveExpression(true)));
                    //attr.Arguments.Add(new CodeAttributeArgument("NullValue", new CodePrimitiveExpression(GetDefaultValueForNull(col.PhysicalDatatype))));
                }

                champDB.CustomAttributes.Add(attr); // ajout de l'attribut sur la prop

                maClasse.Members.Add(champDB);	// ajout de la propriété dans la classe
            }

            // On génère finalement le code
            System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
            TextWriter textWriter = new StringWriter(stringBuilder);

            try
            {
                codeGenerator.GenerateCodeFromNamespace(monNamespace, textWriter, null);
            }
            catch (Exception exception)
            {
                return(exception.ToString());
            }
            finally
            {
                textWriter.Close();
            }

            return(stringBuilder.ToString());
        }
开发者ID:flyingoverclouds,项目名称:sfinx,代码行数:101,代码来源:frmStoredProcCreator.cs


注:本文中的ICodeGenerator.GenerateCodeFromNamespace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。