Example #1
0
        private void InitializeFieldDefinition(Cts.FieldDesc entity, Field record)
        {
            record.Name      = HandleString(entity.Name);
            record.Signature = new FieldSignature
            {
                Type = HandleType(entity.FieldType),
                // TODO: CustomModifiers
            };
            record.Flags = GetFieldAttributes(entity);

            var ecmaField = entity as Cts.Ecma.EcmaField;

            if (ecmaField != null)
            {
                Ecma.MetadataReader  reader             = ecmaField.MetadataReader;
                Ecma.FieldDefinition fieldDef           = reader.GetFieldDefinition(ecmaField.Handle);
                Ecma.ConstantHandle  defaultValueHandle = fieldDef.GetDefaultValue();
                if (!defaultValueHandle.IsNil)
                {
                    record.DefaultValue = HandleConstant(ecmaField.Module, defaultValueHandle);
                }

                Ecma.CustomAttributeHandleCollection customAttributes = fieldDef.GetCustomAttributes();
                if (customAttributes.Count > 0)
                {
                    record.CustomAttributes = HandleCustomAttributes(ecmaField.Module, customAttributes);
                }
            }

            // TODO: Offset
        }
 internal ImportedField(ImportedModule module, FieldDefinition fieldDef, ImportedType declaringType)
     : base(module, fieldDef.Name, declaringType)
 {
     _fieldDef = fieldDef;
 }
        private bool IsPubliclyVisible(MetadataReader referenceMetadata, FieldDefinition fieldDefinition, bool checkDeclaringType = false)
        {
            switch (fieldDefinition.Attributes & FieldAttributes.FieldAccessMask)
            {
            case FieldAttributes.Public:
            case FieldAttributes.Family:
            case FieldAttributes.FamORAssem:
                break;

            case FieldAttributes.FamANDAssem:
            case FieldAttributes.Assembly:
            case FieldAttributes.Private:
            case FieldAttributes.PrivateScope:
            default:
                return false;
            }

            if (checkDeclaringType)
            {
                TypeDefinition declaringTypeDefinition = referenceMetadata.GetTypeDefinition(fieldDefinition.GetDeclaringType());
                if (!IsPubliclyVisible(referenceMetadata, declaringTypeDefinition))
                    return false;
            }

            return true;
        }
 public static FieldSignature GetSignature(this MetadataReader metadataReader, FieldDefinition fieldDefinition)
 {
     return new FieldSignature(metadataReader.GetBlobReader(fieldDefinition.Signature));
 }
 private string GetMetadataName(MetadataReader metadataReader, FieldDefinition fieldDefinition)
 {
     TypeDefinition declaringTypeDefinition = metadataReader.GetTypeDefinition(fieldDefinition.GetDeclaringType());
     string typeName = GetMetadataName(metadataReader, declaringTypeDefinition);
     string fieldName = metadataReader.GetString(fieldDefinition.Name);
     return string.Format("{0}.{1}", typeName, fieldName);
 }