25using System.Collections.Generic;
35 internal sealed class CustomAttributeData
38 internal static readonly IList<CustomAttributeData> EmptyList =
new List<CustomAttributeData>(0).AsReadOnly();
94 readonly
int customAttributeIndex;
95 readonly
int declSecurityIndex;
96 readonly
byte[] declSecurityBlob;
99 IList<CustomAttributeTypedArgument> lazyConstructorArguments;
100 IList<CustomAttributeNamedArgument> lazyNamedArguments;
107 internal CustomAttributeData(
Module module,
int index)
109 this.module = module ??
throw new ArgumentNullException(nameof(module));
110 this.customAttributeIndex = index;
111 this.declSecurityIndex = -1;
121 internal CustomAttributeData(
Module module,
ConstructorInfo constructor,
object[] args, List<CustomAttributeNamedArgument> namedArguments) :
122 this(module, constructor, WrapConstructorArgs(args, constructor.
MethodSignature), namedArguments)
127 static List<CustomAttributeTypedArgument> WrapConstructorArgs(
object[] args,
MethodSignature sig)
129 var list =
new List<CustomAttributeTypedArgument>();
130 for (
int i = 0; i < args.Length; i++)
131 list.Add(
new CustomAttributeTypedArgument(sig.GetParameterType(i), args[i]));
146 internal CustomAttributeData(
Module module,
ConstructorInfo constructor, List<CustomAttributeTypedArgument> constructorArgs, List<CustomAttributeNamedArgument> namedArguments)
148 this.module = module ??
throw new ArgumentNullException(nameof(module));
149 this.customAttributeIndex = -1;
150 this.declSecurityIndex = -1;
151 this.lazyConstructor = constructor;
153 lazyConstructorArguments = constructorArgs.AsReadOnly();
154 if (namedArguments ==
null)
155 this.lazyNamedArguments = Array.Empty<CustomAttributeNamedArgument>();
157 this.lazyNamedArguments = namedArguments.AsReadOnly();
169 this.module =
asm.ManifestModule;
170 this.customAttributeIndex = -1;
171 this.declSecurityIndex = -1;
172 this.lazyConstructor = constructor;
176 lazyConstructorArguments = Array.Empty<CustomAttributeTypedArgument>();
177 lazyNamedArguments = Array.Empty<CustomAttributeNamedArgument>();
181 if (br.ReadUInt16() != 1)
182 throw new BadImageFormatException();
184 lazyConstructorArguments = ReadConstructorArguments(module, br, constructor);
185 lazyNamedArguments = ReadNamedArguments(module, br, br.ReadUInt16(), constructor.DeclaringType,
true);
189 public override string ToString()
191 var sb =
new StringBuilder();
193 sb.Append(Constructor.DeclaringType.FullName);
197 var parameters = Constructor.GetParameters();
198 var args = ConstructorArguments;
200 for (
int i = 0; i < parameters.Length; i++)
204 AppendValue(sb, parameters[i].ParameterType, args[i]);
207 foreach (var named
in NamedArguments)
211 sb.Append(named.MemberInfo.Name);
214 var type = fi !=
null ? fi.FieldType : ((
PropertyInfo)named.MemberInfo).PropertyType;
215 AppendValue(sb, type, named.TypedValue);
220 return sb.ToString();
223 static void AppendValue(StringBuilder sb,
Type type, CustomAttributeTypedArgument arg)
225 if (arg.ArgumentType == arg.ArgumentType.Module.Universe.System_String)
227 sb.Append(
'"').Append(arg.Value).Append(
'"');
229 else if (arg.ArgumentType.IsArray)
231 var elementType = arg.ArgumentType.GetElementType();
232 string elementTypeName;
233 if (elementType.IsPrimitive
234 || elementType == type.Module.Universe.System_Object
235 || elementType == type.Module.Universe.System_String
236 || elementType == type.Module.Universe.System_Type)
238 elementTypeName = elementType.Name;
242 elementTypeName = elementType.FullName;
244 sb.Append(
"new ").Append(elementTypeName).Append(
"[").Append(((Array)arg.Value).Length).Append(
"] { ");
246 foreach (var elem
in (CustomAttributeTypedArgument[])arg.Value)
250 AppendValue(sb, elementType, elem);
256 if (arg.ArgumentType != type || (type.IsEnum && !arg.Value.Equals(0)))
259 sb.Append(arg.ArgumentType.FullName);
263 sb.Append(arg.Value);
267 internal static void ReadDeclarativeSecurity(
Module module,
int index, List<CustomAttributeData> list)
269 var
asm = module.Assembly;
270 var action = module.DeclSecurityTable.records[index].Action;
271 var br = module.GetBlobReader(module.DeclSecurityTable.records[index].PermissionSet);
272 if (br.PeekByte() ==
'.')
275 var count = br.ReadCompressedUInt();
276 for (
int j = 0; j < count; j++)
278 var type = ReadType(module, br);
279 var constructor = type.GetPseudoCustomAttributeConstructor(module.Universe.System_Security_Permissions_SecurityAction);
281 var blob = br.ReadBytes(br.ReadCompressedUInt());
282 list.Add(
new CustomAttributeData(
asm, constructor, action, blob, index));
288 var buf =
new char[br.Length / 2];
289 for (
int i = 0; i < buf.Length; i++)
290 buf[i] = br.ReadChar();
292 var xml =
new string(buf);
293 var ctor = module.Universe.System_Security_Permissions_PermissionSetAttribute.GetPseudoCustomAttributeConstructor(module.Universe.System_Security_Permissions_SecurityAction);
294 var args =
new List<CustomAttributeNamedArgument>();
295 args.Add(
new CustomAttributeNamedArgument(GetProperty(
null, module.Universe.System_Security_Permissions_PermissionSetAttribute,
"XML", module.Universe.System_String),
new CustomAttributeTypedArgument(module.Universe.System_String, xml)));
296 list.Add(
new CustomAttributeData(
asm.
ManifestModule, ctor,
new object[] { action }, args));
308 internal CustomAttributeData(
Assembly asm,
ConstructorInfo constructor,
int securityAction,
byte[] blob,
int index)
310 this.module =
asm.ManifestModule;
311 this.customAttributeIndex = -1;
312 this.declSecurityIndex = index;
313 this.lazyConstructor = constructor;
315 var list =
new List<CustomAttributeTypedArgument>();
316 list.Add(
new CustomAttributeTypedArgument(constructor.Module.Universe.System_Security_Permissions_SecurityAction, securityAction));
317 this.lazyConstructorArguments = list.AsReadOnly();
318 this.declSecurityBlob = blob;
323 return br.ReadByte()
switch
325 Signature.ELEMENT_TYPE_BOOLEAN => context.Universe.System_Boolean,
326 Signature.ELEMENT_TYPE_CHAR => context.Universe.System_Char,
327 Signature.ELEMENT_TYPE_I1 => context.Universe.System_SByte,
328 Signature.ELEMENT_TYPE_U1 => context.Universe.System_Byte,
329 Signature.ELEMENT_TYPE_I2 => context.Universe.System_Int16,
330 Signature.ELEMENT_TYPE_U2 => context.Universe.System_UInt16,
331 Signature.ELEMENT_TYPE_I4 => context.Universe.System_Int32,
332 Signature.ELEMENT_TYPE_U4 => context.Universe.System_UInt32,
333 Signature.ELEMENT_TYPE_I8 => context.Universe.System_Int64,
334 Signature.ELEMENT_TYPE_U8 => context.Universe.System_UInt64,
335 Signature.ELEMENT_TYPE_R4 => context.Universe.System_Single,
336 Signature.ELEMENT_TYPE_R8 => context.Universe.System_Double,
337 Signature.ELEMENT_TYPE_STRING => context.Universe.System_String,
338 Signature.ELEMENT_TYPE_SZARRAY => ReadFieldOrPropType(context, br).MakeArrayType(),
339 0x55 => ReadType(context, br),
340 0x50 => context.Universe.System_Type,
341 0x51 => context.Universe.System_Object,
342 _ =>
throw new BadImageFormatException(),
348 var u = context.Universe;
349 if (type == u.System_String)
351 return new CustomAttributeTypedArgument(type, br.ReadString());
353 else if (type == u.System_Boolean)
355 return new CustomAttributeTypedArgument(type, br.ReadByte() != 0);
357 else if (type == u.System_Char)
359 return new CustomAttributeTypedArgument(type, br.ReadChar());
361 else if (type == u.System_Single)
363 return new CustomAttributeTypedArgument(type, br.ReadSingle());
365 else if (type == u.System_Double)
367 return new CustomAttributeTypedArgument(type, br.ReadDouble());
369 else if (type == u.System_SByte)
371 return new CustomAttributeTypedArgument(type, br.ReadSByte());
373 else if (type == u.System_Int16)
375 return new CustomAttributeTypedArgument(type, br.ReadInt16());
377 else if (type == u.System_Int32)
379 return new CustomAttributeTypedArgument(type, br.ReadInt32());
381 else if (type == u.System_Int64)
383 return new CustomAttributeTypedArgument(type, br.ReadInt64());
385 else if (type == u.System_Byte)
387 return new CustomAttributeTypedArgument(type, br.ReadByte());
389 else if (type == u.System_UInt16)
391 return new CustomAttributeTypedArgument(type, br.ReadUInt16());
393 else if (type == u.System_UInt32)
395 return new CustomAttributeTypedArgument(type, br.ReadUInt32());
397 else if (type == u.System_UInt64)
399 return new CustomAttributeTypedArgument(type, br.ReadUInt64());
401 else if (type == u.System_Type)
403 return new CustomAttributeTypedArgument(type, ReadType(context, br));
405 else if (type == u.System_Object)
407 return ReadFixedArg(context, br, ReadFieldOrPropType(context, br));
409 else if (type.IsArray)
411 var length = br.ReadInt32();
413 return new CustomAttributeTypedArgument(type,
null);
415 var elementType = type.GetElementType();
416 var array =
new CustomAttributeTypedArgument[length];
417 for (
int i = 0; i < length; i++)
418 array[i] = ReadFixedArg(context, br, elementType);
420 return new CustomAttributeTypedArgument(type, array);
422 else if (type.IsEnum)
424 return new CustomAttributeTypedArgument(type, ReadFixedArg(context, br, type.GetEnumUnderlyingTypeImpl()).Value);
428 throw new InvalidOperationException();
434 var typeName = br.ReadString();
435 if (typeName ==
null)
439 if (typeName.Length > 0 && typeName[typeName.Length - 1] == 0)
440 typeName = typeName.Substring(0, typeName.Length - 1);
442 return TypeNameParser.Parse(typeName,
true).GetType(context.Universe, context,
true, typeName,
true,
false);
447 var sig = constructor.MethodSignature;
448 var count = sig.GetParameterCount();
449 var list =
new List<CustomAttributeTypedArgument>(count);
450 for (
int i = 0; i < count; i++)
451 list.Add(ReadFixedArg(context, br, sig.GetParameterType(i)));
453 return list.AsReadOnly();
456 static IList<CustomAttributeNamedArgument> ReadNamedArguments(
Module context,
ByteReader br,
int named,
Type type,
bool required)
458 var list =
new List<CustomAttributeNamedArgument>(named);
459 for (
int i = 0; i < named; i++)
461 var fieldOrProperty = br.ReadByte();
462 var fieldOrPropertyType = ReadFieldOrPropType(context, br);
463 if (fieldOrPropertyType.__IsMissing && !required)
466 var name = br.ReadString();
467 var value = ReadFixedArg(context, br, fieldOrPropertyType);
468 var member = fieldOrProperty
switch
470 0x53 => (
MemberInfo)GetField(context, type, name, fieldOrPropertyType),
471 0x54 => (
MemberInfo)GetProperty(context, type, name, fieldOrPropertyType),
472 _ =>
throw new BadImageFormatException(),
475 list.Add(
new CustomAttributeNamedArgument(member, value));
478 return list.AsReadOnly();
484 for (; type !=
null && !type.__IsMissing; type = type.BaseType)
485 foreach (
FieldInfo field in type.__GetDeclaredFields())
486 if (field.IsPublic && !field.IsStatic && field.Name == name)
493 var sig =
FieldSignature.Create(fieldType,
new CustomModifiers());
494 return type.FindField(name, sig) ?? type.Module.Universe.GetMissingFieldOrThrow(context, type, name, sig);
500 for (; type !=
null && !type.__IsMissing; type = type.BaseType)
501 foreach (
PropertyInfo property in type.__GetDeclaredProperties())
502 if (property.IsPublic && !property.IsStatic && property.Name == name)
509 return type.Module.Universe.GetMissingPropertyOrThrow(context, type, name,
PropertySignature.Create(CallingConventions.Standard | CallingConventions.HasThis, propertyType,
null,
new PackedCustomModifiers()));
512 [Obsolete(
"Use AttributeType property instead.")]
513 internal bool __TryReadTypeName(out
string ns, out
string name)
515 if (Constructor.DeclaringType.IsNested)
522 var typeName = AttributeType.TypeName;
523 ns = typeName.Namespace;
524 name = typeName.Name;
528 public byte[] __GetBlob()
530 if (declSecurityBlob !=
null)
531 return (
byte[])declSecurityBlob.Clone();
532 else if (customAttributeIndex == -1)
533 return __ToBuilder().GetBlob(module.Assembly);
535 return ((
ModuleReader)module).GetBlobCopy(module.CustomAttributeTable.records[customAttributeIndex].Value);
542 return customAttributeIndex >= 0
543 ? module.CustomAttributeTable.records[customAttributeIndex].Parent
544 : declSecurityIndex >= 0
545 ? module.DeclSecurityTable.records[declSecurityIndex].Parent
550 public Type AttributeType
552 get {
return Constructor.DeclaringType; }
559 if (lazyConstructor ==
null)
562 return lazyConstructor;
566 public IList<CustomAttributeTypedArgument> ConstructorArguments
570 if (lazyConstructorArguments ==
null)
571 LazyParseArguments(
false);
573 return lazyConstructorArguments;
577 public IList<CustomAttributeNamedArgument> NamedArguments
581 if (lazyNamedArguments ==
null)
583 if (customAttributeIndex >= 0)
586 LazyParseArguments(
true);
593 lazyNamedArguments = ReadNamedArguments(module, br, br.ReadCompressedUInt(), Constructor.DeclaringType,
true);
597 return lazyNamedArguments;
601 void LazyParseArguments(
bool requireNameArguments)
603 var br = module.GetBlobReader(module.CustomAttributeTable.records[customAttributeIndex].Value);
607 lazyConstructorArguments = Array.Empty<CustomAttributeTypedArgument>();
608 lazyNamedArguments = Array.Empty<CustomAttributeNamedArgument>();
612 if (br.ReadUInt16() != 1)
613 throw new BadImageFormatException();
615 lazyConstructorArguments = ReadConstructorArguments(module, br, Constructor);
616 lazyNamedArguments = ReadNamedArguments(module, br, br.ReadUInt16(), Constructor.DeclaringType, requireNameArguments);
620 public CustomAttributeBuilder __ToBuilder()
622 var parameters = Constructor.GetParameters();
623 var args =
new object[ConstructorArguments.Count];
624 for (
int i = 0; i < args.Length; i++)
625 args[i] = RewrapArray(parameters[i].ParameterType, ConstructorArguments[i]);
627 var namedProperties =
new List<PropertyInfo>();
628 var propertyValues =
new List<object>();
629 var namedFields =
new List<FieldInfo>();
630 var fieldValues =
new List<object>();
632 foreach (var named
in NamedArguments)
637 namedProperties.Add(pi);
638 propertyValues.Add(RewrapArray(pi.PropertyType, named.TypedValue));
644 fieldValues.Add(RewrapArray(fi.FieldType, named.TypedValue));
648 return new CustomAttributeBuilder(Constructor, args, namedProperties.ToArray(), propertyValues.ToArray(), namedFields.ToArray(), fieldValues.ToArray());
651 static object RewrapArray(
Type type, CustomAttributeTypedArgument arg)
653 var list = arg.Value as IList<CustomAttributeTypedArgument>;
656 var elementType = arg.ArgumentType.GetElementType();
657 var arr =
new object[list.Count];
658 for (
int i = 0; i < arr.Length; i++)
659 arr[i] = RewrapArray(elementType, list[i]);
661 if (type == type.Module.Universe.System_Object)
662 return CustomAttributeBuilder.__MakeTypedArgument(arg.ArgumentType, arr);
672 public static IList<CustomAttributeData> GetCustomAttributes(
MemberInfo member)
674 return __GetCustomAttributes(member,
null,
false);
677 public static IList<CustomAttributeData> GetCustomAttributes(
Assembly assembly)
679 return assembly.GetCustomAttributesData(
null);
682 public static IList<CustomAttributeData> GetCustomAttributes(
Module module)
684 return __GetCustomAttributes(module,
null,
false);
687 public static IList<CustomAttributeData> GetCustomAttributes(
ParameterInfo parameter)
689 return __GetCustomAttributes(parameter,
null,
false);
692 public static IList<CustomAttributeData> __GetCustomAttributes(
Assembly assembly,
Type attributeType,
bool inherit)
694 return assembly.GetCustomAttributesData(attributeType);
697 public static IList<CustomAttributeData> __GetCustomAttributes(
Module module,
Type attributeType,
bool inherit)
699 if (module.__IsMissing)
702 return GetCustomAttributesImpl(
null, module, 0x00000001, attributeType) ?? EmptyList;
705 public static IList<CustomAttributeData> __GetCustomAttributes(
ParameterInfo parameter,
Type attributeType,
bool inherit)
707 var module = parameter.Module;
708 List<CustomAttributeData> list =
null;
709 if (module.Universe.ReturnPseudoCustomAttributes)
711 if (attributeType ==
null || attributeType.IsAssignableFrom(parameter.Module.Universe.System_Runtime_InteropServices_MarshalAsAttribute))
713 if (parameter.__TryGetFieldMarshal(out var spec))
715 list ??=
new List<CustomAttributeData>();
716 list.Add(CustomAttributeData.CreateMarshalAsPseudoCustomAttribute(parameter.Module, spec));
721 var token = parameter.MetadataToken;
722 if (module is ModuleBuilder mb && mb.IsSaved && ModuleBuilder.IsPseudoToken(token))
723 token = mb.ResolvePseudoToken(token);
725 return GetCustomAttributesImpl(list, module, token, attributeType) ?? EmptyList;
728 public static IList<CustomAttributeData> __GetCustomAttributes(
MemberInfo member,
Type attributeType,
bool inherit)
732 throw new NotImplementedException();
734 if (!inherit || !IsInheritableAttribute(attributeType))
735 return GetCustomAttributesImpl(
null, member, attributeType) ?? EmptyList;
737 var list =
new List<CustomAttributeData>();
740 GetCustomAttributesImpl(list, member, attributeType);
742 var type = member as
Type;
745 type = type.BaseType;
757 method = method.GetBaseDefinition();
758 if (method ==
null || method == prev)
769 static List<CustomAttributeData> GetCustomAttributesImpl(List<CustomAttributeData> list,
MemberInfo member,
Type attributeType)
771 if (member.Module.Universe.ReturnPseudoCustomAttributes)
773 var pseudo = member.GetPseudoCustomAttributes(attributeType);
776 else if (pseudo !=
null)
777 list.AddRange(pseudo);
780 return GetCustomAttributesImpl(list, member.Module, member.GetCurrentToken(), attributeType);
783 internal static List<CustomAttributeData> GetCustomAttributesImpl(List<CustomAttributeData> list,
Module module,
int token,
Type attributeType)
785 foreach (var i
in module.CustomAttributeTable.Filter(token))
787 if (attributeType ==
null)
789 list ??=
new List<CustomAttributeData>();
790 list.Add(
new CustomAttributeData(module, i));
794 if (attributeType.IsAssignableFrom(module.ResolveMethod(module.CustomAttributeTable.records[i].Constructor).DeclaringType))
796 list ??=
new List<CustomAttributeData>();
797 list.Add(
new CustomAttributeData(module, i));
805 public static IList<CustomAttributeData> __GetCustomAttributes(
Type type,
Type interfaceType,
Type attributeType,
bool inherit)
807 var module = type.Module;
808 foreach (
int i
in module.InterfaceImplTable.Filter(type.MetadataToken))
809 if (module.ResolveType(module.InterfaceImplTable.records[i].Interface, type) == interfaceType)
810 return GetCustomAttributesImpl(
null, module, (
InterfaceImplTable.Index << 24) | (i + 1), attributeType) ?? EmptyList;
815 public static IList<CustomAttributeData> __GetDeclarativeSecurity(
Assembly assembly)
817 if (assembly.__IsMissing)
820 return assembly.ManifestModule.GetDeclarativeSecurity(0x20000001);
823 public static IList<CustomAttributeData> __GetDeclarativeSecurity(
Type type)
825 if ((type.Attributes & TypeAttributes.HasSecurity) != 0)
826 return type.Module.GetDeclarativeSecurity(type.MetadataToken);
831 public static IList<CustomAttributeData> __GetDeclarativeSecurity(
MethodBase method)
833 if ((method.Attributes & MethodAttributes.HasSecurity) != 0)
834 return method.Module.GetDeclarativeSecurity(method.MetadataToken);
839 private static bool IsInheritableAttribute(
Type attribute)
841 var attributeUsageAttribute = attribute.Module.Universe.System_AttributeUsageAttribute;
842 var attr = __GetCustomAttributes(attribute, attributeUsageAttribute,
false);
844 foreach (CustomAttributeNamedArgument named
in attr[0].NamedArguments)
845 if (named.MemberInfo.Name ==
"Inherited")
846 return (
bool)named.TypedValue.Value;
851 internal static CustomAttributeData CreateDllImportPseudoCustomAttribute(
Module module, ImplMapFlags flags,
string entryPoint,
string dllName, MethodImplAttributes attr)
854 var charSet = (flags & ImplMapFlags.CharSetMask)
switch
856 ImplMapFlags.CharSetAnsi =>
System.
Runtime.InteropServices.CharSet.Ansi,
857 ImplMapFlags.CharSetUnicode =>
System.
Runtime.InteropServices.CharSet.Unicode,
858 ImplMapFlags.CharSetAuto =>
System.
Runtime.InteropServices.CharSet.Auto,
862 var callingConvention = (flags & ImplMapFlags.CallConvMask)
switch
864 ImplMapFlags.CallConvCdecl =>
System.
Runtime.InteropServices.CallingConvention.Cdecl,
865 ImplMapFlags.CallConvFastcall =>
System.
Runtime.InteropServices.CallingConvention.FastCall,
866 ImplMapFlags.CallConvStdcall =>
System.
Runtime.InteropServices.CallingConvention.StdCall,
867 ImplMapFlags.CallConvThiscall =>
System.
Runtime.InteropServices.CallingConvention.ThisCall,
868 ImplMapFlags.CallConvWinapi =>
System.
Runtime.InteropServices.CallingConvention.Winapi,
872 var list =
new List<CustomAttributeNamedArgument>();
873 var type = module.Universe.System_Runtime_InteropServices_DllImportAttribute;
874 var constructor = type.GetPseudoCustomAttributeConstructor(module.Universe.System_String);
875 AddNamedArgument(list, type,
"EntryPoint", entryPoint);
876 AddNamedArgument(list, type,
"CharSet", module.Universe.System_Runtime_InteropServices_CharSet, (
int)charSet);
877 AddNamedArgument(list, type,
"ExactSpelling", (
int)flags, (
int)ImplMapFlags.NoMangle);
878 AddNamedArgument(list, type,
"SetLastError", (
int)flags, (
int)ImplMapFlags.SupportsLastError);
879 AddNamedArgument(list, type,
"PreserveSig", (
int)attr, (
int)MethodImplAttributes.PreserveSig);
880 AddNamedArgument(list, type,
"CallingConvention", module.Universe.System_Runtime_InteropServices_CallingConvention, (
int)callingConvention);
881 AddNamedArgument(list, type,
"BestFitMapping", (
int)flags, (
int)ImplMapFlags.BestFitOn);
882 AddNamedArgument(list, type,
"ThrowOnUnmappableChar", (
int)flags, (
int)ImplMapFlags.CharMapErrorOn);
883 return new CustomAttributeData(module, constructor,
new object[] { dllName }, list);
886 internal static CustomAttributeData CreateMarshalAsPseudoCustomAttribute(
Module module, FieldMarshal fm)
888 var typeofMarshalAs = module.Universe.System_Runtime_InteropServices_MarshalAsAttribute;
889 var typeofUnmanagedType = module.Universe.System_Runtime_InteropServices_UnmanagedType;
890 var typeofVarEnum = module.Universe.System_Runtime_InteropServices_VarEnum;
891 var typeofType = module.Universe.System_Type;
892 var named =
new List<CustomAttributeNamedArgument>();
893 AddNamedArgument(named, typeofMarshalAs,
"ArraySubType", typeofUnmanagedType, (
int)(fm.ArraySubType ?? 0));
894 AddNamedArgument(named, typeofMarshalAs,
"SizeParamIndex", module.Universe.System_Int16, fm.SizeParamIndex ?? 0);
895 AddNamedArgument(named, typeofMarshalAs,
"SizeConst", module.Universe.System_Int32, fm.SizeConst ?? 0);
896 AddNamedArgument(named, typeofMarshalAs,
"IidParameterIndex", module.Universe.System_Int32, fm.IidParameterIndex ?? 0);
897 AddNamedArgument(named, typeofMarshalAs,
"SafeArraySubType", typeofVarEnum, (
int)(fm.SafeArraySubType ?? 0));
898 if (fm.SafeArrayUserDefinedSubType !=
null)
899 AddNamedArgument(named, typeofMarshalAs,
"SafeArrayUserDefinedSubType", typeofType, fm.SafeArrayUserDefinedSubType);
900 if (fm.MarshalType !=
null)
901 AddNamedArgument(named, typeofMarshalAs,
"MarshalType", module.Universe.System_String, fm.MarshalType);
902 if (fm.MarshalTypeRef !=
null)
903 AddNamedArgument(named, typeofMarshalAs,
"MarshalTypeRef", module.Universe.System_Type, fm.MarshalTypeRef);
904 if (fm.MarshalCookie !=
null)
905 AddNamedArgument(named, typeofMarshalAs,
"MarshalCookie", module.Universe.System_String, fm.MarshalCookie);
907 var constructor = typeofMarshalAs.GetPseudoCustomAttributeConstructor(typeofUnmanagedType);
908 return new CustomAttributeData(module, constructor,
new object[] { (int)fm.UnmanagedType }, named);
911 static void AddNamedArgument(List<CustomAttributeNamedArgument> list,
Type type,
string fieldName,
string value)
913 AddNamedArgument(list, type, fieldName, type.Module.Universe.System_String, value);
916 static void AddNamedArgument(List<CustomAttributeNamedArgument> list,
Type type,
string fieldName,
int flags,
int flagMask)
918 AddNamedArgument(list, type, fieldName, type.Module.Universe.System_Boolean, (flags & flagMask) != 0);
921 static void AddNamedArgument(List<CustomAttributeNamedArgument> list,
Type attributeType,
string fieldName,
Type valueType,
object value)
924 var field = attributeType.FindField(fieldName,
FieldSignature.Create(valueType,
new CustomModifiers()));
926 list.Add(
new CustomAttributeNamedArgument(field,
new CustomAttributeTypedArgument(valueType, value)));
929 internal static CustomAttributeData CreateFieldOffsetPseudoCustomAttribute(
Module module,
int offset)
931 var type = module.Universe.System_Runtime_InteropServices_FieldOffsetAttribute;
932 var constructor = type.GetPseudoCustomAttributeConstructor(module.Universe.System_Int32);
933 return new CustomAttributeData(module, constructor,
new object[] { offset },
null);
936 internal static CustomAttributeData CreatePreserveSigPseudoCustomAttribute(
Module module)
938 var type = module.Universe.System_Runtime_InteropServices_PreserveSigAttribute;
939 var constructor = type.GetPseudoCustomAttributeConstructor();
940 return new CustomAttributeData(module, constructor, Array.Empty<
object>(),
null);
IKVM.Reflection.Module Module
IKVM.Reflection.Type Type
IKVM.Reflection.Assembly Assembly
IKVM.Reflection.ConstructorInfo ConstructorInfo
IKVM.Reflection.FieldInfo FieldInfo
IKVM.Reflection.MemberInfo MemberInfo
IKVM.Reflection.PropertyInfo PropertyInfo
IKVM.Reflection.MethodInfo MethodInfo
IKVM.Reflection.ParameterInfo ParameterInfo
IKVM.Reflection.MethodBase MethodBase
Represents a method signature from IL metadadata.
override MethodBase ResolveMethod(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)