【发布时间】:2018-05-25 20:35:50
【问题描述】:
我有这个结构。
public class FirstClass
{
public List<Foo> FooList{ get; set; }
}
public class Foo{
//Ex:
//public string Name{ get; set; }
}
public List<Foo> GetFoo(){
//I'm use Firstclass like this here typeof(FirstClass);
//I want create here dynamic property for Foo class.
}
我的问题是,我想从“GetFoo()”函数为“Foo”类创建属性。同时,该函数返回“List”“Foo”类型。我正在研究"Dynamically Add C# Properties at Runtime"、"How to dynamically create a class in C#?",但这些链接中的答案没有被引用为返回值或被引用到另一个类。我该怎么做?
【问题讨论】:
-
如果您描述了为什么需要它,有人可能会建议一种更好的方法来解决问题,而不是在运行时添加属性。
-
@Evk 我认为没有必要再次考虑这个问题,谢谢。
标签: c# dynamic properties