"景先生毕设|www.jxszl.com

C# CodeMemberMethod类代码示例

2023-12-29 17:45编辑: www.jxszl.com景先生毕设
本文整理汇总了C#中CodeMemberMethod类的典型用法代码示例。如果您正苦于以下问题:C#CodeMemberMethod类的具体用法?C#CodeMemberMethod怎么用?C#CodeMemberMethod使用的例子?这里精选的类代码示例或许可以为您提供帮助。 示例1:BuildTree publicoverridevoidBuildTree(CodeDomProviderprovider,CodeCompileUnitcu){ //cu.UserData["AllowLateBound"]=true; //GENERATES(C#): //namespaceNamespace1{ //usingSystem; // // //publicclassClass1{ // //publicvirtualstringFoo1(stringformat,[System.Runtime.InteropServices.OptionalAttribute()]paramsobject[]array){ //stringstr; //str=format.Replace("{0}",array[0].ToString()); //str=str.Replace("{1}",array[1].ToString()); //str=str.Replace("{2}",array[2].ToString()); //returnstr; //} //} //} CodeNamespacens=newCodeNamespace("Namespace1"); ns.Imports.Add(newCodeNamespaceImport("System")); cu.Namespaces.Add(ns); //FullVerificationObjects CodeTypeDeclarationclass1=newCodeTypeDeclaration(); class1.Name="Class1"; ns.Types.Add(class1); AddScenario("CheckFoo1"); CodeMemberMethodfooMethod1=newCodeMemberMethod(); fooMethod1.Name="Foo1"; fooMethod1.Attributes=MemberAttributes.Public; fooMethod1.ReturnType=newCodeTypeReference(typeof(string)); CodeParameterDeclarationExpressionparameter1=newCodeParameterDeclarationExpression(); parameter1.Name="format"; parameter1.Type=newCodeTypeReference(typeof(string)); fooMethod1.Parameters.Add(parameter1); CodeParameterDeclarationExpressionparameter2=newCodeParameterDeclarationExpression(); parameter2.Name="array"; parameter2.Type=newCodeTypeReference(typeof(object[])); if(Supports(provider,GeneratorSupport.ParameterAttributes)){ parameter2.CustomAttributes.Add(newCodeAttributeDeclaration("System.ParamArrayAttribute")); parameter2.CustomAttributes.Add(newCodeAttributeDeclaration("System.Runtime.InteropServices.OptionalAttribute")); } fooMethod1.Parameters.Add(parameter2); class1.Members.Add(fooMethod1); fooMethod1.Statements.Add(newCodeVariableDeclarationStatement(typeof(string),"str")); fooMethod1.Statements.Add(CreateStatement(newCodeArgumentReferenceExpression("format"),0)); fooMethod1.Statements.Add(CreateStatement(newCodeVariableReferenceExpression("str"),1)); fooMethod1.Statements.Add(CreateStatement(newCodeVariableReferenceExpression("str"),2)); fooMethod1.Statements.Add(newCodeMethodReturnStatement(newCodeVariableReferenceExpression("str"))); }
原文链接:http://www.jxszl.com/biancheng/C/556803.html