Merge pull request #439 from mono-soc-2012/garyb/iconfix
[mono.git] / mcs / class / IKVM.Reflection / FieldInfo.cs
index 62d95eb4656b599aae856874d834dc82fb809596..92f89090ea0280a4ec57e0bc413dcc719e0c35f7 100644 (file)
@@ -130,6 +130,13 @@ namespace IKVM.Reflection
                        return this;
                }
 
+               public abstract bool __TryGetFieldOffset(out int offset);
+
+               public bool __TryGetFieldMarshal(out FieldMarshal fieldMarshal)
+               {
+                       return FieldMarshal.ReadFieldMarshal(this.Module, GetCurrentToken(), out fieldMarshal);
+               }
+
                internal abstract int ImportTo(Emit.ModuleBuilder module);
 
                internal virtual FieldInfo BindTypeParameters(Type type)
@@ -154,6 +161,29 @@ namespace IKVM.Reflection
                {
                        return new FieldInfoWithReflectedType(type, this);
                }
+
+               internal sealed override List<CustomAttributeData> GetPseudoCustomAttributes(Type attributeType)
+               {
+                       Module module = this.Module;
+                       List<CustomAttributeData> list = new List<CustomAttributeData>();
+                       if (attributeType == null || attributeType.IsAssignableFrom(module.universe.System_Runtime_InteropServices_MarshalAsAttribute))
+                       {
+                               FieldMarshal spec;
+                               if (__TryGetFieldMarshal(out spec))
+                               {
+                                       list.Add(CustomAttributeData.CreateMarshalAsPseudoCustomAttribute(module, spec));
+                               }
+                       }
+                       if (attributeType == null || attributeType.IsAssignableFrom(module.universe.System_Runtime_InteropServices_FieldOffsetAttribute))
+                       {
+                               int offset;
+                               if (__TryGetFieldOffset(out offset))
+                               {
+                                       list.Add(CustomAttributeData.CreateFieldOffsetPseudoCustomAttribute(module, offset));
+                               }
+                       }
+                       return list;
+               }
        }
 
        sealed class FieldInfoWithReflectedType : FieldInfo
@@ -183,6 +213,11 @@ namespace IKVM.Reflection
                        get { return field.__FieldRVA; }
                }
 
+               public override bool __TryGetFieldOffset(out int offset)
+               {
+                       return field.__TryGetFieldOffset(out offset);
+               }
+
                public override Object GetRawConstantValue()
                {
                        return field.GetRawConstantValue();
@@ -236,11 +271,6 @@ namespace IKVM.Reflection
                        return reflectedType.GetHashCode() ^ field.GetHashCode();
                }
 
-               internal override IList<CustomAttributeData> GetCustomAttributesData(Type attributeType)
-               {
-                       return field.GetCustomAttributesData(attributeType);
-               }
-
                public override int MetadataToken
                {
                        get { return field.MetadataToken; }
@@ -260,5 +290,15 @@ namespace IKVM.Reflection
                {
                        return field.ToString();
                }
+
+               internal override int GetCurrentToken()
+               {
+                       return field.GetCurrentToken();
+               }
+
+               internal override bool IsBaked
+               {
+                       get { return field.IsBaked; }
+               }
        }
 }