[英]How can I take a C# Class, as a string UserInput, and make it available to the ASP.NET Core runtime?
I have users who save data into a propertybag JSON store and want to have a customer-supplied C# Model file (like below), to be pasted in, and then some ( System.*
wizardry) and make that class available on either a per-usersession or global form.我有用户将数据保存到 propertybag JSON 存储中,并希望有一个客户提供的 C# 模型文件(如下所示),粘贴进去,然后粘贴一些( System.*
巫术)并使该类在每个-usersession 或全局表单。
It's OK if I need to restart ASP.NET, ILInject, or anything else.如果我需要重新启动 ASP.NET、ILInject 或其他任何东西,都可以。 My goal is to have this class work with hard-coded EntityFramework (if data layer), RazorPages (if display layer), Netwonsoft in memory, or other reasons.我的目标是让这个类与硬编码的 EntityFramework(如果是数据层)、RazorPages(如果是显示层)、内存中的 Netwonsoft 或其他原因一起工作。
How can I take a class like the one below, as a string, and add it dynamically to ASP.NET Core ?如何将如下所示的类作为字符串,并将其动态添加到 ASP.NET Core 中? RazorPages, etc, at runtime? RazorPages 等,在运行时?
public class Movie
{
public int ID { get; set; }
#region snippet11
[StringLength(60, MinimumLength = 3)]
[Required]
public string Title { get; set; }
#endregion
#region snippet2
[Display(Name = "Release Date")]
[DataType(DataType.Date)]
public DateTime ReleaseDate { get; set; }
[Range(1, 100)]
[DataType(DataType.Currency)]
[Column(TypeName = "decimal(18, 2)")]
public decimal Price { get; set; }
#endregion
[RegularExpression(@"^[A-Z]+[a-zA-Z]*$")]
[Required]
[StringLength(30)]
public string Genre { get; set; }
[RegularExpression(@"^[A-Z]+[a-zA-Z0-9""'\s-]*$")]
[StringLength(5)]
[Required]
public string Rating { get; set; }
}
First, possible you can't accomplish this without risking integrity has hell, as you are giving them an open way to get to your code.首先,您可能无法在不冒完整性的风险的情况下完成此任务,因为您为他们提供了获取代码的开放方式。 Second, as C# must be compiled, you'll have to push new versions every time your users adds or changes any of this classes (also applies to the necessary changes that the database to which your app is related to, due to the use of EntityFramework)其次,由于必须编译 C#,因此每次用户添加或更改此类中的任何一个时,您都必须推送新版本(也适用于与您的应用程序相关的数据库的必要更改,因为使用实体框架)
So, I'd advice you, that don't do something like that.所以,我建议你,不要做那样的事情。
If you want to have a custom properties, try to think a "Master" class handler, something like a big class with as many fields as you think they may get to need key, field1-field50, or what ever.如果您想拥有自定义属性,请尝试考虑“主”类处理程序,例如具有您认为可能需要 key、field1-field50 或其他任何字段的字段的大类。 And 2 other tables, like tableDescription that related with key wil l tell some more info about that pseudoTable, a name and a clientId that will use it (if you share tables), and in other table that relates pseudoTable with the bigtablehandler named columns with types, so "key, pseudoTable.key, fieldN, type, columnDisplayName)和其他 2 个表,例如与键相关的 tableDescription 将告诉有关该伪表的更多信息,名称和将使用它的 clientId(如果您共享表),以及在其他表中将伪表与 bigtablehandler 命名列相关联类型,所以“key,pseudoTable.key,fieldN,type,columnDisplayName)
:) :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.