2using System.Collections.Generic;
3using System.Reflection;
11 [AttributeUsage(AttributeTargets.Interface | AttributeTargets.Class, AllowMultiple =
false, Inherited =
true)]
14 private static readonly Dictionary<Type, Type> defaultImplementationOverrides =
new Dictionary<Type, Type>();
15 private readonly
Type type;
25 throw new ArgumentException(
"Type cannot be null.", nameof(
Type));
42 lock (defaultImplementationOverrides)
44 if (defaultImplementationOverrides.ContainsKey(From))
45 throw new InvalidOperationException(
"Default implemnentation already registered.");
47 defaultImplementationOverrides[From] = To;
58 lock (defaultImplementationOverrides)
60 if (defaultImplementationOverrides.TryGetValue(From, out
Type To2) && To == To2)
61 return defaultImplementationOverrides.Remove(From);
75 lock (defaultImplementationOverrides)
77 if (defaultImplementationOverrides.TryGetValue(
Type, out DefaultImplementation))
81 TypeInfo TI =
Type.GetTypeInfo();
86 DefaultImplementation = Attr.
Type;
Defines a default implementation for an interface. If a request to instantiate an interface is made,...
static bool UnregisterDefaultImplementation(Type From, Type To)
Unregisters a default implementation for an interface.
static void RegisterDefaultImplementation(Type From, Type To)
Registers a default implementation for an interface.
Type Type
Type to instantiate.
DefaultImplementationAttribute(Type Type)
Defines a default implementation for an interface. If a request to instantiate an interface is made,...
static bool TryGetDefaultImplementation(Type Type, out Type DefaultImplementation)
Tries to get the default implementation for an interface.