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


C# global.GenerateCodeFromStatement方法代码示例

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


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

示例1: GeneratePostInitializationCode

		protected override void GeneratePostInitializationCode(string directiveName, global::System.Text.StringBuilder codeBuffer, global::System.CodeDom.Compiler.CodeDomProvider languageProvider, global::System.Collections.Generic.IDictionary<string, string> requiresArguments, global::System.Collections.Generic.IDictionary<string, string> providesArguments)
		{
			if ((global::System.StringComparer.OrdinalIgnoreCase.Compare(directiveName, supportedDirectiveName) == 0))
			{
				// We check the encoding of the model file, and ask the host to use that
				// encoding to write the output. This is to make sure we use the correct encoding
				// if the model file contains international characters that could be used in 
				// the template output.
				string fileName = requiresArguments[requiresFileParameter];
				if (!string.IsNullOrEmpty(fileName) && global::System.IO.File.Exists(fileName))
				{
					Host.SetOutputEncoding(VSTextTemplating::EncodingHelper.GetEncoding(fileName), false);
				}
	
				if (languageProvider != null)
				{
					global::System.CodeDom.CodeMethodInvokeExpression invokeLoad;
					global::System.String transactionName = providesArguments[providesModelParameter].ToLower(global::System.Globalization.CultureInfo.InvariantCulture) + "Transaction";
					global::System.CodeDom.CodeVariableDeclarationStatement transactionDeclaration = new global::System.CodeDom.CodeVariableDeclarationStatement(new global::System.CodeDom.CodeTypeReference(typeof(DslModeling::Transaction)), transactionName, new global::System.CodeDom.CodePrimitiveExpression(null));
					global::System.CodeDom.CodeStatement finallyStatement = new global::System.CodeDom.CodeConditionStatement(new global::System.CodeDom.CodeBinaryOperatorExpression(new global::System.CodeDom.CodeVariableReferenceExpression(transactionName), global::System.CodeDom.CodeBinaryOperatorType.IdentityInequality, new global::System.CodeDom.CodePrimitiveExpression(null)), new global::System.CodeDom.CodeExpressionStatement(new global::System.CodeDom.CodeMethodInvokeExpression(new global::System.CodeDom.CodeVariableReferenceExpression(transactionName), "Dispose")));
					global::System.Collections.Generic.List<global::System.CodeDom.CodeStatement> txTryStatements = new global::System.Collections.Generic.List<global::System.CodeDom.CodeStatement>();
					global::System.CodeDom.CodeVariableDeclarationStatement serializationResultDeclaration = new global::System.CodeDom.CodeVariableDeclarationStatement(new global::System.CodeDom.CodeTypeReference(typeof(DslModeling::SerializationResult)), "serializationResult", new global::System.CodeDom.CodeObjectCreateExpression(new global::System.CodeDom.CodeTypeReference(typeof(DslModeling::SerializationResult))));
	
					global::System.CodeDom.CodeMethodInvokeExpression invokeEnableDiagramRules = null;
					global::System.CodeDom.CodeVariableDeclarationStatement diagramFileDeclaration = null;
					global::System.CodeDom.CodeAssignStatement diagramFileAssign = null;
					if(LoadDiagramData)
					{
						// generate code to enable diagram fixup rules and load the diagram if required.
						invokeEnableDiagramRules = new global::System.CodeDom.CodeMethodInvokeExpression(
							new global::System.CodeDom.CodeMethodReferenceExpression(new global::System.CodeDom.CodeTypeReferenceExpression("ScheduledTasksDomainModel"), "EnableDiagramRules"), new global::System.CodeDom.CodePropertyReferenceExpression(new global::System.CodeDom.CodeThisReferenceExpression(), "Store"));
						diagramFileDeclaration = new global::System.CodeDom.CodeVariableDeclarationStatement(new global::System.CodeDom.CodeTypeReference("System.String"), "diagramFileName");
						diagramFileAssign = new global::System.CodeDom.CodeAssignStatement(new global::System.CodeDom.CodeVariableReferenceExpression("diagramFileName"), new global::System.CodeDom.CodeBinaryOperatorExpression(new global::System.CodeDom.CodePrimitiveExpression(requiresArguments[requiresFileParameter]), global::System.CodeDom.CodeBinaryOperatorType.Add, new global::System.CodeDom.CodePrimitiveExpression(".diagram")));
						invokeLoad = new global::System.CodeDom.CodeMethodInvokeExpression(
							new global::System.CodeDom.CodeMethodReferenceExpression(new global::System.CodeDom.CodeFieldReferenceExpression(new global::System.CodeDom.CodeTypeReferenceExpression(typeof(ScheduledTasksSerializationHelper)), "Instance"), "LoadModelAndDiagram"), new global::System.CodeDom.CodeVariableReferenceExpression("serializationResult"), new global::System.CodeDom.CodePropertyReferenceExpression(new global::System.CodeDom.CodeThisReferenceExpression(), "Store"), new global::System.CodeDom.CodePrimitiveExpression(requiresArguments[requiresFileParameter]), new global::System.CodeDom.CodeVariableReferenceExpression("diagramFileName"), new global::System.CodeDom.CodePrimitiveExpression(null), new global::System.CodeDom.CodePrimitiveExpression(null), new global::System.CodeDom.CodePrimitiveExpression(null));
					}
					else
					{
						invokeLoad = new global::System.CodeDom.CodeMethodInvokeExpression(
							new global::System.CodeDom.CodeMethodReferenceExpression(new global::System.CodeDom.CodeFieldReferenceExpression(new global::System.CodeDom.CodeTypeReferenceExpression(typeof(ScheduledTasksSerializationHelper)), "Instance"), "LoadModel"), new global::System.CodeDom.CodeVariableReferenceExpression("serializationResult"), new global::System.CodeDom.CodePropertyReferenceExpression(new global::System.CodeDom.CodeThisReferenceExpression(), "Store"), new global::System.CodeDom.CodePrimitiveExpression(requiresArguments[requiresFileParameter]), new global::System.CodeDom.CodePrimitiveExpression(null), new global::System.CodeDom.CodePrimitiveExpression(null), new global::System.CodeDom.CodePrimitiveExpression(null));
					}
	
					global::System.CodeDom.CodeAssignStatement loadAssign = new global::System.CodeDom.CodeAssignStatement(new global::System.CodeDom.CodeFieldReferenceExpression(new global::System.CodeDom.CodeThisReferenceExpression(), providesArguments[providesModelParameter].ToLower(global::System.Globalization.CultureInfo.InvariantCulture) + "Value"), invokeLoad);
					txTryStatements.Add(serializationResultDeclaration);
					txTryStatements.Add(new global::System.CodeDom.CodeAssignStatement(new global::System.CodeDom.CodeVariableReferenceExpression(transactionName), new global::System.CodeDom.CodeMethodInvokeExpression(new global::System.CodeDom.CodePropertyReferenceExpression(new global::System.CodeDom.CodePropertyReferenceExpression(new global::System.CodeDom.CodeThisReferenceExpression(), "Store"), "TransactionManager"), "BeginTransaction", new global::System.CodeDom.CodePrimitiveExpression("Load"), new global::System.CodeDom.CodePrimitiveExpression(true))));
					txTryStatements.Add(loadAssign);
					global::System.CodeDom.CodeConditionStatement serializationResultCheck = new global::System.CodeDom.CodeConditionStatement(
						new global::System.CodeDom.CodePropertyReferenceExpression(new global::System.CodeDom.CodeVariableReferenceExpression("serializationResult"), "Failed"),
						new global::System.CodeDom.CodeThrowExceptionStatement(new global::System.CodeDom.CodeObjectCreateExpression(new global::System.CodeDom.CodeTypeReference(typeof(DslModeling::SerializationException)), new global::System.CodeDom.CodeVariableReferenceExpression("serializationResult")))
					);
					txTryStatements.Add(serializationResultCheck);
					txTryStatements.Add(new global::System.CodeDom.CodeExpressionStatement(new global::System.CodeDom.CodeMethodInvokeExpression(new global::System.CodeDom.CodeVariableReferenceExpression(transactionName), "Commit")));
					global::System.CodeDom.CodeTryCatchFinallyStatement txTryStatement = new global::System.CodeDom.CodeTryCatchFinallyStatement(txTryStatements.ToArray(), new global::System.CodeDom.CodeCatchClause[] { }, new global::System.CodeDom.CodeStatement[] { finallyStatement });
	
	
					// We check if the user has requested validation to be performed. If so, we call
					// ValidateStore() on the base ModelingTextTransformation class.
					string validationCategories = requiresArguments[requiresValidationParameter];
					global::System.CodeDom.CodeMethodInvokeExpression validationInvoke = null;
					if (!string.IsNullOrEmpty(validationCategories))
					{
						validationInvoke = new global::System.CodeDom.CodeMethodInvokeExpression(new global::System.CodeDom.CodeThisReferenceExpression(), "ValidateStore", new global::System.CodeDom.CodePrimitiveExpression(validationCategories), new global::System.CodeDom.CodePropertyReferenceExpression(new global::System.CodeDom.CodeThisReferenceExpression(), "Errors"));
					}
	
					global::System.CodeDom.Compiler.CodeGeneratorOptions options = new global::System.CodeDom.Compiler.CodeGeneratorOptions();
					options.BlankLinesBetweenMembers = true;
					options.IndentString = "    ";
					options.VerbatimOrder = true;
					options.BracingStyle = "C";
					using (global::System.IO.StringWriter writer = new global::System.IO.StringWriter(codeBuffer, global::System.Globalization.CultureInfo.InvariantCulture))
					{
						if(invokeEnableDiagramRules != null)
						{
							languageProvider.GenerateCodeFromStatement(new global::System.CodeDom.CodeExpressionStatement(invokeEnableDiagramRules), writer, options);
						}
						
						if(diagramFileDeclaration != null)
						{
							languageProvider.GenerateCodeFromStatement(diagramFileDeclaration, writer, options);
							languageProvider.GenerateCodeFromStatement(diagramFileAssign, writer, options);
						}
						
						languageProvider.GenerateCodeFromStatement(transactionDeclaration, writer, options);
						languageProvider.GenerateCodeFromStatement(txTryStatement, writer, options);
						
						if (validationInvoke != null)
						{
							languageProvider.GenerateCodeFromStatement(new global::System.CodeDom.CodeExpressionStatement(validationInvoke), writer, options);
						}
					}
				}
			}
		}
