2 using System.Collections.Generic;
4 using System.Reflection;
6 using Mono.Cecil.Metadata;
8 namespace Mono.Debugger.Soft
10 public class FieldInfoMirror : Mirror {
15 FieldAttributes attrs;
16 CustomAttributeDataMirror[] cattrs;
17 C.FieldDefinition meta;
20 public FieldInfoMirror (TypeMirror parent, long id, string name, TypeMirror type, FieldAttributes attrs) : base (parent.VirtualMachine, id) {
28 public FieldInfoMirror (VirtualMachine vm, long id) : base (vm, id) {
31 public TypeMirror DeclaringType {
47 public TypeMirror FieldType {
55 public FieldAttributes Attributes {
66 var info = vm.conn.Field_GetInfo (id);
68 parent = vm.GetType (info.Parent);
69 type = vm.GetType (info.TypeId);
70 attrs = (FieldAttributes)info.Attrs;
76 get {return (Attributes & FieldAttributes.Literal) != 0;}
81 get {return (Attributes & FieldAttributes.Static) != 0;}
84 public bool IsInitOnly
86 get {return (Attributes & FieldAttributes.InitOnly) != 0;}
89 public Boolean IsPublic
93 return (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Public;
97 public Boolean IsPrivate
101 return (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Private;
105 public Boolean IsFamily
109 return (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Family;
113 public Boolean IsAssembly
117 return (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Assembly;
121 public Boolean IsFamilyAndAssembly
124 return (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.FamANDAssem;
128 public Boolean IsFamilyOrAssembly
132 return (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.FamORAssem;
136 public Boolean IsPinvokeImpl
140 return (Attributes & FieldAttributes.PinvokeImpl) == FieldAttributes.PinvokeImpl;
144 public Boolean IsSpecialName
148 return (Attributes & FieldAttributes.SpecialName) == FieldAttributes.SpecialName;
152 public Boolean IsNotSerialized
156 return (Attributes & FieldAttributes.NotSerialized) == FieldAttributes.NotSerialized;
160 public CustomAttributeDataMirror[] GetCustomAttributes (bool inherit) {
161 return GetCAttrs (null, inherit);
164 public CustomAttributeDataMirror[] GetCustomAttributes (TypeMirror attributeType, bool inherit) {
165 if (attributeType == null)
166 throw new ArgumentNullException ("attributeType");
167 return GetCAttrs (attributeType, inherit);
170 public C.FieldDefinition Metadata {
172 if (parent.Metadata == null)
174 // FIXME: Speed this up
175 foreach (var fd in parent.Metadata.Fields) {
176 if (fd.Name == Name) {
182 /* Shouldn't happen */
183 throw new NotImplementedException ();
188 CustomAttributeDataMirror[] GetCAttrs (TypeMirror type, bool inherit) {
189 if (cattrs == null && Metadata != null && !Metadata.HasCustomAttributes)
190 cattrs = new CustomAttributeDataMirror [0];
192 // FIXME: Handle inherit
193 if (cattrs == null) {
194 CattrInfo[] info = vm.conn.Type_GetFieldCustomAttributes (DeclaringType.Id, id, 0, false);
195 cattrs = CustomAttributeDataMirror.Create (vm, info);
197 var res = new List<CustomAttributeDataMirror> ();
198 foreach (var attr in cattrs)
199 if (type == null || attr.Constructor.DeclaringType == type)
201 return res.ToArray ();