public static TInterface Implement <TInterface>(IMethodCallProbe <TInterface> probe, Func <string, string> lookupFunctionName = null) where TInterface : class { var libattrib = typeof(TInterface).GetCustomAttributes(typeof(LibraryAttribute), true).OfType <LibraryAttribute>().FirstOrDefault(); if (libattrib == null) { throw new InvalidOperationException(string.Format("The type '{0}' is missing a LibraryAttribute.", typeof(TInterface).Name)); } return(Implement(libattrib.Name, probe, lookupFunctionName)); }
public static TInterface Implement <TInterface>(string library, IMethodCallProbe <TInterface> probe, Func <string, string> lookupFunctionName = null) where TInterface : class { var lib = LibraryLoaderFactory.Create().Load(library); if (lib == null) { throw new DllNotFoundException(string.Format("Unable to locate the library '{0}'.", library)); } return(Implement(lib, probe, lookupFunctionName)); }
public static TInterface Implement <TInterface>(ILibrary library, IMethodCallProbe <TInterface> probe, Func <string, string> lookupFunctionName = null) where TInterface : class { if (library == null) { throw new ArgumentNullException("library"); } if (probe == null) { throw new ArgumentNullException("probe"); } var constructorBuilder = new ProbingConstructorBuilder(lookupFunctionName); var methoCallWrapper = new ProbingMethodCallWrapper(() => constructorBuilder.ProbeField); var mapper = new LibraryInterfaceMapper(new DelegateTypeBuilder(), constructorBuilder, methoCallWrapper); return(mapper.Implement <TInterface>(library, probe)); }