public static T Add <T>(this IRootContext @this, Func <T> create) where T : ISerializerExtension { var result = create(); @this.Add(result); return(result); }
public static IRootContext Apply <T>(this IRootContext @this, Func <T> create) where T : class, ISerializerExtension { if ([email protected] <T>()) { @this.Add(create); } return(@this); }
public static T With <T>(this IRootContext @this) where T : class, ISerializerExtension => @this.Find <T>() ?? @this.Add <T>();
/// <summary> /// Adds an extension of the provided type to the provided context. This will be done by attempting to locate a /// singleton on the provided type, and if that isn't found, activate it by calling its public constructor. /// </summary> /// <typeparam name="T">The serializer extension type to locate and add.</typeparam> /// <param name="this">The configuration context (usually a configuration container) with which to add the created /// serializer extension.</param> /// <returns>The created and added extension.</returns> public static T Add <T>(this IRootContext @this) where T : ISerializerExtension => @this.Add(Support <T> .NewOrSingleton);
/// <summary> /// Used to apply a new serializer extension of the provided type. If an extension already exists in the provided /// context, it is returned. Otherwise, it will use the provided factory to create the serializer and register it /// with the provided context. /// </summary> /// <typeparam name="T">The serializer extension type to apply.</typeparam> /// <param name="this">The configuration context (usually a configuration container) to locate the provided serializer /// extension type.</param> /// <param name="create">The factory used to create the extension of the requested type, if an instance of its type /// does not already exist.</param> /// <returns>The configured context with the requested extension applied to it.</returns> public static IRootContext Apply <T>(this IRootContext @this, Func <T> create) where T : class, ISerializerExtension => @this.Contains <T>() ? @this : @this.Add(create).Return(@this);