我想创建运行时类,但是当使用 Stimulsoft.Report.Dictionary 的属性 [StiAlias("id")] 时;发送错误:
[0] = (1,101):错误 CS0012:类型“属性”是在未引用的程序集中定义的。您必须添加对程序集“netstandard,Version=2.1.0.0,Culture=neutral,PublicKeyToken=cc7b13ffcd2ddd51”的引用。
public object CreateClassRunTime()
{
string strClass =
@"using System; " +
//"using System.Collections.Generic;" +
"using Stimulsoft.Report.Dictionary;" +
"namespace VModel { public class AddressViewTest { " +
"[StiAlias(\"id\")]" +
"public int id { get; set; }" +
" public int? updUser { get; set; } } }";
SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(strClass);
string assemblyName = Path.GetRandomFileName();
var refPaths = new[] {
typeof(object).Assembly.Location,
typeof(System.ComponentModel.DataAnnotations.DisplayAttribute).Assembly.Location,
typeof(System.Runtime.AssemblyTargetedPatchBandAttribute).Assembly.Location,
typeof(Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo).Assembly.Location,
typeof(Stimulsoft.Report.Dictionary.StiAliasAttribute).GetTypeInfo().Assembly.Location,
};
MetadataReference[] references = refPaths.Select(r => MetadataReference.CreateFromFile(r)).ToArray(); …Run Code Online (Sandbox Code Playgroud)