[英]How to create generic property in model class using asp.net core
public class A
{
public int Val {get; set;}
public int B {get; set;}
public T C{get; set;} // make generic property
}
How can I create generic property in model class using asp.net core.如何使用 asp.net 内核在 model class 中创建通用属性。 In above code I want to make
在上面的代码中我想做
"C" property as a generic property and convert that property into particular class.
“C”属性作为通用属性并将该属性转换为特定的 class。
In "C" will be dynamic property.在“C”中将是动态属性。
Example例子
public Class D
{
public int Value1 {get; set;}
}
public Class E
{
public int Value2 {get; set;}
}
The "C" property have either D or E “C”属性具有 D 或 E
public class A<T>
{
public int A {get; set;}
public int B {get; set;}
public T C {get; set;}
}
And use it like this:并像这样使用它:
var a = new A<D>()
OR或者
var a = new A<E>()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.