Skip to content

Commit 00cf2ce

Browse files
added color to the code with c# syntax
1 parent 2b09852 commit 00cf2ce

File tree

1 file changed

+38
-37
lines changed

1 file changed

+38
-37
lines changed

CodingGuidelines.md

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This document outlines the recommended coding guidelines for the Mixed Reality T
88

99
All scripts posted to the MRTK should have the standard License header attached, exactly as shown below:
1010

11-
```
11+
```c#
1212
// Copyright (c) Microsoft Corporation. All rights reserved.
1313
// Licensed under the MIT License. See LICENSE in the project root for license information.
1414
```
@@ -19,7 +19,7 @@ Any script files submitted without the license header will be rejected
1919

2020
All public classes, structs, enums, functions, properties, fields posted to the MRTK should be described as to it's purpose and use, exactly as shown below:
2121

22-
```
22+
```c#
2323
/// <summary>
2424
/// The Controller definition defines the Controller as defined by the SDK / Unity.
2525
/// </summary>
@@ -43,7 +43,8 @@ The vNext structure adheres to a strict namespace culture of mapping the namespa
4343
![](/External/ReadMeImages/MRTK-NameSpaceExample.png)
4444

4545
### Do:
46-
```
46+
47+
```c#
4748
// Copyright (c) Microsoft Corporation. All rights reserved.
4849
// Licensed under the MIT License. See LICENSE in the project root for license information.
4950
@@ -68,7 +69,7 @@ Additionally, ensure that spaces are added for conditional / loop functions like
6869

6970
### Don't:
7071

71-
```
72+
```c#
7273
private Foo () // < - space between Foo and ()
7374
{
7475
if(Bar==null) // <- no space between if and ()
@@ -85,7 +86,7 @@ private Foo () // < - space between Foo and ()
8586

8687
### Do:
8788

88-
```
89+
```c#
8990
private Foo()
9091
{
9192
if (Bar==null)
@@ -106,7 +107,7 @@ Please be sure not to add additional spaces between square brackets and parenthe
106107

107108
### Don't:
108109

109-
```
110+
```c#
110111
private Foo()
111112
{
112113
int[ ] var = new int [ 9 ];
@@ -117,7 +118,7 @@ private Foo()
117118

118119
### Do:
119120

120-
```
121+
```c#
121122
private Foo()
122123
{
123124
int[] var = new int[9];
@@ -132,14 +133,14 @@ Always use `PascalCase` for public / protected / virtual properties, and `camelC
132133
133134
### Don't:
134135

135-
```
136+
```c#
136137
public string myProperty; // <- Starts with a lower case letter
137138
private string MyProperty; // <- Starts with an uppercase case letter
138139
```
139140

140141
### Do:
141142

142-
```
143+
```c#
143144
public string MyProperty;
144145
protected string MyProperty;
145146
private string myProperty;
@@ -157,7 +158,7 @@ Always declare an access modifier for all fields, properties and methods.
157158
158159
### Don't:
159160

160-
```
161+
```c#
161162
// protected field should be private
162163
protected int myVariable = 0;
163164

@@ -171,7 +172,7 @@ void Bar() { }
171172

172173
### Do:
173174

174-
```
175+
```c#
175176
public int MyVariable { get; protected set; } = 0;
176177

177178
private void Foo() { }
@@ -185,7 +186,7 @@ Always use braces after each statement block, and place them on the next line.
185186

186187
### Don't:
187188

188-
```
189+
```c#
189190
private Foo()
190191
{
191192
if (Bar==null) // <- missing braces surrounding if action
@@ -197,7 +198,7 @@ private Foo()
197198

198199
### Don't:
199200

200-
```
201+
```c#
201202
private Foo() { // <- Open bracket on same line
202203
if (Bar==null) DoThing(); <- if action on same line with no surrounding brackets
203204
else DoTheOtherThing();
@@ -206,7 +207,7 @@ private Foo() { // <- Open bracket on same line
206207

207208
### Do:
208209

209-
```
210+
```c#
210211
private Foo()
211212
{
212213
if (Bar==true)
@@ -226,7 +227,7 @@ If the class, struct, or enum can be made private then it's okay to be included
226227

227228
### Don't:
228229

229-
```
230+
```c#
230231
public class MyClass
231232
{
232233
public struct MyStruct() { }
@@ -237,7 +238,7 @@ public class MyClass
237238

238239
### Do:
239240

240-
```
241+
```c#
241242
// Private references for use inside the class only
242243
public class MyClass
243244
{
@@ -249,27 +250,27 @@ public class MyClass
249250

250251
### Do:
251252

252-
```
253+
MyStruct.cs
254+
```c#
253255
// Public Struct / Enum definitions for use in your class. Try to make them generic for reuse.
254-
MyStruct.cs
255256
public struct MyStruct
256257
{
257258
public string Var1;
258259
public string Var2;
259260
}
260261
```
261262

