internal override IList <CustomAttributeData> GetCustomAttributesData(Type attributeType) { List <CustomAttributeData> list = module.GetCustomAttributes(this.MetadataToken, attributeType); if ((this.Attributes & FieldAttributes.HasFieldMarshal) != 0 && (attributeType == null || attributeType.IsAssignableFrom(module.universe.System_Runtime_InteropServices_MarshalAsAttribute))) { list.Add(MarshalSpec.GetMarshalAsAttribute(module, this.MetadataToken)); } if (declaringType.IsExplicitLayout && (attributeType == null || attributeType.IsAssignableFrom(module.universe.System_Runtime_InteropServices_FieldOffsetAttribute))) { int rid = index + 1; // TODO use binary search? for (int i = 0; i < module.FieldLayout.records.Length; i++) { if (module.FieldLayout.records[i].Field == rid) { ConstructorInfo constructor = module.universe.System_Runtime_InteropServices_FieldOffsetAttribute.GetConstructor(new Type[] { module.universe.System_Int32 }); list.Add(new CustomAttributeData(constructor, new object[] { module.FieldLayout.records[i].Offset }, null)); break; } } } return(list); }
public void SetCustomAttribute(CustomAttributeBuilder customAttributeBuilder) { Universe u = moduleBuilder.universe; if (customAttributeBuilder.Constructor.DeclaringType == u.System_Runtime_InteropServices_InAttribute) { flags |= (short)ParameterAttributes.In; } else if (customAttributeBuilder.Constructor.DeclaringType == u.System_Runtime_InteropServices_OutAttribute) { flags |= (short)ParameterAttributes.Out; } else if (customAttributeBuilder.Constructor.DeclaringType == u.System_Runtime_InteropServices_OptionalAttribute) { flags |= (short)ParameterAttributes.Optional; } else if (customAttributeBuilder.Constructor.DeclaringType == u.System_Runtime_InteropServices_MarshalAsAttribute) { MarshalSpec.SetMarshalAsAttribute(moduleBuilder, PseudoToken, customAttributeBuilder); flags |= (short)ParameterAttributes.HasFieldMarshal; } else { moduleBuilder.SetCustomAttribute(PseudoToken, customAttributeBuilder); } }
public void SetCustomAttribute(CustomAttributeBuilder customBuilder) { Universe u = this.Module.universe; if (customBuilder.Constructor.DeclaringType == u.System_Runtime_InteropServices_FieldOffsetAttribute) { customBuilder = customBuilder.DecodeBlob(this.Module.Assembly); SetOffset((int)customBuilder.GetConstructorArgument(0)); } else if (customBuilder.Constructor.DeclaringType == u.System_Runtime_InteropServices_MarshalAsAttribute) { MarshalSpec.SetMarshalAsAttribute(typeBuilder.ModuleBuilder, pseudoToken, customBuilder); attribs |= FieldAttributes.HasFieldMarshal; } else if (customBuilder.Constructor.DeclaringType == u.System_NonSerializedAttribute) { attribs |= FieldAttributes.NotSerialized; } else if (customBuilder.Constructor.DeclaringType == u.System_Runtime_CompilerServices_SpecialNameAttribute) { attribs |= FieldAttributes.SpecialName; } else { typeBuilder.ModuleBuilder.SetCustomAttribute(pseudoToken, customBuilder); } }
internal override IList <CustomAttributeData> GetCustomAttributesData(Type attributeType) { IList <CustomAttributeData> list = base.GetCustomAttributesData(attributeType); if ((this.Attributes & ParameterAttributes.HasFieldMarshal) != 0 && (attributeType == null || attributeType.IsAssignableFrom(this.Module.universe.System_Runtime_InteropServices_MarshalAsAttribute))) { list.Add(MarshalSpec.GetMarshalAsAttribute(this.Module, this.MetadataToken)); } return(list); }
public override void VisitMarshalSpec(MarshalSpec marshalSpec) { if (marshalSpec.Container is FieldDefinition) { FieldReference fr = (FieldReference)marshalSpec.Container; TypeReference tr = GetTypeReference(fr.DeclaringType); if (tr is TypeDefinition) { marshalSpec.Container = (tr as TypeDefinition).Fields.GetField(fr.Name); } else { throw new ArgumentException("Can't found field:" + fr.DeclaringType.FullName + "::" + fr.Name); } } }
internal override IList <CustomAttributeData> GetCustomAttributesData(Type attributeType) { List <CustomAttributeData> list = module.GetCustomAttributes(this.MetadataToken, attributeType); if ((this.Attributes & FieldAttributes.HasFieldMarshal) != 0 && (attributeType == null || attributeType.IsAssignableFrom(module.universe.System_Runtime_InteropServices_MarshalAsAttribute))) { list.Add(MarshalSpec.GetMarshalAsAttribute(module, this.MetadataToken)); } if (declaringType.IsExplicitLayout && (attributeType == null || attributeType.IsAssignableFrom(module.universe.System_Runtime_InteropServices_FieldOffsetAttribute))) { foreach (int i in module.FieldLayout.Filter(index + 1)) { ConstructorInfo constructor = module.universe.System_Runtime_InteropServices_FieldOffsetAttribute.GetPseudoCustomAttributeConstructor(module.universe.System_Int32); list.Add(new CustomAttributeData(module, constructor, new object[] { module.FieldLayout.records[i].Offset }, null)); break; } } return(list); }
public virtual void VisitMarshalSpec(MarshalSpec marshalSpec) { }
public void VisitMarshalSpec(MarshalSpec marshalSpec) { }
public void Read(ClrModuleReader reader) { this.Parent = reader.ReadCodedIndex <HasFieldMarshal>(); this.NativeType = new MarshalSpec(reader.ReadBlob()); }
public void Read(ClrModuleReader reader) { this.Parent = reader.ReadCodedIndex<HasFieldMarshal>(); this.NativeType = new MarshalSpec(reader.ReadBlob()); }