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


C# Compiler.CodeDomProvider类代码示例

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


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

示例1: ImportSchemaType

        //public override string ImportSchemaType(
        //    string name, 
        //    string ns, 
        //    XmlSchemaObject context, 
        //    XmlSchemas schemas, 
        //    XmlSchemaImporter importer,
        //    CodeCompileUnit compileUnit, 
        //    CodeNamespace mainNamespace, 
        //    CodeGenerationOptions options, 
        //    CodeDomProvider codeProvider)
        //{

        //    XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType) schemas.Find(new XmlQualifiedName(name, ns), typeof(XmlSchemaSimpleType));
        //    return ImportSchemaType(
        //        simpleType, 
        //        context, 
        //        schemas, 
        //        importer, 
        //        compileUnit, 
        //        mainNamespace, 
        //        options, 
        //        codeProvider);
        //}

        public override string ImportSchemaType(
            XmlSchemaType type, 
            XmlSchemaObject context, 
            XmlSchemas schemas, 
            XmlSchemaImporter importer,
            CodeCompileUnit compileUnit, 
            CodeNamespace mainNamespace, 
            CodeGenerationOptions options, 
            CodeDomProvider codeProvider)
        {

            XmlSchemaAnnotated annotatedType  = type as XmlSchemaAnnotated;
            if (annotatedType == null)
                return null;

            if (annotatedType.Annotation == null)
                return null;

            // create the comments and add them to the hash table under the namespace of the object
            CreateComments(annotatedType);

            //mainNamespace.Types.

            return null;

        }
开发者ID:nujmail,项目名称:xsd-to-classes,代码行数:50,代码来源:AnnotationTypeExtension.cs

示例2: Execute

        public override bool Execute() {
            try {
                try {
                    codeDomProvider = CodeDomProvider.CreateProvider(Language);
                } catch (ConfigurationErrorsException) {
                    LogError(classNameLineNumber, 1, "CodeDom provider for language '" + Language + "' not found.");
                    return false;
                }

                typeAttributesConverter = codeDomProvider.GetConverter(typeof(TypeAttributes));

                if (!ParseInput()) {
                    return false;
                }

                if (lambdas.Count == 0) {
                    OutputFileName = null;
                    return true;
                }

                if (className == null) {
                    LogError(classNameLineNumber, 1501, "x:Class not found on root element.");
                    return false;
                }
                if (!className.Contains(".")) {
                    LogError(classNameLineNumber, 1502, "x:Class does not include namespace name.");
                    return false;
                }

                return GenerateOutput();
            } catch (Exception ex) {
                LogError(null, 0, 0, ex.Message);
                return false;
            }
        }
开发者ID:CforED,项目名称:Node.js-Tools-for-Visual-Studio,代码行数:35,代码来源:ExtractLambdasFromXaml.cs

示例3: Compile

		public static Assembly Compile(CodeDomProvider cp, string scriptCode, IList assemblies)
		{
			ICodeCompiler ic = cp.CreateCompiler();
			CompilerParameters cpar = GetCompilerParameters(assemblies);
			CompilerResults cr = ic.CompileAssemblyFromSource(cpar, scriptCode);

			bool errors = false;

			if (cr.Errors.Count > 0)
			{
				StringBuilder sb = new StringBuilder("Error compiling the composition script:\n");
				foreach (CompilerError ce in cr.Errors)
				{
					if (!ce.IsWarning)
					{
						errors = true;

						sb.Append("\nError number:\t")
							.Append(ce.ErrorNumber)
							.Append("\nMessage:\t ")
							.Append(ce.ErrorText)
							.Append("\nLine number:\t")
							.Append(ce.Line);
					}
				}
				if (errors)
				{
					throw new PicoCompositionException(sb.ToString());
				}
			}

			return cr.CompiledAssembly;
		}
开发者ID:smmckay,项目名称:picocontainer,代码行数:33,代码来源:FrameworkCompiler.cs

