Example #1
0
        public IUnresolvedField ReadField(FieldInfo field, IUnresolvedTypeDefinition parentType)
        {
            if (field == null)
                throw new ArgumentNullException("field");
            if (parentType == null)
                throw new ArgumentNullException("parentType");
            var f = new DefaultUnresolvedField(parentType, field.Name);
            f.Accessibility = GetAccessibility(field.Attributes);
            f.IsReadOnly = field.IsInitOnly;
            f.IsStatic = field.IsStatic;

            f.ReturnType = ReadTypeReference(field.FieldType, typeAttributes: field.CustomAttributes);

            if (field.Attributes.HasFlag (FieldAttributes.HasDefault)) {
                f.ConstantValue = CreateSimpleConstantValue(f.ReturnType, field.GetRawConstantValue ());
            }
            else {
                var decConstant = field.CustomAttributes.FirstOrDefault(a => a.AttributeType.FullName == "System.Runtime.CompilerServices.DecimalConstantAttribute");
                if (decConstant != null) {
                    var constValue = TryDecodeDecimalConstantAttribute(decConstant);
                    if (constValue != null)
                        f.ConstantValue = CreateSimpleConstantValue(f.ReturnType, constValue);
                }
            }
            AddAttributes(field, f);

            if (field.GetRequiredCustomModifiers ().Any (mt => mt.FullName == typeof(IsVolatile).FullName)) {
                f.IsVolatile = true;
            }

            FinishReadMember(f, field);
            return f;
        }