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


C# CodeDom.CodeNamespace类代码示例

本文整理汇总了C#中System.CodeDom.CodeNamespace的典型用法代码示例。如果您正苦于以下问题:C# CodeNamespace类的具体用法?C# CodeNamespace怎么用?C# CodeNamespace使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CodeNamespace类属于System.CodeDom命名空间,在下文中一共展示了CodeNamespace类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InvokeWebService

        public static object InvokeWebService(string url, string classname, string methodname, object[] args)
        {
            string @namespace = "EnterpriseServerBase.WebService.DynamicWebCalling";
            if ((classname == null) || (classname == ""))
            {
                classname = WebServiceProxy.GetWsClassName(url);
            }

            try
            {
                //获取WSDL
                WebClient wc = new WebClient();
                Stream stream = wc.OpenRead(url + "?WSDL");
                ServiceDescription sd = ServiceDescription.Read(stream);
                ServiceDescriptionImporter sdi = new ServiceDescriptionImporter();
                sdi.AddServiceDescription(sd, "", "");
                CodeNamespace cn = new CodeNamespace(@namespace);

                //生成客户端代理类代码
                CodeCompileUnit ccu = new CodeCompileUnit();
                ccu.Namespaces.Add(cn);
                sdi.Import(cn, ccu);
                CSharpCodeProvider csc = new CSharpCodeProvider();
                ICodeCompiler icc = csc.CreateCompiler();

                //设定编译参数
                CompilerParameters cplist = new CompilerParameters();
                cplist.GenerateExecutable = false;
                cplist.GenerateInMemory = true;
                cplist.ReferencedAssemblies.Add("System.dll");
                cplist.ReferencedAssemblies.Add("System.XML.dll");
                cplist.ReferencedAssemblies.Add("System.Web.Services.dll");
                cplist.ReferencedAssemblies.Add("System.Data.dll");

                //编译代理类
                CompilerResults cr = icc.CompileAssemblyFromDom(cplist, ccu);
                if (true == cr.Errors.HasErrors)
                {
                    System.Text.StringBuilder sb = new System.Text.StringBuilder();
                    foreach (System.CodeDom.Compiler.CompilerError ce in cr.Errors)
                    {
                        sb.Append(ce.ToString());
                        sb.Append(System.Environment.NewLine);
                    }
                    throw new Exception(sb.ToString());
                }

                //生成代理实例,并调用方法
                System.Reflection.Assembly assembly = cr.CompiledAssembly;
                Type t = assembly.GetType(@namespace + "." + classname, true, true);
                object obj = Activator.CreateInstance(t);
                System.Reflection.MethodInfo mi = t.GetMethod(methodname);

                return mi.Invoke(obj, args);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.InnerException.Message, new Exception(ex.InnerException.StackTrace));
            }
        }
开发者ID:SLSoft,项目名称:GGZBTQPT,代码行数:60,代码来源:WebServiceProxy.cs

示例2: CreateImports

 /// <summary>
 /// Adiciona using no namespace
 /// </summary>
 /// <param name="customNamespace"></param>
 /// <param name="nameSpaces"></param>
 public void CreateImports(ref CodeNamespace customNamespace, params string[] nameSpaces)
 {
     foreach (var item in nameSpaces)
     {
         customNamespace.Imports.Add(new CodeNamespaceImport(item));
     }
 }
开发者ID:govinda777,项目名称:WorkflowPoc,代码行数:12,代码来源:FactoryCode.cs

示例3: ImproveEnumFieldsCommand

        public ImproveEnumFieldsCommand(CodeNamespace code)
        {
            if (code == null)
                throw new ArgumentNullException("code");

            this.code = code;
        }
开发者ID:hazzik,项目名称:nh-contrib-everything,代码行数:7,代码来源:ImproveEnumFieldsCommand.cs

示例4: CreateSpecs

        public string CreateSpecs(out int specCount)
        {
            var files = FindSpecFiles().ToArray();
            specCount = files.Length;
            if (specCount < 1)
                return string.Empty;

            var compile = new CodeCompileUnit();

            var globalns = new CodeNamespace();
            globalns.Imports.Add(new CodeNamespaceImport("NUnit.Framework"));
            globalns.Imports.Add(new CodeNamespaceImport(config.MyNamespace));
            compile.Namespaces.Add(globalns);
            var specNamespace = new CodeNamespace(config.TargetNamespace + ".ChutzpahSpecs");
            compile.Namespaces.Add(specNamespace);

            foreach (var fileInfo in files)
            {
                AddSpec(specNamespace, fileInfo);
            }
            //specNamespace.Types.AddRange(files.Select(CreateSpec).ToArray());

            var provider = CreateProvider();
            var options = new CodeGeneratorOptions { BracingStyle = "C", BlankLinesBetweenMembers = false };
            var stringBuilder = new StringBuilder();
            using (var writer = new StringWriter(stringBuilder))
            {
                provider.GenerateCodeFromCompileUnit(compile, writer, options);
                writer.Flush();
                writer.Close();
            }
            var result = stringBuilder.ToString();
            return result;
        }
