Why declare DependencyProperty members public not protected?

半腔热情 提交于 2019-12-01 07:48:08

According to MSDN, restrictive access modifiers don't actually provide the intended access protection from certain APIs, so there's no point declaring dependency properties and their identifier fields anything other than public:

Dependency Property Security Considerations

Dependency properties should be declared as public properties. Dependency property identifier fields should be declared as public static fields. Even if you attempt to declare other access levels (such as protected), a dependency property can always be accessed through the identifier in combination with the property system APIs. Even a protected identifier field is potentially accessible because of metadata reporting or value determination APIs that are part of the property system, such as LocalValueEnumerator. For more information, see Dependency Property Security.

It doesn't do any harm exposing them as public anyway, I'd gather.

Dependency properties should generally be considered to be public properties, accessible or at least discoverable by any caller that has access to an instance.

I think the section "Dependency Property Security Considerations " in below link can help you understand why dependency properties are implemented/registered in this way and more on this:

http://msdn.microsoft.com/en-us/library/ms753358.aspx

Thanks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!