本文整理汇总了C#中System.CodeDom.CodeEntryPointMethod类的典型用法代码示例。如果您正苦于以下问题:C# CodeEntryPointMethod类的具体用法?C# CodeEntryPointMethod怎么用?C# CodeEntryPointMethod使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CodeEntryPointMethod类属于System.CodeDom命名空间,在下文中一共展示了CodeEntryPointMethod类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildHelloWorldGraph
// Builds a Hello World Program Graph using System.CodeDom objects
public static CodeCompileUnit BuildHelloWorldGraph()
{
// Create a new CodeCompileUnit to contain the program graph
CodeCompileUnit CompileUnit = new CodeCompileUnit();
// Declare a new namespace object and name it
CodeNamespace Samples = new CodeNamespace("Samples");
// Add the namespace object to the compile unit
CompileUnit.Namespaces.Add( Samples );
// Add a new namespace import for the System namespace
Samples.Imports.Add( new CodeNamespaceImport("System") );
// Declare a new type object and name it
CodeTypeDeclaration Class1 = new CodeTypeDeclaration("Class1");
// Add the new type to the namespace object's type collection
Samples.Types.Add(Class1);
// Declare a new code entry point method
CodeEntryPointMethod Start = new CodeEntryPointMethod();
// Create a new method invoke expression
CodeMethodInvokeExpression cs1 = new CodeMethodInvokeExpression(
// Call the System.Console.WriteLine method
new CodeTypeReferenceExpression("System.Console"), "WriteLine",
// Pass a primitive string parameter to the WriteLine method
new CodePrimitiveExpression("Hello World!") );
// Add the new method code statement
Start.Statements.Add(new CodeExpressionStatement(cs1));
// Add the code entry point method to the type's members collection
Class1.Members.Add( Start );
return CompileUnit;