开发者ID:vurt007,项目名称:ghost-bridge,代码行数:34,代码来源:NUnitCodeProvider.cs

示例5: CreateModels

        public void CreateModels(IEnumerable<OvhApi> apis)
        {
            Dictionary<string,ModelType> modelsByNamespace = new Dictionary<string, ModelType>();
            foreach (var ovhApi in apis)
            {
                foreach (var model in ovhApi.Models)
                {
                    string fullTypeName = Util.GetType(model.Key);

                    if (modelsByNamespace.ContainsKey(fullTypeName))
                        continue;

                    modelsByNamespace.Add(fullTypeName, new ModelType(model.Value));
                }
            }

            foreach (var st in modelsByNamespace)
            {
                string modelNamespace = Util.GetNamespace(st.Value.Model);

                if (modelsByNamespace.ContainsKey(modelNamespace))
                {
                    modelsByNamespace[modelNamespace].AddChild(st.Value);
                }
            }

            foreach (var type in modelsByNamespace.Where(x => x.Value.Parent == null))
            {
                CodeNamespace ns = new CodeNamespace(Util.GetNamespace(type.Value.Model));
                ns.Types.Add(CreateType(type.Value));
                _code.Namespaces.Add(ns);
            }
        }
开发者ID:biapar,项目名称:ovhapicil,代码行数:33,代码来源:ModelGenerator.cs

示例6: BuildProgram

        static CodeNamespace BuildProgram()
        {
            // namespaceの作成
            var ns = new CodeNamespace("MetaWorld");
            // import編成
            var systemImport = new CodeNamespaceImport("System");
            // class作成
            var programClass = new CodeTypeDeclaration("Program");

            // mainメソッドの定義
            var methodMain = new CodeMemberMethod()
            {
                Attributes = MemberAttributes.Static,
                Name = "Main"
            };
            methodMain.Statements.Add(
                new CodeMethodInvokeExpression(
                    new CodeSnippetExpression("Console"),
                    "WriteLine",
                    new CodePrimitiveExpression("Hello World")
                    )
                );

            // コード構造の編成
            programClass.Members.Add(methodMain);
            ns.Imports.Add(systemImport);
            ns.Types.Add(programClass);
            return ns;
        }
开发者ID:read-only-man,项目名称:Cs,代码行数:29,代码来源:HelloWorldCodeDOM.cs

示例7: CodeSnippetBlankLines

		public void CodeSnippetBlankLines ()
		{
			var opt = new CodeGeneratorOptions () {
				BlankLinesBetweenMembers = false,
				VerbatimOrder = false
			};

			var ccu = new CodeCompileUnit ();
			var ns = new CodeNamespace ("Foo");
			ccu.Namespaces.Add (ns);
			var t = new CodeTypeDeclaration ("Bar");
			ns.Types.Add (t);

			t.Members.Add (new CodeSnippetTypeMember ("#line hidden"));
			t.Members.Add (new CodeSnippetTypeMember ("#line hidden2"));
	
			t.Members.Add (new CodeMemberMethod () { Name = "Foo" });

			using (var sw = new StringWriter ()) {
				new CSharpCodeProvider ().GenerateCodeFromCompileUnit (ccu, sw, opt);
				var str = sw.ToString ();

				Assert.IsFalse (str.Contains ("hidden2private"), "#0");
				Assert.IsTrue (str.Contains( "#line hidden#line hidden2"), "#1");
			}
		}
开发者ID:sushihangover,项目名称:playscript,代码行数:26,代码来源:CodeGeneratorGenerateFromCompileUnitTest.cs

示例8: PostProcessGeneratedCodeAddsApplicationInstanceProperty

        public void PostProcessGeneratedCodeAddsApplicationInstanceProperty() {
            const string expectedPropertyCode = @"
protected Foo.Bar ApplicationInstance {
    get {
        return ((Foo.Bar)(Context.ApplicationInstance));
    }
}
";

            // Arrange
            CodeCompileUnit generatedCode = new CodeCompileUnit();
            CodeNamespace generatedNamespace = new CodeNamespace();
            CodeTypeDeclaration generatedClass = new CodeTypeDeclaration();
            CodeMemberMethod executeMethod = new CodeMemberMethod();
            WebPageRazorHost host = new WebPageRazorHost("Foo.cshtml") {
                GlobalAsaxTypeName = "Foo.Bar"
            };

            // Act
            host.PostProcessGeneratedCode(generatedCode, generatedNamespace, generatedClass, executeMethod);

            // Assert
            CodeMemberProperty property = generatedClass.Members[0] as CodeMemberProperty;
            Assert.IsNotNull(property);

            CSharpCodeProvider provider = new CSharpCodeProvider();
            StringBuilder builder = new StringBuilder();
            using(StringWriter writer = new StringWriter(builder)) {
                provider.GenerateCodeFromMember(property, writer, new CodeDom.Compiler.CodeGeneratorOptions());
            }

            Assert.AreEqual(expectedPropertyCode, builder.ToString());
        }
