Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一组属性,其中一些具有privatesetter,其中一些具有internalsetter。有什么方法可以在运行时检查属性的设置器是否internal存在?
private
internal
您可以使用反射获取此信息:
var myType = obj.GetType(); var setMethod = myType.GetProperty(propertyName, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public) .GetSetMethod(true); bool isInternalSetter = setMethod != null && setMethod.IsAssembly;