static string MakeDllImportArguments(string entryPoint, System.Runtime.InteropServices.CharSet charSet, bool setLastError, bool exactSpelling, bool preserveSig, System.Runtime.InteropServices.CallingConvention callingConvention, bool bestFitMapping, bool throwOnUnmappableChar) { var retval = new StringBuilder(); if (!String.IsNullOrWhiteSpace(entryPoint)) { retval.Append(", EntryPoint=\"" + entryPoint + '"'); } if (charSet != DefaultDllImportAttribute.CharSet) { retval.Append(", CharSet = System.Runtime.InteropServices.CharSet." + charSet.ToString()); } MakeDllImportArgument(retval, "SetLastError", setLastError, DefaultDllImportAttribute.SetLastError); MakeDllImportArgument(retval, "ExactSpelling", exactSpelling, DefaultDllImportAttribute.ExactSpelling); MakeDllImportArgument(retval, "PreserveSig", preserveSig, DefaultDllImportAttribute.PreserveSig); if (callingConvention != DefaultDllImportAttribute.CallingConvention) { retval.Append(", CallingConvention=" + callingConvention.ToString()); } MakeDllImportArgument(retval, "BestFitMapping", bestFitMapping, DefaultDllImportAttribute.BestFitMapping); MakeDllImportArgument(retval, "ThrowOnUnmappableChar", throwOnUnmappableChar, DefaultDllImportAttribute.ThrowOnUnmappableChar); return(retval.ToString()); }
public static void VerifyProcCallingConvention(string code, string name, System.Runtime.InteropServices.CallingConvention conv) { CodeMemberMethod mem = ConvertToSingleProc(code, name); CodeAttributeDeclaration decl = null; VerifyAttribute(mem.CustomAttributes, typeof(System.Runtime.InteropServices.DllImportAttribute), ref decl); if (conv == System.Runtime.InteropServices.CallingConvention.Winapi) { VerifyNoArgument(decl, "CallingConvention"); } else { CodeAttributeArgument arg = null; VerifyArgument(decl, "CallingConvention", ref arg); Assert.Equal("CallingConvention." + conv.ToString(), CodeDomPrinter.Convert(arg.Value)); } }
public static void VerifyFPtrCallingConvention(string code, string name, System.Runtime.InteropServices.CallingConvention conv) { CodeTypeDeclarationCollection col = ConvertToCodeDom(code); CodeTypeDeclaration type = null; VerifyType(col, name, ref type); if (conv != System.Runtime.InteropServices.CallingConvention.Winapi) { CodeAttributeDeclaration decl = null; VerifyAttribute(type.CustomAttributes, typeof(System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute), ref decl); CodeAttributeArgument arg = null; VerifyArgument(decl, string.Empty, ref arg); Assert.Equal("CallingConvention." + conv.ToString(), CodeDomPrinter.Convert(arg.Value)); } else { VerifyNoAttribute(type.CustomAttributes, typeof(System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute)); } }