示例4: GetTypeUpdates

		public Dictionary<string, List<NSObjectTypeInfo>> GetTypeUpdates (IProgressMonitor monitor, CodeDomProvider provider,
			out Dictionary<string, NSObjectTypeInfo> newTypes,
			out Dictionary<string, ProjectFile> newFiles)
		{
			Dictionary<string, List<NSObjectTypeInfo>> designerFiles = new Dictionary<string, List<NSObjectTypeInfo>> ();
			string defaultNamespace;
			
			// First, we need to name any new user-defined types.
			foreach (var job in TypeSyncJobs) {
				if (!job.IsFreshlyAdded) {
					monitor.Log.WriteLine ("Found updated class: {0}", job.Type.CliName);
					continue;
				}
				
				defaultNamespace = Project.GetDefaultNamespace (job.RelativePath);
				job.Type.CliName = defaultNamespace + "." + provider.CreateValidIdentifier (job.Type.ObjCName);
				monitor.Log.WriteLine ("Found newly-added class: {0}", job.Type.CliName);
				ProjectInfo.InsertUpdatedType (job.Type);
			}
			
			// Next we can resolve base-types, outlet types, and action parameter types for each of our user-defined types.
			foreach (var job in TypeSyncJobs) {
				defaultNamespace = Project.GetDefaultNamespace (job.RelativePath);
				ProjectInfo.ResolveObjcToCli (monitor, job.Type, provider, defaultNamespace);
			}
			
			AggregateTypeUpdates (monitor, provider, designerFiles, out newTypes, out newFiles);
			MergeExistingTypes (designerFiles);
			
			return designerFiles;
		}
开发者ID:JamesChan,项目名称:monodevelop,代码行数:31,代码来源:XcodeSyncBackContext.cs

示例5: ImportSchemaType

		public override string ImportSchemaType(XmlSchemaType type, XmlSchemaObject context, XmlSchemas schemas, XmlSchemaImporter importer, CodeCompileUnit compileUnit, CodeNamespace mainNamespace, CodeGenerationOptions options, CodeDomProvider codeProvider) {
			if (type == null) {
				return null;
			}

			if (importedTypes[type] != null) {
				mainNamespace.Imports.Add(new CodeNamespaceImport(typeof(DataSet).Namespace));
				compileUnit.ReferencedAssemblies.Add("System.Data.dll");
				return (string)importedTypes[type];
			}
			if (!(context is XmlSchemaElement))
				return null;

			if (type is XmlSchemaComplexType) {
				XmlSchemaComplexType ct = (XmlSchemaComplexType)type;
				if (ct.Particle is XmlSchemaSequence) {
					XmlSchemaObjectCollection items = ((XmlSchemaSequence)ct.Particle).Items;
					if (items.Count == 2 && items[0] is XmlSchemaAny && items[1] is XmlSchemaAny) {
						XmlSchemaAny any0 = (XmlSchemaAny)items[0];
						XmlSchemaAny any1 = (XmlSchemaAny)items[1];
						if (any0.Namespace == XmlSchema.Namespace && any1.Namespace == "urn:schemas-microsoft-com:xml-diffgram-v1") {
							string typeName = typeof(DataTable).FullName;
							importedTypes.Add(type, typeName);
							mainNamespace.Imports.Add(new CodeNamespaceImport(typeof(DataTable).Namespace));
							compileUnit.ReferencedAssemblies.Add("System.Data.dll");
							return typeName;
						}
					}
				}
			}
			return null;
		}
开发者ID:GodLesZ,项目名称:svn-dump,代码行数:32,代码来源:DataTableSchemaImporterExtension.cs

示例6: CreateFileCodeModel

 public static FileCodeModel CreateFileCodeModel(DTE dte, ProjectItem item, CodeDomProvider provider, string fileName)
 {
     if (null == item) {
         throw new ArgumentNullException("item");
     }
     return new CodeDomFileCodeModel(dte, item, provider, fileName);
 }
开发者ID:ufosky-server,项目名称:MultiversePlatform,代码行数:7,代码来源:PythonCodeModelFactory.cs

示例7: Supports

        protected bool Supports (CodeDomProvider provider, GeneratorSupport support) {
#if WHIDBEY
            return provider.Supports (support);
#else
            return (provider.CreateGenerator ()).Supports (support);
#endif
        }
开发者ID:modulexcite,项目名称:powerpack-archive,代码行数:7,代码来源:CodeDomTest.cs

示例8: CodeDomFileCodeModel

        private CodeDomCodeNamespace vsTopNamespace; // top-level CodeModel namespace

        #endregion Fields

        #region Constructors

        public CodeDomFileCodeModel(DTE dte, ProjectItem parent, CodeDomProvider provider, string filename)
            : base(dte, filename)
        {
            this.parent = parent;
            this.provider = provider as IMergableProvider;
            if (provider == null) throw new ArgumentException("provider must implement IMergeableProvider interface");
        }
开发者ID:smartmobili,项目名称:parsing,代码行数:13,代码来源:FileCodeModel.cs

