本文整理汇总了C#中NetLanguage类的典型用法代码示例。如果您正苦于以下问题:C# NetLanguage类的具体用法?C# NetLanguage怎么用?C# NetLanguage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NetLanguage类属于命名空间,在下文中一共展示了NetLanguage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WizardOutput
//private NetVisibility mClassVisibility = NetVisibility.Public;
//public NetVisibility ClassVisibility
//{
// get { return mClassVisibility; }
// set { mClassVisibility = value; }
//}
public string WizardOutput(NetLanguage lang)
{
if (mClassBuilder == null)
return string.Empty;
return mClassBuilder.GetClassSourceCode(lang);
}
示例2: GetVisibility
public static string GetVisibility(NetLanguage leng, NetVisibility visi)
{
switch (leng) {
case NetLanguage.VbNet:
switch (visi) {
case NetVisibility.Private:
return "Private";
case NetVisibility.Protected:
return "Protected";
case NetVisibility.Public:
return "Public";
case NetVisibility.Internal:
return "Friend";
}
break;
case NetLanguage.CSharp:
switch (visi) {
case NetVisibility.Private:
return "private";
case NetVisibility.Protected:
return "protected";
case NetVisibility.Public:
return "public";
case NetVisibility.Internal:
return "internal";
}
break;
default:
break;
}
return "";
}
示例3: GetConverterCode
/// <summary>
/// Create the converter in source code
/// </summary>
/// <param name="lang">C# or Visual Basic</param>
/// <returns>Converter attribute in appropriate language</returns>
internal string GetConverterCode(NetLanguage lang)
{
var sb = new StringBuilder();
if (mKind != ConverterKind.None)
sb.Append("FieldConverter(ConverterKind." + mKind.ToString());
else if (mTypeName != string.Empty)
{
if (lang == NetLanguage.CSharp)
sb.Append("FieldConverter(typeof(" + mTypeName + ")");
else if (lang == NetLanguage.VbNet)
sb.Append("FieldConverter(GetType(" + mTypeName + ")");
}
else
return string.Empty;
if (!string.IsNullOrEmpty(mArg1))
{
sb.Append(", \"" + mArg1 + "\"");
if (!string.IsNullOrEmpty(mArg2))
{
sb.Append(", \"" + mArg2 + "\"");
if (!string.IsNullOrEmpty(mArg3))
{
sb.Append(", \"" + mArg3 + "\"");
}
}
}
sb.Append(")");
return sb.ToString();
}
示例4: ClassFromString
/// <summary>Compiles the source code passed and returns the Type with the name className.</summary>
/// <param name="classStr">The Source Code of the class in the specified language</param>
/// <param name="className">The Name of the Type that must be returned</param>
/// <returns>The Type generated by runtime compilation of the class source.</returns>
/// <param name="lang">One of the .NET Languages</param>
public static Type ClassFromString(string classStr, string className, NetLanguage lang)
{
var cp = new CompilerParameters();
cp.ReferencedAssemblies.Add("system.dll");
cp.ReferencedAssemblies.Add("system.data.dll");
cp.ReferencedAssemblies.Add(typeof (ClassBuilder).Assembly.GetModules()[0].FullyQualifiedName);
cp.GenerateExecutable = false;
cp.GenerateInMemory = true;
cp.IncludeDebugInformation = false;
var code = new StringBuilder();
switch (lang)
{
case NetLanguage.CSharp:
code.Append("using System; using Transformalize.Libs.FileHelpers.Attributes; using Transformalize.Libs.FileHelpers.Enums; using System.Data; ");
break;
case NetLanguage.VbNet:
code.Append("Imports System \n");
code.Append("Imports FileHelpers \n");
code.Append("Imports System.Data \n");
break;
}
code.Append(classStr);
var comp = new CSharpCodeProvider();
var cr = comp.CompileAssemblyFromSource(cp, code.ToString());
if (cr.Errors.HasErrors)
{
var error = new StringBuilder();
error.Append("Error Compiling Expression: " + StringHelper.NewLine);
foreach (CompilerError err in cr.Errors)
{
error.AppendFormat("Line {0}: {1}\n", err.Line, err.ErrorText);
}
throw new RunTimeCompilationException(error.ToString(), classStr, cr.Errors);
}
// Assembly.Load(cr.CompiledAssembly.);
if (className != string.Empty)
return cr.CompiledAssembly.GetType(className, true, true);
else
{
var ts = cr.CompiledAssembly.GetTypes();
if (ts.Length > 0)
foreach (var t in ts)
{
if (t.FullName.StartsWith("My.My") == false)
return t;
}
throw new BadUsageException("The Compiled assembly don´t have any Type inside.");
}
}
示例5: frmDataPreview
public frmDataPreview(string data, NetLanguage language)
{
InitializeComponent();
ShowCode(data, language);
//sdClassOut.Text = data;
cboClassLanguage.Items.Clear();
cboClassLanguage.Items.AddRange(NetLanguageList.Languages.ToArray());
NetLanguageList.LanguageType selected = NetLanguageList.Languages.Find(x => x.Language == language);
cboClassLanguage.SelectedItem = selected;
}
示例6: frmDataPreview
public frmDataPreview(string data, NetLanguage language)
{
InitializeComponent();
ShowCode(data, language);
//sdClassOut.Text = data;
cboClassLanguage.Items.Clear();
cboClassLanguage.Items.Add(NetLanguage.CSharp);
cboClassLanguage.Items.Add(NetLanguage.VbNet);
cboClassLanguage.SelectedItem = language;
}
示例7: AddAttributesCode
/// <summary>
/// Add attributes to the field at the appropriate spot in the code
/// </summary>
/// <param name="attbs">Add attributes to this</param>
/// <param name="lang">Language to use, C# of Visual Basic</param>
internal override void AddAttributesCode(AttributesBuilder attbs, NetLanguage lang)
{
if (mFieldLength <= 0)
throw new BadUsageException("The Length of each field must be grater than 0");
else
attbs.AddAttribute("FieldFixedLength("+ mFieldLength.ToString() +")");
if (mAlignMode != AlignMode.Left)
{
if (lang == NetLanguage.CSharp)
attbs.AddAttribute("FieldAlign(AlignMode."+ mAlignMode.ToString()+", '"+ mAlignChar.ToString() +"')");
else if (lang == NetLanguage.VbNet)
attbs.AddAttribute("FieldAlign(AlignMode."+ mAlignMode.ToString()+", \""+ mAlignChar.ToString() +"\"c)");
}
}
示例8: WizardOutput
//private NetVisibility mClassVisibility = NetVisibility.Public;
//public NetVisibility ClassVisibility
//{
// get { return mClassVisibility; }
// set { mClassVisibility = value; }
//}
public string WizardOutput(NetLanguage lang)
{
if (mClassBuilder == null)
return string.Empty;
try
{
return mClassBuilder.GetClassSourceCode(lang);
}
catch (Exception ex)
{
//MessageBox.Show(ex.Message, "Error generating class code", MessageBoxButtons.OK, MessageBoxIcon.Error);
return ex.Message;
}
}
示例9: ShowCode
private void ShowCode(string code, NetLanguage language)
{
mLastCode = code;
browserCode.DocumentText = "";
var colorizer = new CodeColorizer();
switch (language) {
case NetLanguage.CSharp:
browserCode.DocumentText = GetDefaultCss() + colorizer.Colorize(code, Languages.CSharp);
break;
case NetLanguage.VbNet:
browserCode.DocumentText = GetDefaultCss() + colorizer.Colorize(code, Languages.VbDotNet);
break;
default:
throw new ArgumentOutOfRangeException("language");
}
}
示例10: AddAttributesCode
internal override void AddAttributesCode(AttributesBuilder attbs, NetLanguage leng)
{
if (mFieldQuoted)
{
if (leng == NetLanguage.CSharp)
{
var quoteStr = mQuoteChar.ToString();
if (mQuoteChar == '\'') quoteStr = @"\'";
attbs.AddAttribute("FieldQuoted('" + quoteStr + "', QuoteMode." + mQuoteMode.ToString() + ", MultilineMode." + mQuoteMultiline.ToString() + ")");
}
else if (leng == NetLanguage.VbNet)
{
var quoteStr = mQuoteChar.ToString();
if (mQuoteChar == '"') quoteStr = "\"\"";
attbs.AddAttribute("FieldQuoted(\"" + quoteStr + "\"c, QuoteMode." + mQuoteMode.ToString() + ", MultilineMode." + mQuoteMultiline.ToString() + ")");
}
}
}
示例11: GetDelimiter
private static string GetDelimiter(string delimiter, NetLanguage lang)
{
switch (lang)
{
case NetLanguage.CSharp:
if (delimiter == "\t")
return "\"\\t\"";
else
return "\"" + delimiter + "\"";
case NetLanguage.VbNet:
if (delimiter == "\t")
return "VbTab";
else
return "\"" + delimiter + "\"";
default:
throw new ArgumentOutOfRangeException("lang");
}
}
示例12: AddAttributesCode
/// <summary>
/// Add any attributes to source (currently only the delimiter attribute)
/// </summary>
/// <param name="attbs">Attributes storage area to add to class</param>
/// <param name="lang"></param>
internal override void AddAttributesCode(AttributesBuilder attbs, NetLanguage lang)
{
if (mDelimiter == string.Empty)
throw new BadUsageException("The Delimiter of the DelimiterClassBuilder can't be null or empty.");
else
attbs.AddAttribute("DelimitedRecord("+ GetDelimiter(mDelimiter, lang) +")");
}
示例13: ClassFromSourceFile
/// <summary>
/// Create a class from a source file.
/// </summary>
/// <param name="filename">The filename with the source of the class.</param>
/// <param name="lang">The language used to compile the class.</param>
/// <returns>The compiled class.</returns>
public static Type ClassFromSourceFile(string filename, NetLanguage lang)
{
return ClassFromSourceFile(filename, string.Empty, lang);
}
示例14: AddAttributesCode
internal override void AddAttributesCode(AttributesBuilder attbs, NetLanguage leng)
{
attbs.AddAttribute("FixedLengthRecord(FixedMode." + mFixedMode.ToString() + ")");
}
示例15: GetClassSourceCode
/// <summary>
/// Returns the source code for the current class in the specified language.
/// </summary>
/// <param name="lang">The language for the return code.</param>
/// <returns>The Source Code for the class that are currently building.</returns>
public string GetClassSourceCode(NetLanguage lang)
{
ValidateClass();
StringBuilder sb = new StringBuilder(100);
BeginNamespace(lang, sb);
AttributesBuilder attbs = new AttributesBuilder(lang);
AddAttributesInternal(attbs);
AddAttributesCode(attbs, lang);
sb.Append(attbs.GetAttributesCode());
switch (lang)
{
case NetLanguage.VbNet:
sb.Append(GetVisibility(lang, mVisibility) + GetSealed(lang) + "Class " + mClassName);
sb.Append(StringHelper.NewLine);
break;
case NetLanguage.CSharp:
sb.Append(GetVisibility(lang, mVisibility) + GetSealed(lang) + "class " + mClassName);
sb.Append(StringHelper.NewLine);
sb.Append("{");
break;
}
sb.Append(StringHelper.NewLine);
sb.Append(StringHelper.NewLine);
foreach (FieldBuilder field in mFields)
{
sb.Append(field.GetFieldCode(lang));
sb.Append(StringHelper.NewLine);
}
sb.Append(StringHelper.NewLine);
switch (lang)
{
case NetLanguage.VbNet:
sb.Append("End Class");
break;
case NetLanguage.CSharp:
sb.Append("}");
break;
}
EndNamespace(lang, sb);
return sb.ToString();
}