public void CopyTo(DmdCustomAttributeData[] destination, ref int index, DmdMethodInfo method, ref DmdImplMap?implMap) { if (Count == 0) { return; } var appDomain = ctor.AppDomain; var im = implMap.Value; var attributes = im.Attributes; var charSetType = appDomain.GetWellKnownType(DmdWellKnownType.System_Runtime_InteropServices_CharSet, isOptional: false); var callingConventionType = appDomain.GetWellKnownType(DmdWellKnownType.System_Runtime_InteropServices_CallingConvention, isOptional: false); CharSet charSet; switch (attributes & DmdPInvokeAttributes.CharSetMask) { default: case DmdPInvokeAttributes.CharSetNotSpec: charSet = CharSet.None; break; case DmdPInvokeAttributes.CharSetAnsi: charSet = CharSet.Ansi; break; case DmdPInvokeAttributes.CharSetUnicode: charSet = CharSet.Unicode; break; case DmdPInvokeAttributes.CharSetAuto: charSet = CharSet.Auto; break; } CallingConvention callingConvention; switch (attributes & DmdPInvokeAttributes.CallConvMask) { case DmdPInvokeAttributes.CallConvWinapi: callingConvention = CallingConvention.Winapi; break; case DmdPInvokeAttributes.CallConvCdecl: callingConvention = CallingConvention.Cdecl; break; case DmdPInvokeAttributes.CallConvStdcall: callingConvention = CallingConvention.StdCall; break; case DmdPInvokeAttributes.CallConvThiscall: callingConvention = CallingConvention.ThisCall; break; case DmdPInvokeAttributes.CallConvFastcall: callingConvention = CallingConvention.FastCall; break; default: callingConvention = CallingConvention.Cdecl; break; } var ctorArgs = new[] { new DmdCustomAttributeTypedArgument(appDomain.System_String, im.Module) }; var type = ctor.ReflectedType; var namedArgs = new DmdCustomAttributeNamedArgument[8] { new DmdCustomAttributeNamedArgument(type.GetField("EntryPoint"), new DmdCustomAttributeTypedArgument(appDomain.System_String, im.Name)), new DmdCustomAttributeNamedArgument(type.GetField("CharSet"), new DmdCustomAttributeTypedArgument(charSetType, (int)charSet)), new DmdCustomAttributeNamedArgument(type.GetField("ExactSpelling"), new DmdCustomAttributeTypedArgument(appDomain.System_Boolean, (attributes & DmdPInvokeAttributes.NoMangle) != 0)), new DmdCustomAttributeNamedArgument(type.GetField("SetLastError"), new DmdCustomAttributeTypedArgument(appDomain.System_Boolean, (attributes & DmdPInvokeAttributes.SupportsLastError) != 0)), new DmdCustomAttributeNamedArgument(type.GetField("PreserveSig"), new DmdCustomAttributeTypedArgument(appDomain.System_Boolean, method.IsPreserveSig)), new DmdCustomAttributeNamedArgument(type.GetField("CallingConvention"), new DmdCustomAttributeTypedArgument(callingConventionType, (int)callingConvention)), new DmdCustomAttributeNamedArgument(type.GetField("BestFitMapping"), new DmdCustomAttributeTypedArgument(appDomain.System_Boolean, (attributes & DmdPInvokeAttributes.BestFitMask) == DmdPInvokeAttributes.BestFitEnabled)), new DmdCustomAttributeNamedArgument(type.GetField("ThrowOnUnmappableChar"), new DmdCustomAttributeTypedArgument(appDomain.System_Boolean, (attributes & DmdPInvokeAttributes.ThrowOnUnmappableCharMask) == DmdPInvokeAttributes.ThrowOnUnmappableCharEnabled)), }; destination[index++] = new DmdCustomAttributeData(ctor, ctorArgs, namedArgs, isPseudoCustomAttribute: true); }
public PreserveSigAttributeInfo(DmdMethodInfo method) { if ((method.MethodImplementationFlags & DmdMethodImplAttributes.PreserveSig) != 0) { var caType = method.AppDomain.GetWellKnownType(DmdWellKnownType.System_Runtime_InteropServices_PreserveSigAttribute, isOptional: true); ctor = caType?.GetConstructor(Array.Empty <DmdType>()); Debug.Assert((object)caType == null || (object)ctor != null); } else { ctor = null; } }
public DllImportAttributeInfo(DmdMethodInfo method, ref DmdImplMap?implMap) { if (implMap != null) { var appDomain = method.AppDomain; var caType = appDomain.GetWellKnownType(DmdWellKnownType.System_Runtime_InteropServices_DllImportAttribute, isOptional: true); var charSetType = appDomain.GetWellKnownType(DmdWellKnownType.System_Runtime_InteropServices_CharSet, isOptional: true); var callingConventionType = appDomain.GetWellKnownType(DmdWellKnownType.System_Runtime_InteropServices_CallingConvention, isOptional: true); if ((object)charSetType == null || (object)callingConventionType == null || (object)caType == null) { ctor = null; } else { ctor = caType.GetConstructor(DmdBindingFlags.Public | DmdBindingFlags.NonPublic | DmdBindingFlags.Instance, new[] { appDomain.System_String }); Debug.Assert((object)ctor != null); } } else { ctor = null; } }
public static DmdCustomAttributeData Find(DmdMethodInfo method, DmdType attributeType, bool inherit) { for (var currentMethod = method; (object)currentMethod != null; currentMethod = currentMethod.GetParentDefinition()) { var customAttributes = currentMethod.GetCustomAttributesData(); for (int i = 0; i < customAttributes.Count; i++) { var ca = customAttributes[i]; if ((object)currentMethod != method && ca.IsPseudoCustomAttribute) { continue; } if (DmdMemberInfoEqualityComparer.DefaultType.Equals(ca.AttributeType, attributeType)) { return(ca); } } if (!inherit) { break; } } return(null); }
public static DmdCustomAttributeData Find(DmdMethodInfo method, string attributeTypeFullName, bool inherit) { for (var currentMethod = method; (object)currentMethod != null; currentMethod = currentMethod.GetParentDefinition()) { var customAttributes = currentMethod.GetCustomAttributesData(); for (int i = 0; i < customAttributes.Count; i++) { var ca = customAttributes[i]; if ((object)currentMethod != method && ca.IsPseudoCustomAttribute) { continue; } if (ca.AttributeType.FullName == attributeTypeFullName) { return(ca); } } if (!inherit) { break; } } return(null); }
public DllImportAttributeInfo(DmdMethodInfo method, in DmdImplMap?implMap)
/// <summary> /// Makes a generic method /// </summary> /// <param name="genericMethodDefinition">Generic method definition</param> /// <param name="typeArguments">Generic arguments</param> /// <param name="options">Options</param> /// <returns></returns> public abstract DmdMethodInfo MakeGenericMethod(DmdMethodInfo genericMethodDefinition, IList <DmdType> typeArguments, DmdMakeTypeOptions options = DmdMakeTypeOptions.None);