Placing custom code in a System namespace

前端 未结 3 1987
南笙
南笙 2020-12-20 16:45

Are there any best-practices that state custom code shouldn\'t be placed in a System namespace? Should System and its children be reserved for Micr

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-20 17:37

    It's not a good idea because it defeats one of the primary benefits of namespaces: preventing name clashes. What if a newer version of the framework introduced an identically named type in that namespace?

    This is particularly bad for System namespaces since they are imported in many other pieces of code with using directives and introducing custom types in those namespaces pollutes the naming scope of other source files with unexpected identifiers.

    To categorize your custom interop related types, you can create a new namespace like MyProduct.InteropServices.

提交回复
热议问题