Orchard conventions
果园会议
Definitions
定义
-
Camel case is a casing convention where the first letter is lower-case, words are not separated by any character but have their first letter capitalized. Example:
thisIsCamelCased
. -
[Camel case](http://en.wikipedia.org/wiki/CamelCase)是一种大写惯例,其中第一个字母是小写的,单词不是由任何字符分隔,而是首字母大写。示例:
thisIsCamelCased
。 * -
Pascal case is a casing convention where the first letter of each word is capitalized, and no separating character is included between words. Example:
ThisIsPascalCased
. -
[Pascal案例](http://c2.com/cgi/wiki?PascalCase)是一种套管约定,其中每个单词的首字母大写,并且单词之间不包括分隔字符。示例:
ThisIsPascalCased
。 *
Solution conventions
解决方案约定
-
For the extensions to be able to properly load when running the application by hitting
Ctrl+F5
in Visual Studio (without building the full solution), each extension's project needs to be a project dependency ofOrchard.Web
(right-click onOrchard.Web
-> Build Dependencies -> Project Dependencies); otherwise NuGet packages for the extension's project won't be restored. -
为了能够在运行应用程序时通过在Visual Studio中单击“Ctrl + F5”来正确加载扩展(无需构建完整的解决方案),每个扩展的项目需要是“Orchard.Web”的项目依赖项(右键单击)在
Orchard.Web
- > Build Dependencies - > Project Dependencies );否则将无法恢复扩展程序项目的NuGet包。
Please note that this is not the same as a project reference (but adding a project reference adds a project dependency too) and this information is stored in the solution file, not the project file.
请注意,这与项目引用不同(但添加项目引用也会添加项目依赖项),此信息存储在解决方案文件中,而不是项目文件中。
C# Coding Conventions
C#编码约定
We are using the C# coding conventions described in this document: C# Coding Guidelines with the following exceptions:
我们使用本文档中描述的C#编码约定:[C#编码指南](http://blogs.msdn.com/brada/articles/361363.aspx),但以下情况除外:
-
Orchard supports C# 5, so you cannot use C# 6 (or above) language features (even if you can build it in Visual Studio), since Dynamic Compilation currently uses the pre-Roslyn compiler.
-
Orchard支持C#5,因此您无法使用C#6(或更高版本)语言功能(即使您可以在Visual Studio中构建它),因为Dynamic Compilation目前使用的是前Roslyn编译器。 *
-
Opening braces are on the same line as the statement that begins the block, with a space before the brace (this is consistent with what we do in JavaScript), a.k.a. K&R convention.
-
打开括号与开始块的语句位于同一行,在大括号前有一个空格(这与我们在JavaScript中的做法一致),a.k.a。K&R约定。 *
If you have the Rebracer Visual Studio extension installed it will automatically configure the editor to use the conventional brace styling.
如果安装了[Rebracer Visual Studio扩展](https://visualstudiogallery.msdn.microsoft.com/410e9b9f-65f3-4495-b68e-15567e543c58),它将自动配置编辑器以使用传统的支撑样式。
-
Private fields are prefixed with an underscore and camel-cased.
-
私有字段以下划线和驼峰为前缀。 *
-
Using directives appear before the namespace, not inside it.
-
使用指令出现在命名空间之前,而不是在其中。 *
JavaScript Coding Conventions
JavaScript编码约定
-
Namespaces are Pascal-cased.
-
命名空间是Pascal-cased。 *
-
Class names are Pascal-cased.
-
类名是Pascal-cased。 *
-
Plugin names are Camel-cased.
-
插件名称是Camel-cased。 *
-
Properties, fields, local variables are Camel-cased.
-
属性,字段,局部变量是Camel-cased。 *
-
Parameters are Camel-cased.
-
参数是Camel-cased。 *
-
Function names are Camel-cased unless they really are class constructors or namespaces (in other words, global/local functions and methods are Camel-cased).
-
函数名称是Camel-cased,除非它们确实是类构造函数或命名空间(换句话说,全局/局部函数和方法是Camel-cased)。 *
-
Private/internal/protected members are underscore-prefixed and Camel-cased.
-
私人/内部/受保护成员以下划线为前缀,以驼峰为主。 *
-
Constants are just static fields (apply same rules as for fields).
-
常量只是静态字段(应用与字段相同的规则)。 *
-
JavaScript coding conventions follow C# conventions except for Pascal vs. Camel.
-
除了Pascal vs. Camel之外,JavaScript编码约定遵循C#约定。 *
-
"
and'
are interchangeable (strictly equivalent). -
和
是可以互换的(严格等同)。 *
XHTML attributes should be in double quotes and if code needs to be in there, it has to use single quotes:
XHTML属性应该是双引号,如果代码需要在那里,它必须使用单引号:
e.g.: <input type="button" onclick="alert('Foo');"/>
(note: this kind of DOM-0 event creating is itself discouraged and is only shown here as an example).
例如:<input type =“button”onclick =“alert('Foo');”/>
(注意:这种DOM-0事件创建本身不鼓励,这里仅作为示例显示)。
In pure JS code, use double quotes for string delimiters.
在纯JS代码中,对字符串分隔符使用双引号。
When the string is one character and the intent is a character, use single quote for consistency with managed code.
当字符串是一个字符且intent是字符时,使用单引号与托管代码保持一致。
-
There is no need for
String.Empty
, just use""
. -
不需要
String.Empty
,只需使用“”
。 * -
Localizable strings need to be isolated into resource dictionaries until we figure out our client localization story, e.g.
alert(Foo.badArgument); ... Foo = {badArgument: "The argument was bad."};
-
在我们弄清楚我们的客户端本地化故事之前,需要将可本地化的字符串隔离到资源字典中。
警报(Foo.badArgument); ...... Foo = {badArgument:“论证很糟糕。”};
* -
Don't worry about string concatenation unless you have specific evidence that regular concatenation is significantly harming performance in your specific scenario.
-
除非您有特定证据表明常规连接在特定情况下严重损害性能,否则不要担心字符串连接。 *
-
Use the K&R style for opening braces (put the opening brace on the opening line).
-
使用[K&R](http://en.wikipedia.org/wiki/Indent_style)样式打开括号(将左括号放在开始行上)。 *
This is because in JavaScript, the semicolon is optional, which can cause difficult to spot bugs (see http://msmvps.com/blogs/luisabreu/archive/2009/08/26/the-semicolon-bug.aspx for an example).
这是因为在JavaScript中,分号是可选的,这可能导致很难发现错误(参见[http://msmvps.com/blogs/luisabreu/archive/2009/08/26/the-semicolon-bug.aspx]( http://msmvps.com/blogs/luisabreu/archive/2009/08/26/the-semicolon-bug.aspx)示例)。