本文整理汇总了C#中Code.To方法的典型用法代码示例。如果您正苦于以下问题:C# Code.To方法的具体用法?C# Code.To怎么用?C# Code.To使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Code
的用法示例。
在下文中一共展示了Code.To方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Parse
public void Parse(IList<string> raw)
{
//Console.Clear();
program = new BaseInt.Class();
program.name = "unnamed"+RandomString(5);
ParseMethods(raw);
foreach (var method in program.methods)
{
try{
ParseRawLoc(method);
}
catch(Exception ex)
{
Code c = new Code(typeof(comment));
c.To<comment>().commentedtext = "Parsing error: " + ex.Message + Environment.NewLine+ex.Source+Environment.NewLine+ex.StackTrace+Environment.NewLine+ex.InnerException;
c.To<comment>().multiline = true;
method.code.Add(c);
}
}
}
示例2: ConvertCode
public string ConvertCode(Code code)
{
Type t = code.code.GetType();
if (t == typeof(callmethod))
{
return code.To<callmethod>().methodname + "();";
}
if (t == typeof(Output))
{
if (code.To<Output>().outstring.ToString().EndsWith(Environment.NewLine))
{
return @"Console.WriteLine(""" + code.To<Output>().outstring.ToString().Replace(Environment.NewLine, "") + @""");";
}
else
{
return @"Console.Write(""" + code.To<Output>().outstring.ToString() + @""");";
}
}
if (t == typeof(comment))
{
if (code.To<comment>().multiline)
{
return @"/*" + code.To<comment>().commentedtext + @"*/";
}
else
{
return @"//" + code.To<comment>().commentedtext;
}
}
if (t == typeof(DeclareVariable))
{
string ret = "";
DeclareVariable d = code.To<DeclareVariable>();
if (d.variable.isdeclared)
{
ret += d.variable.type.Name + " ";
}
ret += d.variable.name;
if (!d.setvariabledata)
{
ret += ";";
}
else
{
ret += @" = """ + d.variable.data + @""";";
}
return ret;
}
if (t == typeof(Input))
{
if (code.To<Input>().storevar)
{
if (
code.To<Input>().var.isdeclared
)
{
return code.To<Input>().var.name + " = Console.ReadLine();";
}
else
{
return "//TODO!";
}
}
else
{
return "Console.ReadLine();";
}
}
if (t == typeof(pause))
{
string ret = "";
ret += @"Console.WriteLine(""Press any key to continue..."");";
ret+=Environment.NewLine+"\t\t\tConsole.ReadKey();";
return ret;
}
return "//code convert error here, whilst trying to parse code of type: "+t.Name;
}
示例3: ParseRawLoc
public void ParseRawLoc(Method m)
{
int no = 0;
while (no != m.rawcode.Count)
{
if (m.rawcode[no].ToLower().StartsWith("goto"))
{
Code c= new Code(typeof(callmethod));
c.To<callmethod>().methodname = m.rawcode[no].Replace("goto ", "");
m.code.Add(c);
}
if (m.rawcode[no].ToLower().StartsWith("pause"))
{
m.code.Add(new Code(typeof(pause)));
}
if (m.rawcode[no].ToLower().StartsWith("echo "))
{
Code c = new Code(typeof(Output));
c.To<Output>().outstring = m.rawcode[no].Replace("echo ", "") + Environment.NewLine;
if (m.rawcode[no].ToLower().StartsWith("echo."))
{
c.To<Output>().outstring = Environment.NewLine;
}
m.code.Add(c);
}
if (m.rawcode[no].ToLower().StartsWith("set"))
{
#region set
Var v = new Var();
v.isdeclared = true;
//0 1
///p var=
#region getvarname
foreach (var item in m.rawcode[no].Split(' '))
{
if (item.Contains("="))
{
v.name = item.Substring(0,item.IndexOf('='));
}
}
#endregion
// 0 1 2
//set /p var=
#region getvartype
try
{
if (m.rawcode[no].Split(' ')[1].Contains("/a"))
{
v.type = typeof(int);
}
else
{
v.type = typeof(string);
}
}
catch { v.type = typeof(string); }
v.isvardataset = false;
#endregion
#region declare var
Code c = new Code(typeof(DeclareVariable));
#region set
if (!string.IsNullOrEmpty(m.rawcode[no].Split('=')[1]))
{
v.data = m.rawcode[no].Split('=')[1].Replace("=", "");
c.To<DeclareVariable>().setvariabledata = true;
}
#endregion
// c.To<DeclareVariable>().setvariabledata = false;
c.To<DeclareVariable>().variable = v;
m.code.Add(c);// string s;
#endregion
//----------------------------------------------------------
#region mathematical var definition mk1
//v super fancy comment switch
//*
if (m.rawcode[no].Split(' ')[1].Contains("/a"))
{
Code cc = new Code(typeof(MathDeclareVariable));
List<string> vars = new List<string>();
#region parse all vars involved
foreach (var item in m.rawcode[no].Split(' ')[2].Substring(
m.rawcode[no].Split(' ')[2].IndexOf('=') + 0, m.rawcode[no].Split(' ')[2].Length))
{
#region parsing stuff
if (item == '%')
{
string varname = "";
vars.Add(varname);
}
else if (new char[]{'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p'
,'q','r','s','t','u','v','w','x','y','z'}.Contains(item.ToString().ToLower()[0]))
{
vars[vars.Count] += item;
}
if (item == '+')
{
cc.To<MathDeclareVariable>().mathematicaloperators.Add(Operator.add);
}
//.........这里部分代码省略.........