Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 作为对象的.NET类属性,如System.String_C#_.net - Fatal编程技术网

C# 作为对象的.NET类属性,如System.String

C# 作为对象的.NET类属性,如System.String,c#,.net,C#,.net,我不确定这是否可行,甚至不知道如何恰当地表达这个词 我正在创建一个新的webAPI,希望与脱机应用程序一起使用。该应用程序连接到api(脱机前),并下拉字段列表以生成动态表单。我想向客户端提供一个字段列表。简单来说,这可能是id和description 但是,要完全按照我的要求生成表单,我可能需要提供一个字段“type”,例如System.DateTime或System.String。有可能这样做吗 在伪代码中,这可能是: public class EntityType { public

我不确定这是否可行,甚至不知道如何恰当地表达这个词

我正在创建一个新的webAPI,希望与脱机应用程序一起使用。该应用程序连接到api(脱机前),并下拉字段列表以生成动态表单。我想向客户端提供一个字段列表。简单来说,这可能是
id
description

但是,要完全按照我的要求生成表单,我可能需要提供一个字段“type”,例如
System.DateTime
System.String
。有可能这样做吗

在伪代码中,这可能是:

public class EntityType
{
    public Guid EntityTypeId { get; set; }
    public string Description { get; set; }
    public Object Type { get; set; }
}
然后我可能想创建一个
EntityType
,如下所示:

EntityType entityType = new EntityType { 
    EntityTypeId = Guid.NewGuid(),
    Description = "Visit Date",
    Type = System.DateTime
};
这是我想要实现的
Type=System.DateTime
。然后,我可以让我的表单生成一个类型为date的字段。例如,这可能适用于字符串。

要表示类型,请使用
type

 public Type Type { get; set; }

然而!这不太可能与webapi一起工作,因为
类型
在平台之间不可互换


另一个选项是预期类型的
enum
;你可能会发现
TypeCode
拥有你想要的一切,但你也可以简单地创建你自己的
enum
已知类型。

非常好-正是我想要的。谢谢。如果webapi不能做到这一点,你能用这样的泛型“作弊”吗
public类EntityType{public Type{get{return typeof(T);}}}}
或者会有同样的问题吗?
Type = typeof(DateTime)