Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
198 views
in Technique[技术] by (71.8m points)

.net core - C# - Get the Model properties inside a List<Model> and SetValue with System.Reflection

I am doing a POC for a project that I am developing and at the moment I'm in kind of a hard spot. So, I am receiving a param T which normally is a Model and then I have to check its properties to see which type the props are and then populate them. To achieve this I am using System.Reflection which does the job wonderfully! So far so good, It's working fine.

The problem is when the property in the model is a List

This is the example model that I have:

public List<TestModel2> TestList1 { get; set; }

public string test1 { get; set; }

public string test2 { get; set; }

public string test3 { get; set; }

So, the strings are totally fine, I can receive the Model, see their type and populate their value, the real problem arises when I get TestList1 which I can't seem to get the TestModel2 props and types.

This is a library that I am developing for a project, that's why the param type for the model is T by the way, it's because you can pass different models in which I will populate.

How can I access the Model inside the List<TestModel2> and check its properties and types with System.Reflection?

Can you guys give me a hint?

question from:https://stackoverflow.com/questions/65873459/c-sharp-get-the-model-properties-inside-a-listmodel-and-setvalue-with-system

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...