开发者

Reflection from DTO

开发者 https://www.devze.com 2023-02-06 23:50 出处:网络
I have 1 dto, statEMailDTO, which has a field that holds the Field Names of what I\'m looking for (they are comma delimited.

I have 1 dto, statEMailDTO, which has a field that holds the Field Names of what I'm looking for (they are comma delimited.

var emailParams = statEmailDTO.EmailParam.ToString().Split(',');

for (int i = 0; i < emailParams.Length; i++) {
  var fieldName = emailParams[i].ToString();

etc.

But, then how do I use Reflection to then get the Actual value of ``fieldName which is found in a different DTO, siDTO.

So let's say that fieldName = "SuggestionItemID", I then what to get the value of siDTO.SuggestionItemID.

I haven't done a lot of reflectio开发者_如何转开发n in the past. Sure, I read up on PropertyInfo, but it's just not clicking.

Thoughts?


Like this:

PropertyInfo property = typeof(SomeType).GetProperty(fieldName);
object value = property.GetValue(instance, null);
0

精彩评论

暂无评论...
验证码 换一张
取 消