c# - 如何获取子属性的 PropertyDescriptor
问题描述
我需要从字符串中获取对象的子属性的 PropertyDescriptor。为了之后根据该属性对集合进行排序。
我为该方法提供了一个类似“Subobject.Subproperty”的字符串,但 PropertyDescriptor 为空
PropertyDescriptor prop = TypeDescriptor.GetProperties(typeof(MyParentObject)).Find("MyChildObject.MySubProperty", true);
//....
items = items.OrderBy(y => prop.GetValue(y)).ToList();
最后我得到一个由 prop 为空引起的异常。
解决方案
推荐阅读
- android - 在 Unity Android 中将资产包与流资产文件夹一起使用
- xamarin - Xamarin - 此版本的 iOS 不支持此 API - UIKit.UIMenuElement
- python - 如何构建一个遍历dict的JSON对象?
- javascript - 使用 IF 控制结构在 JS 中进行验证的正确方法是什么
- c# - AZURE Blobs .ListBlobs() 扩展了限制
- angular - 如何让 NativeScript 的滑块使用步长值?
- spring - Spring 是否有类似 PHP 的开源包?
- java - 如何删除数组中重复的值?
- java - 如何忽略或处理输入流中的退格键
- amazon-cognito - 在后台线程上将 Cognito 身份验证状态更改发布到 environmentObject