/// <summary> /// Creates an implementation of interface <typeparamref name="T"/> and /// initializes it using the provided <paramref name="initializer"/> delegate. /// </summary> /// <typeparam name="T"> /// The type of interface to create an implementation for. /// </typeparam> /// <param name="initializer"> /// The initializer to run when an instance has been created. /// </param> /// <returns> /// An instance of <typeparamref name="T"/>. /// </returns> /// <exception cref="InvalidOperationException"> /// <typeref name="T"/> is not an interface. /// </exception> /// <exception cref="InvalidOperationException"> /// <typeref name="T"/> contains methods. /// </exception> public static T CreateContract <T>(Action <T> initializer) where T : class { return(DynamicContract <T> .CreateInstance(initializer)); }
/// <summary> /// Creates realization of a contract via the <see cref="IDynamicContract"/> mechanism /// </summary> /// <typeparam name="T">The contract type for which a realization will be created</typeparam> /// <returns></returns> public static T Create <T>(HttpContractedClientOptions options) => DynamicContract.Realize <T>(new HttpContractedClient(typeof(T), options));
/// <summary> /// Creates a dynamic implementation of interface <typeparamref name="T"/>. /// </summary> /// <typeparam name="T"> /// The type of interface to create an implementation for. /// </typeparam> /// <returns> /// An instance of <typeparamref name="T"/>. /// </returns> /// <exception cref="InvalidOperationException"> /// <typeref name="T"/> is not an interface. /// </exception> /// <exception cref="InvalidOperationException"> /// <typeref name="T"/> contains methods. /// </exception> public static T CreateContract <T>() where T : class { return(DynamicContract <T> .CreateInstance()); }