[英].NET Class property as object, such as System.String
I'm not sure if this is possible, or even how to properly word this. 我不确定这是否可行,甚至不确定如何正确表达。
I am creating a new webAPI that I want to use with an offline app. 我正在创建要与脱机应用程序一起使用的新webAPI。 The app connects to the api (before going offline) and pulls down a list of fields to generate a dynamic form.
该应用程序连接到api(离线之前),并下拉字段列表以生成动态表单。 I want to supply a list of fields to the client.
我想向客户提供字段列表。 In simple terms this might be
id
and description
. 简单来说,这可能是
id
和description
。
However, to generate the form exactly as I want it, I might want to supply a field "type" such as System.DateTime
or System.String
. 但是,要完全按照我的要求生成表单,我可能要提供一个字段“类型”,例如
System.DateTime
或System.String
。 Is it possible to do this? 是否有可能做到这一点?
In pseudocode this might be: 用伪代码可能是:
public class EntityType
{
public Guid EntityTypeId { get; set; }
public string Description { get; set; }
public Object Type { get; set; }
}
I might then want to create an EntityType
like this: 然后,我可能想创建一个这样的
EntityType
:
EntityType entityType = new EntityType {
EntityTypeId = Guid.NewGuid(),
Description = "Visit Date",
Type = System.DateTime
};
It's the Type = System.DateTime
I want to be able to achieve. 这是我想能够实现的
Type = System.DateTime
。 I can then have my form generate a field where the type is date. 然后,我可以让我的表单生成一个类型为日期的字段。 The same might apply for strings for example.
例如,同样的情况可能适用于字符串。
To represent a type , use Type
: 要表示类型 ,请使用
Type
:
public Type Type { get; set; }
... ...
Type = typeof(DateTime)
However! 然而! It is unlikely that this will work with webapi, since
Type
is not interchangeable between platforms. 由于
Type
在平台之间不可互换,因此不太可能与webapi一起使用。
Another option is an enum
of your expected types; 另一个选择是您期望的类型的
enum
。 you might find that TypeCode
has everything you want, but you could also simply create your own enum
of known types. 您可能会发现
TypeCode
具有所需的一切,但您也可以简单地创建自己的已知类型的enum
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.