262-
```
263263
MyEnumType.cs
264+
```c#
264265
public enum MuEnumType
265266
{
266267
Value1,
267268
Value2 // <- note, no "," on last value to denote end of list.
268269
}
269270
```
270271

271-
```
272272
MyClass.cs
273+
```c#
273274
public class MyClass
274275
{
275276
private MyStruct myStructreference;
@@ -285,7 +286,7 @@ To ensure all Enum's are initialized correctly starting at 0, .NET gives you a t
285286
286287
### Don't:
287288

288-
```
289+
```c#
289290
public enum Value
290291
{
291292
Value1, <- no initializer
@@ -296,7 +297,7 @@ public enum Value
296297

297298
### Do:
298299

299-
```
300+
```c#
300301
public enum ValueType
301302
{
302303
Value1 = 0,
@@ -311,7 +312,7 @@ It is critical that if an Enum is likely to be extended in the future, to order
311312

312313
### Don't:
313314

314-
```
315+
```c#
315316
public enum SDKType
316317
{
317318
WindowsMR,
@@ -324,7 +325,7 @@ public enum SDKType
324325

325326
### Do:
326327

327-
```
328+
```c#
328329
/// <summary>
329330
/// The SDKType lists the VR SDK's that are supported by the MRTK
330331
/// Initially, this lists proposed SDK's, not all may be implemented at this time (please see ReleaseNotes for more details)
@@ -392,7 +393,7 @@ If there is a possibility for an enum to require multiple states as a value, e.g
392393
393394
### Don't:
394395

395-
```
396+
```c#
396397
public enum Handedness
397398
{
398399
None,
@@ -403,7 +404,7 @@ public enum Handedness
403404

404405
### Do:
405406

406-
```
407+
```c#
407408
[flags]
408409
public enum HandednessType
409410
{
@@ -429,20 +430,20 @@ If you need to have the ability to edit your field in the inspector, it's best p
429430
430431
### Don't:
431432

432-
```
433+
```c#
433434
public float MyValue;
434435
```
435436

436437
### Do:
437438

438-
```
439+
```c#
439440
// private field, only accessible within script (field is not serialized in Unity)
440441
private float myValue;
441442
```
442443

443444
### Do:
444445

445-
```
446+
```c#
446447
// Enable private field to be configurable only in editor (field is correctly serialized in Unity)
447448
[SerializeField]
448449
private float myValue;
@@ -452,7 +453,7 @@ public float MyValue;
452453

453454
### Don't:
454455

455-
```
456+
```c#
456457
private float myValue1;
457458
private float myValue2;
458459

@@ -471,7 +472,7 @@ public float MyValue;
471472

472473
### Do:
473474

474-
```
475+
```c#
475476
// Enable field to be configurable in the editor and available externally to other scripts (field is correctly serialized in Unity)
476477
[SerializeField]
477478
[ToolTip("If using a tooltip, the text should match the public property's summary documentation, if appropriate.")]
@@ -493,13 +494,13 @@ In some cases a foreach is required, e.g. when looping over an IEnumerable. But
493494

494495
### Don't:
495496

496-
```
497+
```c#
497498
foreach(var item in items)
498499
```
499500

500501
### Do:
501502

502-
```
503+
```c#
503504
int length = items.length; // cache reference to list/array length
504505
for(int i=0; i < length; i++)
505506
```
@@ -510,7 +511,7 @@ With the HoloLens in mind, it's best to optimize for performance and cache refer
510511

511512
### Don't:
512513

513-
```
514+
```c#
514515
void Update()
515516
{
516517
gameObject.GetComponent<Renderer>().Foo(Bar);
@@ -519,7 +520,7 @@ void Update()
519520

520521
### Do:
521522

522-
```
523+
```c#
523524
[SerializeField] // To enable setting the reference in the inspector.
524525
private Renderer myRenderer;
525526

@@ -544,7 +545,7 @@ Unity will create a new material each time you use ".material", which will cause
544545

545546
### Don't:
546547

547-
```
548+
```c#
548549
public class MyClass
549550
{
550551
void Update()
@@ -557,7 +558,7 @@ public class MyClass
557558

558559
### Do:
559560

560-
```
561+
```c#
561562
// Private references for use inside the class only
562563
public class MyClass
563564
{

0 commit comments

Comments
 (0)