AsmResolver.Tests.Net.TypeSignatureTests.CreateGenericInstanceFieldReflection C# (CSharp) 메소드

CreateGenericInstanceFieldReflection() 개인적인 메소드

private CreateGenericInstanceFieldReflection ( ) : void
리턴 void
        public void CreateGenericInstanceFieldReflection()
        {
            // set up temp assembly.
            var assembly = Utilities.CreateTempNetAssembly();
            var tableStream = assembly.NetDirectory.MetadataHeader.GetStream<TableStream>();
            var fieldTable = tableStream.GetTable<FieldDefinition>();
            var importer = new ReferenceImporter(tableStream);

            // create field.
            var typeSignature = (GenericInstanceTypeSignature)importer.ImportTypeSignature(typeof(List<string>));
            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(GenericInstanceTypeSignature));
            var newTypeSignature = (GenericInstanceTypeSignature)field.Signature.FieldType;
            Utilities.ValidateType(typeSignature.GenericType, newTypeSignature.GenericType);
            Assert.AreEqual(typeSignature.GenericArguments.Count, newTypeSignature.GenericArguments.Count);
            for (int i = 0; i < typeSignature.GenericArguments.Count; i++)
                Assert.AreEqual(typeSignature.GenericArguments[i].FullName,
                    newTypeSignature.GenericArguments[i].FullName);
        }