示例9: Process

        /// <summary>Called when extension shall processs generated CodeDOM</summary>
        /// <param name="code">Object tree representing generated CodeDOM</param>
        /// <param name="schema">Input XML schema</param>
        /// <param name="provider">CodeDOM provider (the language)</param>
        /// <version version="1.5.3">Added documentation</version>
        /// <version version="1.5.3">Parameter <c>Provider</c> renamed to <c>provider</c></version>
        public void Process(CodeNamespace code, XmlSchema schema, CodeDomProvider provider)
        {
            // Copy as we will be adding types.
            CodeTypeDeclaration[] types =
                new CodeTypeDeclaration[code.Types.Count];
            code.Types.CopyTo(types, 0);

            foreach (CodeTypeDeclaration type in types) {
                if (type.IsClass || type.IsStruct) {
                    foreach (CodeTypeMember member in type.Members) {
                        if (member is CodeMemberField && ((CodeMemberField)member).Type.ArrayElementType != null) {
                            CodeMemberField field = (CodeMemberField)member;
                            // Change field type to collection.
                            field.Type = GetCollection(field.Type.ArrayElementType);
                            field.InitExpression = new CodeObjectCreateExpression(field.Type);
                            if (field.Name.EndsWith("Field"))
                                field.Comments.Add(new CodeCommentStatement(string.Format("<summary>Contains value of the <see cref='{0}'/> property</summary>", field.Name.Substring(0, field.Name.Length - "field".Length)), true));
                        } else if (member is CodeMemberProperty && ((CodeMemberProperty)member).Type.ArrayElementType != null) {
                            CodeMemberProperty Property = (CodeMemberProperty)member;
                            Property.Type = GetCollection(Property.Type.ArrayElementType);
                            Property.HasSet = false;
                        }
                    }
                }
            }
        }
开发者ID:wskplho,项目名称:Tools,代码行数:32,代码来源:ArraysToGenericCollections.cs

示例10: ProjectCompiler

 public ProjectCompiler(Logger logger, CodeDomProvider codeProvider,
     IEnumerable<Path> referencedAssemblies)
 {
     this.logger = logger;
     this.codeProvider = codeProvider;
     this.referencedAssemblies = referencedAssemblies;
 }
开发者ID:danaxa,项目名称:Pencil,代码行数:7,代码来源:ProjectCompiler.cs

示例11: WriteClassFile

		private void WriteClassFile(Project project, String name, CodeNamespace ns, CodeDomProvider provider)
		{
			String filename =  String.Format("{0}.{1}", name, provider.FileExtension);

			FileInfo fileInfo = new FileInfo( Path.Combine(project.LastOutDir, filename) );

			if (fileInfo.Exists && !project.OverwriteFiles)
			{
				Log( String.Format("Skipping {0} as it already exists", filename) );
			}
			else
			{
				Log( String.Format("Writing {0}...", filename) );

				try
				{
					using(FileStream stream = new FileStream(fileInfo.FullName, FileMode.Create, FileAccess.Write))
					{
						StreamWriter writer = new StreamWriter(stream);
						CodeGeneratorOptions opts = new CodeGeneratorOptions();
						opts.BracingStyle = "C";
						opts.BlankLinesBetweenMembers = true;
						provider.CreateGenerator().GenerateCodeFromNamespace(ns, writer, opts);
						writer.Flush();
						writer.Close();
					}
				}
				catch(Exception ex)
				{
					Log( String.Format("Error Writing {0} []", filename, ex.Message) );
				}
			}
		}
开发者ID:ralescano,项目名称:castle,代码行数:33,代码来源:ProjectGenerator.cs

示例12: Compile

 public bool Compile(CodeDomProvider codeProvider, string source, TempFileRef dataContextAssembly, QueryLanguage queryKind, string compilerOptions)
 {
     if (this.IsMyExtensions)
     {
         string directoryName = Path.GetDirectoryName(MyExtensions.QueryFilePath);
         if (!Directory.Exists(directoryName))
         {
             Directory.CreateDirectory(directoryName);
         }
         TempFileRef ref2 = new TempFileRef(Path.ChangeExtension(MyExtensions.QueryFilePath, ".dll")) {
             AutoDelete = false
         };
         this.OutputFile = ref2;
         TempFileRef ref3 = new TempFileRef(Path.ChangeExtension(MyExtensions.QueryFilePath, ".pdb")) {
             AutoDelete = false
         };
         this.PDBFile = ref3;
     }
     else
     {
         this.OutputFile = TempFileRef.GetRandom("query", ".dll");
         this.PDBFile = new TempFileRef(Path.ChangeExtension(this.OutputFile.FullPath, ".pdb"));
     }
     List<string> references = new List<string>(this.References);
     if (!((dataContextAssembly == null) || string.IsNullOrEmpty(dataContextAssembly.FullPath)))
     {
         references.Add(dataContextAssembly.FullPath);
     }
     return base.Compile(codeProvider, references, source.ToString(), this.OutputFile.FullPath, compilerOptions);
 }
