public void Intercept(IInvocation invocation)
        {
            Raise.ObjectDisposedException.If(_isDisposed, nameof(WrapperClientInterceptor));

            // Early out if it's a call to Dispose()
            if (invocation.Method.Name == nameof(IDisposable.Dispose))
            {
                Dispose();
                return;
            }

            Type[] parameterTypes = GetParameterTypesFromInvocation(invocation);
            Type   returnType     = invocation.Method.ReturnType;

            LegacyDllImportAttribute dllImportAttribute = GetLegacyAttribute <LegacyDllImportAttribute>(_interfaceType);
            LegacyDllMethodAttribute dllMethodAttribute = GetLegacyAttribute <LegacyDllMethodAttribute>(invocation.Method);

            string libraryName = _libraryNameProvider.GetLibraryName(dllImportAttribute);

            var callData = new CallData
            {
                LibraryName       = libraryName,
                ProcedureName     = invocation.Method.Name,
                Parameters        = invocation.Arguments,
                ParameterTypes    = parameterTypes,
                ReturnType        = returnType,
                CallingConvention = dllMethodAttribute.CallingConvention,
                CharSet           = dllMethodAttribute.CharSet,
            };

            invocation.ReturnValue = _wrapperClient.InvokeInternal(callData);
        }
 public string GetLibraryName(LegacyDllImportAttribute attribute)
 {
     if (Environment.Is64BitProcess)
     {
         return(@"TestLibrary\LegacyWrapperTestDll32.dll");
     }
     else
     {
         return(@"TestLibrary\LegacyWrapperTestDll64.dll");
     }
 }
Exemple #3
0
        public string GetLibraryName(LegacyDllImportAttribute attribute)
        {
            Raise.ArgumentNullException.IfIsNull(attribute, nameof(attribute));

            return(attribute.LibraryName);
        }