Skip to content
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
26 changes: 26 additions & 0 deletions src/Scrutor/DecoratedService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;

namespace Scrutor;

/// <summary>
/// A handle to a decorated service. This can be used to resolve decorated services from an <see cref="IServiceProvider"/>
/// using <see cref="ServiceProviderExtensions.GetRequiredDecoratedService{TService}(IServiceProvider, DecoratedService{TService})"/>.
/// </summary>
/// <typeparam name="TService">The type of services which were decorated.</typeparam>
public sealed class DecoratedService<TService>
{
internal DecoratedService(Type serviceType, IReadOnlyList<string> serviceKeys)
{
if (!typeof(TService).IsAssignableFrom(serviceType))
throw new ArgumentException($"The type {serviceType} is not assignable to the service type {typeof(TService)}");

ServiceType = serviceType;
ServiceKeys = serviceKeys;
}

internal Type ServiceType { get; }
internal IReadOnlyList<string> ServiceKeys { get; } // In descending order of precedence

internal DecoratedService<TService2> Downcast<TService2>() => new(ServiceType, ServiceKeys);
}
19 changes: 19 additions & 0 deletions src/Scrutor/MaybeNullWhenAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#if NETFRAMEWORK

using System;

/// <summary>Specifies that when a method returns <see cref="ReturnValue"/>, the parameter will not be null even if the corresponding type allows it.</summary>
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
internal sealed class NotNullWhenAttribute : Attribute
{
/// <summary>Initializes the attribute with the specified return value condition.</summary>
/// <param name="returnValue">
/// The return value condition. If the method returns this value, the associated parameter will not be null.
/// </param>
public NotNullWhenAttribute(bool returnValue) => ReturnValue = returnValue;

/// <summary>Gets the return value condition.</summary>
public bool ReturnValue { get; }
}

#endif
Loading