简体   繁体   English

如何将 C# 类作为字符串 UserInput,并使其可用于 ASP.NET Core 运行时?

[英]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.

相关问题 如何在 asp.net 核心 1.0 c# 中将字符串(实际上是位图)转换为 IFormFile - How can I convert String (which is actually Bitmap) to IFormFile in asp.net core 1.0 c# 我可以在asp.net核心上运行C#游戏吗? - Can I run a C# game on asp.net core? 我如何获得C#asp.net在运行时中创建的所有控件的值 - how can i get value of all controls created in runtime in C# asp.net 如何加载网站,然后在 Asp.Net Core (C#) Razor Pages 中添加数据 - How can I load the website and then later add data to it in Asp.Net Core (C#) Razor Pages 如何将MongoDB驱动程序与C#ASP.NET核心API框架一起使用? - How can I use the MongoDB Driver with C# ASP.NET Core API framework? asp.net core C# 如何在存储库模式中传递值 - asp.net core C# how can I pass value in a repository pattern 如何在 asp.net 核心 mvc ZD7EFA19FBE7D39372FD5ADB60242 中将列表 object 转换为 Viewmodel object? - How can I convert List object to Viewmodel object in asp.net core mvc C#? 如何在 C# 中使用 ASP.NET Core 连接外部认证服务器 - How can I connect with an external authentication server with ASP.NET Core in C# 如何使用 Autofac 在 N 层 ASP.NET MVC Core 1.0 应用程序中使用连接字符串 - How to make the connection string available in a N-Tier ASP.NET MVC Core 1.0 App with Autofac 我在哪里可以找到关于如何制作简单内容管理系统的C#ASP.NET教程? - Where can I find a C# ASP.NET tutorial on how to make a simple content management system?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM