Using GetProperties() with BindingFlags.DeclaredOnly in .NET Reflection

后端 未结 5 1811
天涯浪人
天涯浪人 2020-12-01 07:02

If I use

sometype.GetProperties();

I get all of the properties from the type and it\'s parent. However I only want to retrieve the proper

5条回答
  •  庸人自扰
    2020-12-01 07:35

    I had problems using typeof(Thing), eventually this worked for me:

            var thisThing = (new Thing()).GetType();
            foreach (var property in thisThing.GetProperties())
            {
                // ...
            }
    

提交回复
热议问题