开发者ID:adrianvallejo,项目名称:MVC3_Source,代码行数:33,代码来源:WebPageRazorEngineHostTest.cs

示例9: XmlSerializerOperationGenerator

 internal XmlSerializerOperationGenerator(XmlSerializerImportOptions options)
 {
     operationGenerator = new OperationGenerator();
     this.options = options;
     this.codeNamespace = GetTargetCodeNamespace(options);
     partInfoTable = new Dictionary<MessagePartDescription, PartInfo>();
 }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:7,代码来源:XmlSerializerOperationGenerator.cs

示例10: Generate

        public CodeCompileUnit Generate(ClassData classData)
        {
            if (classData == null)
            {
                throw FxTrace.Exception.ArgumentNull("classData");
            }
            CodeCompileUnit result = new CodeCompileUnit();

            // Add global namespace
            CodeNamespace globalNamespace = new CodeNamespace();
            result.Namespaces.Add(globalNamespace);

            CodeTypeDeclaration classDeclaration = GenerateClass(classData);
            if (!String.IsNullOrEmpty(classData.Namespace))
            {
                // Add namespace the class is defined in
                CodeNamespace classNamespace = new CodeNamespace(classData.Namespace);
                result.Namespaces.Add(classNamespace);
                classNamespace.Types.Add(classDeclaration);
            }
            else
            {
                // Add class to global namespace
                globalNamespace.Types.Add(classDeclaration);
            }

            return result;
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:28,代码来源:ClassGenerator.cs

示例11: GenerateWidgetCode

        static void GenerateWidgetCode(SteticCompilationUnit globalUnit, CodeNamespace globalNs, GenerationOptions options, List<SteticCompilationUnit> units, Gtk.Widget w, ArrayList warnings)
        {
            // Generate the build method

            CodeTypeDeclaration type = CreatePartialClass (globalUnit, units, options, w.Name);
            CodeMemberMethod met = new CodeMemberMethod ();
            met.Name = "Build";
            type.Members.Add (met);
            met.ReturnType = new CodeTypeReference (typeof(void));
            met.Attributes = MemberAttributes.Family;

            if (options.GenerateEmptyBuildMethod) {
                GenerateWrapperFields (type, Wrapper.Widget.Lookup (w));
                return;
            }

            met.Statements.Add (
                    new CodeMethodInvokeExpression (
                        new CodeTypeReferenceExpression (globalNs.Name + ".Gui"),
                        "Initialize",
                        new CodeThisReferenceExpression ()
                    )
            );

            Stetic.Wrapper.Widget wwidget = Stetic.Wrapper.Widget.Lookup (w);
            if (wwidget.GeneratePublic)
                type.TypeAttributes = TypeAttributes.Public;
            else
                type.TypeAttributes = TypeAttributes.NotPublic;

            Stetic.WidgetMap map = Stetic.CodeGenerator.GenerateCreationCode (globalNs, type, w, new CodeThisReferenceExpression (), met.Statements, options, warnings);
            CodeGenerator.BindSignalHandlers (new CodeThisReferenceExpression (), wwidget, map, met.Statements, options);
        }
开发者ID:mono,项目名称:stetic,代码行数:33,代码来源:CodeGeneratorPartialClass.cs

示例12: Main

        static void Main(string[] args)
        {
            CodeCompileUnit compileUnit = new CodeCompileUnit();
            CodeNamespace myNamespace = new CodeNamespace("MyNamespace");
            myNamespace.Imports.Add(new CodeNamespaceImport("System"));
            CodeTypeDeclaration myClass = new CodeTypeDeclaration("MyClass");
            CodeEntryPointMethod start = new CodeEntryPointMethod();
            CodeMethodInvokeExpression cs1 = new CodeMethodInvokeExpression(new CodeTypeReferenceExpression("Console"), "WriteLine", new CodePrimitiveExpression("Hello World"));
            compileUnit.Namespaces.Add(myNamespace);
            myNamespace.Types.Add(myClass);
            myClass.Members.Add(start);
            start.Statements.Add(cs1);

            CSharpCodeProvider provider = new CSharpCodeProvider();

            using(StreamWriter sw = new StreamWriter("HelloWorld.cs", false))
            {
                IndentedTextWriter tw = new IndentedTextWriter(sw, " ");
                provider.GenerateCodeFromCompileUnit(compileUnit, tw, new CodeGeneratorOptions());
                tw.Close();
            }

            Console.WriteLine("HelloWorld.cs generated in .../bin/Debug or .../bin/Release project folders.");

            Console.Write("Press a key to exit");
            Console.ReadKey();
        }
开发者ID:jbijoux,项目名称:Exam70_483,代码行数:27,代码来源:Program.cs

示例13: Build

        public void Build(DataStructure dataStructure, string rendererFilename = "")
        {
            if (string.IsNullOrEmpty(rendererFilename)) { rendererFilename = this.GetFilename(dataStructure); }

            var rendererType = new CodeTypeDeclaration(dataStructure.RendererName);
            rendererType.IsClass = true;
            rendererType.IsPartial = true;
            rendererType.BaseTypes.Add(typeof(Renderer));
            rendererType.Comments.Add(new CodeCommentStatement("<summary>", true));
            rendererType.Comments.Add(new CodeCommentStatement(string.Format("Renderer of {0}", dataStructure.TargetName), true));
            rendererType.Comments.Add(new CodeCommentStatement("</summary>", true));
            BuildCreate(rendererType, dataStructure);
            BuildConstructor(rendererType, dataStructure);
            BuildDoInitialize(rendererType, dataStructure);
            BuildDoRender(rendererType, dataStructure);

            var parserNamespace = new CodeNamespace("CSharpGL");
            parserNamespace.Imports.Add(new CodeNamespaceImport(typeof(System.Object).Namespace));
            parserNamespace.Imports.Add(new CodeNamespaceImport(typeof(System.Collections.Generic.List<int>).Namespace));
            parserNamespace.Types.Add(rendererType);

            //生成代码
            using (var stream = new StreamWriter(rendererFilename, false))
            {
                CSharpCodeProvider codeProvider = new CSharpCodeProvider();
                CodeGeneratorOptions opentions = new CodeGeneratorOptions();//代码生成选项
                opentions.BlankLinesBetweenMembers = true;
                opentions.BracingStyle = "C";
                opentions.ElseOnClosing = false;
                opentions.IndentString = "    ";
                opentions.VerbatimOrder = true;

                codeProvider.GenerateCodeFromNamespace(parserNamespace, stream, opentions);
            }
        }
开发者ID:bitzhuwei,项目名称:CSharpGL,代码行数:35,代码来源:RendererBuilder.cs

示例14: LoadFileElement

 private static CodeTypeDeclaration LoadFileElement(XmlElement element,
     CodeNamespace codeNamespace)
 {
     string className = element.GetAttribute("class");
     CodeTypeDeclaration codeType = new CodeTypeDeclaration(className);
     codeType.Attributes = MemberAttributes.Assembly;
     codeType.BaseTypes.Add(new CodeTypeReference("DbEntry"));
     int order = 0;
     foreach(XmlNode node in element.ChildNodes) {
         if(!(node is XmlElement)) continue;
         XmlElement childElement = (XmlElement)node;
         CodeMemberProperty codeProperty;
         if(childElement.Name == "field")
             LoadFieldElement(childElement, codeType, out codeProperty);
         else if(childElement.Name == "enum")
             LoadEnumElement(childElement, codeType, out codeProperty);
         else continue;
         codeProperty.CustomAttributes.Add(new CodeAttributeDeclaration(
             new CodeTypeReference("PropertyOrderAttribute"),
             new CodeAttributeArgument(new CodePrimitiveExpression(order++))));
     }
     CodeMemberMethod stringMethod = new CodeMemberMethod();
     stringMethod.Name = "ToString";
     stringMethod.Attributes = MemberAttributes.Public | MemberAttributes.Override;
     string stringMethodBody = element["string"].InnerText.TrimEnd(';');
     stringMethod.Statements.Add(new CodeSnippetExpression(stringMethodBody));
     stringMethod.ReturnType = new CodeTypeReference("System.String");
     codeType.Members.Add(stringMethod);
     return codeType;
 }
开发者ID:jaggedsoft,项目名称:aesirtk,代码行数:30,代码来源:Program.cs

示例15: ProcessGeneratedCode

 public override void ProcessGeneratedCode(CodeCompileUnit codeCompileUnit, CodeNamespace generatedNamespace, CodeTypeDeclaration generatedClass, CodeMemberMethod executeMethod)
 {
     if (!String.IsNullOrEmpty(_suffix))
     {
         generatedClass.Name += _suffix;
     }
 }
开发者ID:HansS,项目名称:ServiceStack,代码行数:7,代码来源:SuffixFileNameTransformer.cs


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