C# CSharpCodeProvider没有看到堆栈<;T>;在System.Collections.Generic下初始化
我正在构建一个伪代码转换器和编译器。 它通过执行几个字符串操作将伪代码转换为代码,然后使用类编译伪代码,最后尝试运行伪代码 经过几次测试后,在翻译/输出代码如下的情况下:C# CSharpCodeProvider没有看到堆栈<;T>;在System.Collections.Generic下初始化,c#,.net,compiler-errors,pseudocode,csharpcodeprovider,C#,.net,Compiler Errors,Pseudocode,Csharpcodeprovider,我正在构建一个伪代码转换器和编译器。 它通过执行几个字符串操作将伪代码转换为代码,然后使用类编译伪代码,最后尝试运行伪代码 经过几次测试后,在翻译/输出代码如下的情况下: using System; using System.Collections.Generic; public class TranslatedProgram { public static void ReadLine(ref int destiny) { destiny = int.Parse
using System;
using System.Collections.Generic;
public class TranslatedProgram
{
public static void ReadLine(ref int destiny)
{
destiny = int.Parse(Console.ReadLine());
}
public static void InsertInStack(ref Stack<int> originalStack, int value)
{
Console.WriteLine("Inserting the value " + value + " to the stack.");
originalStack.Push(value);
foreach (int current in originalStack)
{
Console.WriteLine("|" + current);
}
Console.WriteLine("_______");
}
public static void Main()
{
int value = new int();
Stack<int> data = new Stack<int>();
ReadLine(ref value);
InsertInStack(ref data, value);
}
}
如何包含对System.dll的引用?请确保在编译时,有一个对包含
堆栈的dll的引用,即System.dll
您可以使用CompilerParameters
类的属性referencedAssemblys
添加引用:
CompilerParameters cp = new CompilerParameters();
cp.ReferencedAssemblies.Add("System.dll");
CSharpCodeProvider provider = new CSharpCodeProvider();
CompilerResults cr = provider.CompileAssemblyFromFile(cp, "MyFile.cs");
确保在编译时,有一个对保存堆栈的dll的引用,即System.dll
您可以使用CompilerParameters
类的属性referencedAssemblys
添加引用:
CompilerParameters cp = new CompilerParameters();
cp.ReferencedAssemblies.Add("System.dll");
CSharpCodeProvider provider = new CSharpCodeProvider();
CompilerResults cr = provider.CompileAssemblyFromFile(cp, "MyFile.cs");
使用CSharpCodeProvider编译时,是否将System.dll
作为程序集引用?使用CSharpCodeProvider编译时,是否将System.dll
作为程序集引用?我可以使用哪个属性向编译器提供该信息?这是我第一次使用这个类,我找不到任何属性或参数来执行此操作。我在答案中添加了更多信息。我可以使用哪个属性向编译器提供这些信息?这是我第一次使用这个类,我找不到任何属性或参数来执行此操作,我在答案中添加了更多信息。