开发者ID:CuneytKukrer,项目名称:TestProject,代码行数:30,代码来源:QueryCompiler.cs

示例13: StartProcessingRun

		public override void StartProcessingRun (CodeDomProvider languageProvider, string templateContents, CompilerErrorCollection errors)
		{
			base.StartProcessingRun (languageProvider, templateContents, errors);
			provider = languageProvider;
			postStatements.Clear ();
			members.Clear ();
		}
开发者ID:FreeBSD-DotNet,项目名称:monodevelop,代码行数:7,代码来源:ParameterDirectiveProcessor.cs

示例14: BindingElementExtensionSectionGenerator

        internal BindingElementExtensionSectionGenerator(Type bindingElementType, Assembly userAssembly, CodeDomProvider provider)
        {
            this.bindingElementType = bindingElementType;
            this.userAssembly = userAssembly;
            this.provider = provider;

            string typePrefix = bindingElementType.Name.Substring(0, bindingElementType.Name.IndexOf(TypeNameConstants.BindingElement));
            this.generatedClassName = typePrefix + Constants.ElementSuffix;
            this.constantsClassName = bindingElementType.Name.Substring(0, bindingElementType.Name.IndexOf(TypeNameConstants.BindingElement)) + Constants.ConfigurationStrings;
            this.defaultValuesClassName = bindingElementType.Name.Substring(0, bindingElementType.Name.IndexOf(TypeNameConstants.BindingElement)) + Constants.Defaults;

            this.customBEVarInstance = Helpers.TurnFirstCharLower(bindingElementType.Name);
            customBEArgRef = new CodeArgumentReferenceExpression(customBEVarInstance);

            this.customBETypeRef = new CodeTypeReference(bindingElementType.Name);
            this.customBETypeOfRef = new CodeTypeOfExpression(customBETypeRef);
            this.customBENewVarAssignRef = new CodeVariableDeclarationStatement(
                                                customBETypeRef,
                                                customBEVarInstance,
                                                new CodeObjectCreateExpression(customBETypeRef));
            this.bindingElementMethodParamRef = new CodeParameterDeclarationExpression(
                                                    CodeDomHelperObjects.bindingElementTypeRef,
                                                    Constants.bindingElementParamName);

        }
开发者ID:ssickles,项目名称:archive,代码行数:25,代码来源:BindingElementExtensionSectionGenerator.cs

示例15: PostProcess

 /// <summary>Called when extension shall process generated code</summary>
 /// <param name="code">The code</param>
 /// <param name="provider">CodeDOM provider (the language)</param>
 /// <version version="1.5.3">Parameter <c>Provider</c> renamed to <c>provider</c></version>
 public void PostProcess(ref string code, CodeDomProvider provider)
 {
     System.IO.StringWriter tw = new System.IO.StringWriter();
     provider.GenerateCodeFromStatement(new CodeCommentStatement(FirtsLineOfAccessor), tw, new System.CodeDom.Compiler.CodeGeneratorOptions());
     string srch = tw.GetStringBuilder().ToString();
     if (srch.EndsWith("\r\n")) srch = srch.Substring(0, srch.Length - 2);
     else if (srch.EndsWith("\r") || srch.EndsWith("\n")) srch = srch.Substring(0, srch.Length - 1);
     tw = new System.IO.StringWriter();
     CodeTypeDeclaration foo = new CodeTypeDeclaration("foo");
     foo.CustomAttributes.Add(NewAttribute);
     provider.GenerateCodeFromType(foo, tw, new System.CodeDom.Compiler.CodeGeneratorOptions());
     string attr = new System.IO.StringReader(tw.GetStringBuilder().ToString()).ReadLine();
     System.IO.StringReader sr = new System.IO.StringReader(code);
     List<String> Lines = new List<string>();
     do {
         string line = sr.ReadLine();
         if (line == null) break;
         if (line.EndsWith(srch))
             Lines[Lines.Count - 1] = attr + "\r\n" + Lines[Lines.Count - 1];
         else
             Lines.Add(line);
     } while (true);
     System.Text.StringBuilder b = new System.Text.StringBuilder();
     foreach (string line in Lines)
         b.AppendLine(line);
     code = b.ToString();
 }
开发者ID:wskplho,项目名称:Tools,代码行数:31,代码来源:DebuggerStepThrough.cs


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