Example #1
0
        /// <summary>
        /// Correlates a dllName string with a IPlatformLibraryNameContainer so that when a dll is loaded with the dllName it gets resolved using the name container.
        /// </summary>
        /// <param name="dllName">The dll name to intercept.</param>
        /// <param name="nameContainer">The platform name provider to use for the intercept.</param>
        protected static void AddDllIntercept(string dllName, IPlatformLibraryNameContainer nameContainer)
        {
            if (DllIntercepts.TryGetValue(dllName, out var existing))
            {
                if (existing.GetType() != nameContainer.GetType())
                {
                    throw new InvalidOperationException($"There is already a dll intercept with this name using the platform name provider '{existing.GetType()}'. (Passed '{nameContainer.GetType()}')");
                }

                // If we get here there was no conflict in the intercept, so we don't have to do anything
            }
            else
            {
                DllIntercepts.Add(dllName, nameContainer);
            }
        }
Example #2
0
 /// <summary>
 /// Loads the given API type into an active instance.
 /// </summary>
 /// <typeparam name="TAPI">The API type.</typeparam>
 /// <param name="nameLoader">The type that provides the name of the native library.</param>
 /// <returns>The API instance.</returns>
 public static TAPI Load <TAPI>(IPlatformLibraryNameContainer nameLoader)
     where TAPI : NativeLibraryBase
 {
     return(_builder.ActivateClass <TAPI>(nameLoader.GetLibraryName()));
 }