在系统命名空间中放置自定义code [英] Placing custom code in a System namespace

查看:133
本文介绍了在系统命名空间中放置自定义code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有不应该放在系统命名空间的任何最佳实践,说明自code?如果系统及其子留给微软code?

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 Microsoft code?

我问,因为我正在写一个类库,将在多个项目中使用,我想保持一致性,将其置于 System.InteropServices (因为它涉及的P / Invoke)。

I ask because I'm writing a class library that will be used across many projects and I'd like to keep things consistent by placing it in System.InteropServices (since it deals with P/Invoke).

推荐答案

这不是因为它违背了命名空间的主要优点之一是个好主意:preventing名称冲突。如果该框架的新版本中引入该命名空间中同名的类型?

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?

这是特别糟糕的系统,因为它们都是进口的许多其他作品的code与命名空间使用指令和这些命名空间中引入自定义类型污染的突发标识符其他源文件的命名范围。

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.

要分类,自定义互操作相关的类型,你可以这样建立一个新的命名空间 MyProduct.InteropServices

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

这篇关于在系统命名空间中放置自定义code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