Skip to content

Commit

Permalink
Use file-scoped namespaces in code examples (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
0x6273 authored Jan 6, 2024
1 parent 06ddb56 commit e4e29c4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 27 deletions.
28 changes: 13 additions & 15 deletions src/en/robust-toolbox/ioc.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,25 @@ So, **to make a dependency**, you're gonna want two things: an interface, and an

```cs
// Content.Server/Example/MyDependency.cs
namespace Content.Server.Example
namespace Content.Server.Example;

public class MyDependency : IMyDependency
{
public class MyDependency : IMyDependency
public void Foo()
{
public void Foo()
{
Console.WriteLine("Hello World!");
}
Console.WriteLine("Hello World!");
}
}

// Content.Server/Interfaces/Example/IMyDependency.cs
namespace Content.Server.Interfaces.Example
namespace Content.Server.Interfaces.Example;

public interface IMyDependency
{
public interface IMyDependency
{
/// <summary>
/// Writes a message to the console.
/// </summary>
void Foo();
}
/// <summary>
/// Writes a message to the console.
/// </summary>
void Foo();
}

// ServerContentIoC.cs
Expand Down Expand Up @@ -104,4 +102,4 @@ public class MyDependency : IMyDependency, IPostInjectInit
}
```

Field injection can be ran manually by using `IoCManager.InjectDependencies(object)`. It is done automatically for many dynamically instantiated types, such as entity components, entity systems, and anything instantiated via `IDynamicTypeFactory`.
Field injection can be ran manually by using `IoCManager.InjectDependencies(object)`. It is done automatically for many dynamically instantiated types, such as entity components, entity systems, and anything instantiated via `IDynamicTypeFactory`.
22 changes: 10 additions & 12 deletions src/en/ss14-by-example/adding-a-simple-bikehorn.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,11 @@ Now let's just make the most basic component possible:
```csharp
// Content.Server/Sound/PlaySoundOnUseComponent.cs
namespace Content.Server.Sound
namespace Content.Server.Sound;

[RegisterComponent]
public sealed partial class PlaySoundOnUseComponent : Component
{
[RegisterComponent]
public sealed partial class PlaySoundOnUseComponent : Component
{
}
}
```

Expand Down Expand Up @@ -189,14 +188,13 @@ In our case, we'll probably want a field called `sound` on our component, which
```csharp
// Content.Server/Sound/PlaySoundOnUseComponent.cs
namespace Content.Server.Sound
namespace Content.Server.Sound;
[RegisterComponent]
public sealed partial class PlaySoundOnUseComponent : Component
{
[RegisterComponent]
public sealed partial class PlaySoundOnUseComponent : Component
{
[DataField]
public string Sound = string.Empty;
}
[DataField]
public string Sound = string.Empty;
}
```

Expand Down

0 comments on commit e4e29c4

Please sign in to comment.