public static IRootContext Apply <T>(this IRootContext @this, Func <T> create) where T : class, ISerializerExtension { if ([email protected] <T>()) { @this.Add(create); } return(@this); }
/// <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);