开发者ID:Exclr8,项目名称:CloudCore,代码行数:93,代码来源:DirectiveProcessor.cs

示例2: GeneratePreInitializationCode

		/// <summary>
		/// Contribute additively to initialization code for the TextTransformation generated class.
		/// </summary>
		/// <remarks>
		/// This code will be added before the call to the base class.
		/// </remarks>
		/// <param name="directiveName"></param>
		/// <param name="codeBuffer"></param>
		/// <param name="languageProvider"></param>
		/// <param name="requiresArguments"></param>
		/// <param name="providesArguments"></param>
		protected override void GeneratePreInitializationCode(string directiveName, global::System.Text.StringBuilder codeBuffer, global::System.CodeDom.Compiler.CodeDomProvider languageProvider, global::System.Collections.Generic.IDictionary<string, string> requiresArguments, global::System.Collections.Generic.IDictionary<string, string> providesArguments)
		{
			if ((global::System.StringComparer.OrdinalIgnoreCase.Compare(directiveName, supportedDirectiveName) == 0))
			{
				if (languageProvider != null)
				{
					string[] domainModels = {
						"Architect.ScheduledTasks.ScheduledTasksDomainModel",
					};
	
					global::System.CodeDom.Compiler.CodeGeneratorOptions options = new global::System.CodeDom.Compiler.CodeGeneratorOptions();
					options.BlankLinesBetweenMembers = true;
					options.IndentString = "    ";
					options.VerbatimOrder = true;
					options.BracingStyle = "C";
					using (global::System.IO.StringWriter writer = new global::System.IO.StringWriter(codeBuffer, global::System.Globalization.CultureInfo.InvariantCulture))
					{
						foreach (string domainModel in domainModels)
						{
							global::System.CodeDom.CodeExpressionStatement addModel = new global::System.CodeDom.CodeExpressionStatement(new global::System.CodeDom.CodeMethodInvokeExpression(new global::System.CodeDom.CodeMethodReferenceExpression(new global::System.CodeDom.CodeThisReferenceExpression(), "AddDomainModel"), new global::System.CodeDom.CodeTypeOfExpression(domainModel)));
							languageProvider.GenerateCodeFromStatement(addModel, writer, options);
						}
					}
				}
			}
		}
开发者ID:Exclr8,项目名称:CloudCore,代码行数:37,代码来源:DirectiveProcessor.cs


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