如果有 n 个属性,那么是 .GetProperties O(n) 的 Big-O 还是在反射中涉及增加复杂性的过程?
假设有这个定义的类:
public class Reflector
{
public string name { get; set; }
public int number { get; set; }
public bool flag { get; set; }
public List<string> etc { get; set; }
}
然后进行此调用:
var reflect = new Reflector();
PropertyInfo[] properties = reflect.GetType().GetProperties();
的时间复杂度,即 Big-O,是.GetProperties()
多少?考虑到有 4 个属性,这只需要 4 次迭代还是比这更复杂?或者,进入列表是否具有一些标准复杂性的 O(1) - 似乎它仍然必须是 O(n) 才能构建属性数组?