Skip to content

Commit

Permalink
Use file-scoped namespaces in code examples
Browse files Browse the repository at this point in the history
  • Loading branch information
0x6273 committed Jan 6, 2024
1 parent d791190 commit 9507031
Show file tree
Hide file tree
Showing 2 changed files with 24 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`.
23 changes: 11 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,15 +188,15 @@ 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;
}
```

All you need to do to create a field that can be modified in YAML is to add the `[DataField]` attribute, which holds the name of the field, and give it a default value, in this case `string.Empty`. Now, we can add our sound to our bike horn prototype:
Expand Down

0 comments on commit 9507031

Please sign in to comment.