예제 #1
0
        public void CreateRequiredModifierField()
        {
            // set up temp assembly.
            var assembly    = Utilities.CreateTempNetAssembly();
            var typeSystem  = assembly.NetDirectory.MetadataHeader.TypeSystem;
            var tableStream = assembly.NetDirectory.MetadataHeader.GetStream <TableStream>();
            var fieldTable  = tableStream.GetTable <FieldDefinition>();
            var importer    = new ReferenceImporter(tableStream);

            // create field.
            var typeSignature = new RequiredModifierSignature(importer.ImportType(typeof(IsVolatile)), typeSystem.Int32);
            var field         = new FieldDefinition(FieldName, FieldAttributes.Public | FieldAttributes.Static,
                                                    new FieldSignature(typeSignature));

            fieldTable.Add(field);

            // build and validate.
            assembly   = Utilities.RebuildNetAssembly(assembly);
            fieldTable = assembly.NetDirectory.MetadataHeader.GetStream <TableStream>().GetTable <FieldDefinition>();
            field      = fieldTable.First(x => x.Name == FieldName);

            Assert.IsInstanceOfType(field.Signature.FieldType, typeof(RequiredModifierSignature));
            var newTypeSignature = (RequiredModifierSignature)field.Signature.FieldType;

            Utilities.ValidateType(typeSignature.ModifierType, newTypeSignature.ModifierType);
            Utilities.ValidateType(typeSignature.BaseType, newTypeSignature.BaseType);
        }
예제 #2
0
        public void ImportRequiredModifierType()
        {
            var baseType     = CreateTypeDefOrRef(typeof(Form));
            var modifierType = CreateTypeReference(typeof(IsVolatile));
            var modOptType   = new RequiredModifierSignature(modifierType, baseType);
            var newType      = TestTypeSpecification(modOptType, baseType.Type);

            Assert.NotSame(modifierType, newType.ModifierType);
        }
예제 #3
0
        /// <summary>
        /// Determines whether two types are considered equal according to their signature.
        /// </summary>
        /// <param name="signature1">The first type to compare.</param>
        /// <param name="signature2">The second type to compare.</param>
        /// <returns><c>True</c> if the types are considered equal, <c>False</c> otherwise.</returns>
        public bool Equals(RequiredModifierSignature signature1, RequiredModifierSignature signature2)
        {
            if (signature1 == null && signature2 == null)
            {
                return(true);
            }
            if (signature1 == null || signature2 == null)
            {
                return(false);
            }

            return(Equals(signature1.ModifierType, signature2.ModifierType) &&
                   Equals(signature1.BaseType, signature2.BaseType));
        }
예제 #4
0
 private RequiredModifierSignature ImportRequiredModifierSignature(RequiredModifierSignature modReqType)
 {
     return(new RequiredModifierSignature(ImportType(modReqType.ModifierType),
                                          ImportTypeSignature(modReqType.BaseType)));
 }