public PInvokeMethodData(PInvokeLazyFixupField pInvokeLazyFixupField) { PInvokeMetadata metadata = pInvokeLazyFixupField.PInvokeMetadata; ModuleDesc declaringModule = ((MetadataType)pInvokeLazyFixupField.TargetMethod.OwningType).Module; DllImportSearchPath?dllImportSearchPath = default; if (declaringModule.Assembly is EcmaAssembly asm) { // We look for [assembly:DefaultDllImportSearchPaths(...)] var attrHandle = asm.MetadataReader.GetCustomAttributeHandle(asm.AssemblyDefinition.GetCustomAttributes(), "System.Runtime.InteropServices", "DefaultDllImportSearchPathsAttribute"); if (!attrHandle.IsNil) { var attr = asm.MetadataReader.GetCustomAttribute(attrHandle); var decoded = attr.DecodeValue(new CustomAttributeTypeProvider(asm)); if (decoded.FixedArguments.Length == 1 && decoded.FixedArguments[0].Value is int searchPath) { dllImportSearchPath = (DllImportSearchPath)searchPath; } } } ModuleData = new PInvokeModuleData(metadata.Module, dllImportSearchPath, declaringModule); EntryPointName = metadata.Name; CharSet charSetMangling = default; if (declaringModule.Context.Target.IsWindows && !metadata.Flags.ExactSpelling) { // Mirror CharSet normalization from Marshaller.CreateMarshaller bool isAnsi = metadata.Flags.CharSet switch { CharSet.Ansi => true, CharSet.Unicode => false, CharSet.Auto => false, _ => true }; charSetMangling = isAnsi ? CharSet.Ansi : CharSet.Unicode; } CharSetMangling = charSetMangling; }
public PInvokeModuleFixupNode(PInvokeModuleData pInvokeModuleData) { _pInvokeModuleData = pInvokeModuleData; }
public ISymbolNode PInvokeModuleFixup(PInvokeModuleData moduleData) { return(_pInvokeModuleFixups.GetOrAdd(moduleData)); }
public PInvokeMethodFixupNode PInvokeMethodFixup(PInvokeModuleData moduleData, string entryPointName, PInvokeFlags flags) { return(_pInvokeMethodFixups.GetOrAdd(Tuple.Create(moduleData, entryPointName, flags))); }
public PInvokeMethodFixupNode(PInvokeModuleData moduleData, string entryPointName, PInvokeFlags flags) { _moduleData = moduleData; _entryPointName = entryPointName; _flags = flags; }