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


C# AssemblyBuilder.CreateCodeFile方法代码示例

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


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

示例1: GenerateCode

        // see http://msdn.microsoft.com/en-us/library/system.web.compilation.assemblybuilder.createcodefile%28v=vs.90%29.ASPX
        // there _is_ a way to create source code files, so we _could_ use the TextBuilder
        // but here we're assuming that going for CodeDom is faster (?)

        // no, wait -- anyway CodeDomBuilder will never work because umbraco is not
        // up and running at the time GenerateCode is invoked, so the code files have
        // to be generated beforehand and the builder should just insert them in the
        // right place...

        // can it generate them in app_code?
        // idea would be to drop a models.models file in App_Code that would trigger the build
        // this is for ppl who don't have visual studio, anyway... if you have VS you want to
        // build with VS and then copy the code over to the server, based upon models.cs

        // the actual files generation has to be triggered by the UI

        public override void GenerateCode(AssemblyBuilder assemblyBuilder)
        {
            // issue: I can't put my files into App_Code or they'll get... compiled... too soon?

            if (!Config.EnableAppCodeModels)
                throw new Exception("Building models from App_Code is not enabled, yet a .models file was found in App_Code.");

            var appData = HostingEnvironment.MapPath("~/App_Data");
            if (appData == null)
                throw new Exception("Could not map path ~/App_Data.");
            if (!Directory.Exists(appData))
                throw new Exception("Could not find ~/App_Data.");
            var modelsDirectory = Path.Combine(appData, "Models");
            if (!Directory.Exists(modelsDirectory))
                return;

            foreach (var file in Directory.GetFiles(modelsDirectory, "*.cs"))
            {
                var text = File.ReadAllText(file);
                var textWriter = assemblyBuilder.CreateCodeFile(this);
                textWriter.Write(text);
                textWriter.Close();
            }
        }
开发者ID:nul800sebastiaan,项目名称:Zbu.ModelsBuilder,代码行数:40,代码来源:ModelsBuildProvider.cs

示例2: GenerateCodeFromDataServiceMapFile

        /// <summary>
        /// Generate code for one .datasvcmap file
        /// </summary>
        /// <param name="mapFilePath">The physical path to the data service map file</param>
        private void GenerateCodeFromDataServiceMapFile(string mapFilePath, AssemblyBuilder assemblyBuilder)
        {
            try
            {
                assemblyBuilder.AddAssemblyReference(typeof(System.Data.Services.Client.DataServiceContext).Assembly);

                DataSvcMapFileLoader loader = new DataSvcMapFileLoader(mapFilePath);
                DataSvcMapFile mapFile = loader.LoadMapFile() as DataSvcMapFile;

                if (mapFile.MetadataList[0].ErrorInLoading != null)
                {
                    throw mapFile.MetadataList[0].ErrorInLoading;
                }

                string edmxContent = mapFile.MetadataList[0].Content;

                System.Data.Services.Design.EntityClassGenerator generator = new System.Data.Services.Design.EntityClassGenerator(LanguageOption.GenerateCSharpCode);

                // the EntityClassGenerator works on streams/writers, does not return a CodeDom
                // object, so we use CreateCodeFile instead of compile units.
                using (TextWriter writer = assemblyBuilder.CreateCodeFile(this))
                {

                    // Note: currently GenerateCode never actually returns values
                    // for the error case (even though it returns an IList of error
                    // objects). Instead it throws on error. This may need some tweaking 
                    // later on.
#if DEBUG
                object errors = 
#endif
                    generator.GenerateCode(
                        XmlReader.Create(new StringReader(edmxContent)),
                        writer,
                        GetGeneratedNamespace());

#if DEBUG
                Debug.Assert(
                    errors == null ||
                    !(errors is ICollection) ||
                    ((ICollection)errors).Count == 0,
                    "Errors reported through the return value. Expected an exception");
#endif
                    writer.Flush();
                }
            }
            catch (Exception ex)
            {
                string errorMessage = ex.Message;
                errorMessage = String.Format(CultureInfo.CurrentCulture, "{0}: {1}", IO.Path.GetFileName(mapFilePath), errorMessage);
                throw new InvalidOperationException(errorMessage, ex);
            }
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:56,代码来源:WCFBuildProvider.cs

示例3: WriteCodeFile

 void WriteCodeFile(AssemblyBuilder assemblyBuilder, BuildProvider buildProvider, string name)
 {
     using (TextWriter codeFile = assemblyBuilder.CreateCodeFile(buildProvider))
     {
         foreach (string line in File.ReadLines(name))
         {
             codeFile.WriteLine(line);
         }
     }
 }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:10,代码来源:XamlBuildProviderExtension.cs

示例4: GenerateCode

		/// <summary>
		/// Generate the code from .apgen file.
		/// </summary>
		/// <param name="assemblyBuilder">AssemblyBuilder</param>
		public override void GenerateCode(AssemblyBuilder assemblyBuilder)
		{
			if (!flag && BuildManager.CodeAssemblies != null && getProfileMethodCount > 0)
			{
				getProfileMethodCount = 0;
				flag = true;
			}

			string path = Path.Combine(
				HttpRuntime.AppDomainAppPath,
				VirtualPath.Substring(HttpRuntime.AppDomainAppVirtualPath.Length + (HttpRuntime.AppDomainAppVirtualPath.Length == 1 ? 0 : 1)));

			using (TextWriter writer = assemblyBuilder.CreateCodeFile(this))
			{
				APGen gen = APGenManager.OpenGenDocument(path);
				CodeDomProvider provider = assemblyBuilder.CodeDomProvider;
				provider.GenerateCodeFromCompileUnit(gen.Generate(), writer, null);

				writer.Flush();
				writer.Close();
			}
		}
开发者ID:fankluo,项目名称:APQuery.net,代码行数:26,代码来源:APGenBuildProvider.cs


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