Files
RobustToolbox/Robust.Shared/IoC/Exceptions/UnregisteredDependencyException.cs
T
Pieter-Jan Briers b4eb85ad3c [Dependency] source generator (#6549)
* [Dependency] source generator

No more reflection, no more codegen at runtime

Also various changes to Roslyn helpers to make this easier to write.

Requires all types with dependencies to be partial and not have readonly dependency fields. An analyzer enforces this at warning level, the previous injection strategies have remained in the code *for now* as a fallback.

No fallback is available for [field: Dependency] properties, due to a Roslyn bug.

Code Fixes exist. We love Roslyn

* Release notes

* Handle nullable dependencies

These are bad but gotta deal with it.

* Apply suggestions from code review

Co-authored-by: Moony <moony@hellomouse.net>

* Fine, let's not use collection expressions

---------

Co-authored-by: Moony <moony@hellomouse.net>
2026-05-08 12:38:02 +02:00

47 lines
1.6 KiB
C#

using System;
using System.Runtime.Serialization;
namespace Robust.Shared.IoC.Exceptions
{
/// <summary>
/// Like <see cref="UnregisteredTypeException"/>,
/// except that this is thrown when using field injection via <see cref="DependencyAttribute"/> and includes extra metadata.
/// </summary>
[Serializable]
[Virtual]
public class UnregisteredDependencyException : Exception
{
/// <summary>
/// The type name of the type requesting the unregistered dependency.
/// </summary>
public readonly string? OwnerType;
/// <summary>
/// The type name of the type that was requested and unregistered.
/// </summary>
public readonly string? TargetType;
/// <summary>
/// The name of the field that was marked as dependency.
/// </summary>
public readonly string? FieldName;
public UnregisteredDependencyException(Type owner, Type target, string fieldName)
: base(string.Format("{0} requested unregistered type with its field {1}: {2}",
owner, target, fieldName))
{
OwnerType = owner.AssemblyQualifiedName;
TargetType = target.AssemblyQualifiedName;
FieldName = fieldName;
}
public UnregisteredDependencyException(Type owner, Type target)
: base($"{owner} requested unregistered type with a dependency field: {target}")
{
OwnerType = owner.AssemblyQualifiedName;
TargetType = target.AssemblyQualifiedName;
FieldName = null;
}
}
}