Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use file-scoped namespaces in code examples #104

Merged
merged 2 commits into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading