本文整理汇总了C#中Microsoft.CSharp.CSharpCodeProvider.CreateEscapedIdentifier方法的典型用法代码示例。如果您正苦于以下问题:C# Microsoft.CSharp.CSharpCodeProvider.CreateEscapedIdentifier方法的具体用法?C# Microsoft.CSharp.CSharpCodeProvider.CreateEscapedIdentifier怎么用?C# Microsoft.CSharp.CSharpCodeProvider.CreateEscapedIdentifier使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CSharp.CSharpCodeProvider
的用法示例。
在下文中一共展示了Microsoft.CSharp.CSharpCodeProvider.CreateEscapedIdentifier方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateCode
public void GenerateCode(CodeDomGenerator.Language language)
{
switch (language)
{
case CodeDomGenerator.Language.CSharp:
using (Microsoft.CSharp.CSharpCodeProvider provider = new Microsoft.CSharp.CSharpCodeProvider())
{
System.CodeDom.Compiler.CodeGeneratorOptions opts = new System.CodeDom.Compiler.CodeGeneratorOptions();
using (System.CodeDom.Compiler.IndentedTextWriter tw = new System.CodeDom.Compiler.IndentedTextWriter(new StringWriter(), opts.IndentString))
{
tw.Write("var {0} = ", provider.CreateEscapedIdentifier(VariableName));
provider.GenerateCodeFromExpression(InitExpression, tw, opts);
tw.Write(";");
Value = tw.InnerWriter.ToString();
}
}
break;
case CodeDomGenerator.Language.VB:
using (Microsoft.VisualBasic.VBCodeProvider provider = new Microsoft.VisualBasic.VBCodeProvider())
{
System.CodeDom.Compiler.CodeGeneratorOptions opts = new System.CodeDom.Compiler.CodeGeneratorOptions();
using (System.CodeDom.Compiler.IndentedTextWriter tw = new System.CodeDom.Compiler.IndentedTextWriter(new StringWriter(), opts.IndentString))
{
tw.Write("Dim {0} = ", provider.CreateEscapedIdentifier(VariableName));
provider.GenerateCodeFromExpression(InitExpression, tw, opts);
Value = tw.InnerWriter.ToString();
}
}
break;
default:
throw new NotImplementedException(language.ToString());
}
}