Make TypeBuilder.CreateType return non nullable (#72180)
authorJosie Bigler <34112636+JosieBigler@users.noreply.github.com>
Tue, 26 Jul 2022 22:33:45 +0000 (17:33 -0500)
committerGitHub <noreply@github.com>
Tue, 26 Jul 2022 22:33:45 +0000 (15:33 -0700)
* Make TypeBuilder.CreateType return non nullable

There is no situation when TypeBuilder.CreateType will return null when
being called by user-code.

issue #68840

* Update tests for null check after module.CreateGlobalFunctions()

* Check not null for additional CreateType Unit Tests

* Remove ! from DispatchProxyGenerator CreateType()

* Update Ref for non-null CreateType

* Change CreateTypeInfo to return non-null.

* Refactored CreateTypeInfo().AsType() to be CreateType()

* Annotate failing Mono Assert.Null

72 files changed:
src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/EnumBuilder.cs
src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.cs
src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.cs
src/libraries/Common/src/System/Reflection/Emit/IgnoreAccessChecksToAttributeBuilder.cs
src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/DelegateHelpers.cs
src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationILGen.cs
src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationReaderILGen.cs
src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationWriterILGen.cs
src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlILModule.cs
src/libraries/System.Reflection.DispatchProxy/src/System/Reflection/DispatchProxyGenerator.cs
src/libraries/System.Reflection.Emit.ILGeneration/tests/CustomAttributeBuilderTests.cs
src/libraries/System.Reflection.Emit.ILGeneration/tests/ILGenerator/Emit1Tests.cs
src/libraries/System.Reflection.Emit.ILGeneration/tests/ILGenerator/Emit3Tests.cs
src/libraries/System.Reflection.Emit.ILGeneration/tests/ILGenerator/Emit5Tests.cs
src/libraries/System.Reflection.Emit.ILGeneration/tests/ILGenerator/EmitWriteLineTests.cs
src/libraries/System.Reflection.Emit.ILGeneration/tests/ILGenerator/ExceptionEmitTests.cs
src/libraries/System.Reflection.Emit.ILGeneration/tests/ParameterBuilder/SetCustomAttributeTests.cs
src/libraries/System.Reflection.Emit/ref/System.Reflection.Emit.cs
src/libraries/System.Reflection.Emit/tests/ConstructorBuilder/ConstructorBuilderDefineParameter.cs
src/libraries/System.Reflection.Emit/tests/ConstructorBuilder/ConstructorBuilderSetCustomAttribute.cs
src/libraries/System.Reflection.Emit/tests/ConstructorBuilder/ConstructorBuilderSetImplementationFlags.cs
src/libraries/System.Reflection.Emit/tests/EnumBuilder/EnumBuilder.Methods.Tests.cs
src/libraries/System.Reflection.Emit/tests/EnumBuilder/EnumBuilder.Properties.Tests.cs
src/libraries/System.Reflection.Emit/tests/EventBuilder/EventBuilderAddOtherMethod.cs
src/libraries/System.Reflection.Emit/tests/EventBuilder/EventBuilderSetAddOnMethod.cs
src/libraries/System.Reflection.Emit/tests/EventBuilder/EventBuilderSetCustomAttribute.cs
src/libraries/System.Reflection.Emit/tests/EventBuilder/EventBuilderSetRaiseMethod.cs
src/libraries/System.Reflection.Emit/tests/EventBuilder/EventBuilderSetRemoveOnMethod.cs
src/libraries/System.Reflection.Emit/tests/FieldBuilder/FieldBuilderSetConstant.cs
src/libraries/System.Reflection.Emit/tests/FieldBuilder/FieldBuilderSetCustomAttribute.cs
src/libraries/System.Reflection.Emit/tests/FieldBuilder/FieldBuilderSetOffset.cs
src/libraries/System.Reflection.Emit/tests/GenericTypeParameterBuilder/GenericTypeParameterBuilderSetInterfaceConstraints.cs
src/libraries/System.Reflection.Emit/tests/MethodBuilder/MethodBuilderDefineGenericParameters.cs
src/libraries/System.Reflection.Emit/tests/MethodBuilder/MethodBuilderDefineParameter.cs
src/libraries/System.Reflection.Emit/tests/MethodBuilder/MethodBuilderGetILGenerator.cs
src/libraries/System.Reflection.Emit/tests/MethodBuilder/MethodBuilderReturnParameter.cs
src/libraries/System.Reflection.Emit/tests/MethodBuilder/MethodBuilderSetCustomAttribute.cs
src/libraries/System.Reflection.Emit/tests/MethodBuilder/MethodBuilderSetImplementationFlags.cs
src/libraries/System.Reflection.Emit/tests/MethodBuilder/MethodBuilderSetParameters.cs
src/libraries/System.Reflection.Emit/tests/MethodBuilder/MethodBuilderSetReturnType.cs
src/libraries/System.Reflection.Emit/tests/MethodBuilder/MethodBuilderSetSignature.cs
src/libraries/System.Reflection.Emit/tests/ModuleBuilder/ModuleBuilderCreateGlobalFunctions.cs
src/libraries/System.Reflection.Emit/tests/ModuleBuilder/ModuleBuilderDefineEnum.cs
src/libraries/System.Reflection.Emit/tests/ModuleBuilder/ModuleBuilderDefineInitializedData.cs
src/libraries/System.Reflection.Emit/tests/ModuleBuilder/ModuleBuilderDefineType.cs
src/libraries/System.Reflection.Emit/tests/ParameterBuilder/ParameterBuilderSetConstant.cs
src/libraries/System.Reflection.Emit/tests/PropertyBuilder/PropertyBuilderAddOtherMethod.cs
src/libraries/System.Reflection.Emit/tests/PropertyBuilder/PropertyBuilderGetIndexParameters.cs
src/libraries/System.Reflection.Emit/tests/PropertyBuilder/PropertyBuilderGetValue.cs
src/libraries/System.Reflection.Emit/tests/PropertyBuilder/PropertyBuilderSetConstant.cs
src/libraries/System.Reflection.Emit/tests/PropertyBuilder/PropertyBuilderSetCustomAttribute.cs
src/libraries/System.Reflection.Emit/tests/PropertyBuilder/PropertyBuilderSetGetMethod.cs
src/libraries/System.Reflection.Emit/tests/PropertyBuilder/PropertyBuilderSetSetMethod.cs
src/libraries/System.Reflection.Emit/tests/PropertyBuilder/PropertyBuilderSetValue.cs
src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderAddInterfaceImplementation.cs
src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderCreateType.cs
src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderCreateTypeInfo.cs
src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderDefineConstructor.cs
src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderDefineDefaultConstructor.cs
src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderDefineEvent.cs
src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderDefineField.cs
src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderDefineMethodOverride.cs
src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderDefineProperty.cs
src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderDefineTypeInitializer.cs
src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderGUID.cs
src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderIsGenericTypeDefinition.cs
src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderSetCustomAttribute.cs
src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderSetParent.cs
src/libraries/System.Reflection.Emit/tests/Utilities.cs
src/libraries/System.Runtime.Loader/tests/System.Runtime.Loader.Noop.Assembly/TestClass.cs
src/libraries/System.Runtime/tests/System/EnumTests.cs
src/tests/reflection/RefEmit/EmittingIgnoresAccessChecksToAttributeIsRespected.cs

index 1368665..0ed9ab0 100644 (file)
@@ -39,14 +39,14 @@ namespace System.Reflection.Emit
         }
 
         [return: DynamicallyAccessedMembersAttribute(DynamicallyAccessedMemberTypes.All)]
-        public TypeInfo? CreateTypeInfo()
+        public TypeInfo CreateTypeInfo()
         {
             return m_typeBuilder.CreateTypeInfo();
         }
 
         // CreateType cause EnumBuilder to be baked.
         [return: DynamicallyAccessedMembersAttribute(DynamicallyAccessedMemberTypes.All)]
-        public Type? CreateType()
+        public Type CreateType()
         {
             return m_typeBuilder.CreateType();
         }
index a076bf3..40025b0 100644 (file)
@@ -852,7 +852,7 @@ namespace System.Reflection.Emit
                 // cannot create globals twice
                 throw new InvalidOperationException(SR.InvalidOperation_NotADebugModule);
             }
-            _globalTypeBuilder.CreateType();
+            _globalTypeBuilder.CreateTypeInfoImpl();
             _hasGlobalBeenCreated = true;
         }
 
index 2430d32..088d22b 100644 (file)
@@ -1677,16 +1677,23 @@ namespace System.Reflection.Emit
         #region Create Type
 
         [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
-        public TypeInfo? CreateTypeInfo()
+        public TypeInfo CreateTypeInfo()
         {
-            lock (SyncRoot)
-            {
-                return CreateTypeNoLock();
-            }
+            TypeInfo? typeInfo = CreateTypeInfoImpl();
+            Debug.Assert(typeInfo != null);
+            return typeInfo;
+        }
+
+        [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
+        public Type CreateType()
+        {
+            Type? type = CreateTypeInfoImpl();
+            Debug.Assert(type != null);
+            return type;
         }
 
         [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
-        public Type? CreateType()
+        internal TypeInfo? CreateTypeInfoImpl()
         {
             lock (SyncRoot)
             {
index dac3584..6d258b1 100644 (file)
@@ -95,7 +95,7 @@ namespace System.Reflection.Emit
             attributeTypeBuilder.SetCustomAttribute(customAttributeBuilder);
 
             // Make the TypeInfo real so the constructor can be used.
-            return attributeTypeBuilder.CreateTypeInfo()!.DeclaredConstructors.Single();
+            return attributeTypeBuilder.CreateTypeInfo().DeclaredConstructors.Single();
         }
     }
 }
index ced4a20..af9f48f 100644 (file)
@@ -122,7 +122,7 @@ namespace System.Linq.Expressions.Compiler
                 TypeBuilder builder = AssemblyGen.DefineDelegateType("Delegate" + types.Length);
                 builder.DefineConstructor(ctorAttributes, CallingConventions.Standard, delegateCtorSignature).SetImplementationFlags(implAttributes);
                 builder.DefineMethod("Invoke", invokeAttributes, returnType, parameters).SetImplementationFlags(implAttributes);
-                return builder.CreateTypeInfo()!;
+                return builder.CreateTypeInfo();
             }
             else
             {
index a459338..b57ac4b 100644 (file)
@@ -299,7 +299,7 @@ namespace System.Xml.Serialization
 
             baseSerializerTypeBuilder.DefineDefaultConstructor(
                 MethodAttributes.Family | MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName);
-            Type baseSerializerType = baseSerializerTypeBuilder.CreateTypeInfo()!.AsType();
+            Type baseSerializerType = baseSerializerTypeBuilder.CreateType();
             CreatedTypes.Add(baseSerializerType.Name, baseSerializerType);
 
             return baseSerializer;
@@ -396,7 +396,7 @@ namespace System.Xml.Serialization
                 ilg.EndMethod();
             }
             typedSerializerTypeBuilder.DefineDefaultConstructor(CodeGenerator.PublicMethodAttributes);
-            Type typedSerializerType = typedSerializerTypeBuilder.CreateTypeInfo()!.AsType();
+            Type typedSerializerType = typedSerializerTypeBuilder.CreateType();
             CreatedTypes.Add(typedSerializerType.Name, typedSerializerType);
 
             return typedSerializerType.Name;
@@ -558,7 +558,7 @@ namespace System.Xml.Serialization
             ilg.Call(baseCtor);
             ilg.EndMethod();
             // Instantiate type
-            Type serializerContractType = serializerContractTypeBuilder.CreateTypeInfo()!.AsType();
+            Type serializerContractType = serializerContractTypeBuilder.CreateType();
             CreatedTypes.Add(serializerContractType.Name, serializerContractType);
         }
 
index 56d8bd2..0e2fc04 100644 (file)
@@ -255,7 +255,7 @@ namespace System.Xml.Serialization
 
             this.typeBuilder.DefineDefaultConstructor(
                 CodeGenerator.PublicMethodAttributes);
-            Type readerType = this.typeBuilder.CreateTypeInfo()!.AsType();
+            Type readerType = this.typeBuilder.CreateType();
             CreatedTypes.Add(readerType.Name, readerType);
         }
 
index a090d23..1e74f84 100644 (file)
@@ -68,7 +68,7 @@ namespace System.Xml.Serialization
             GenerateInitCallbacksMethod();
             this.typeBuilder.DefineDefaultConstructor(
                 CodeGenerator.PublicMethodAttributes);
-            return this.typeBuilder.CreateTypeInfo()!.AsType();
+            return this.typeBuilder.CreateType();
         }
 
         [RequiresUnreferencedCode("calls GenerateTypeElement")]
index 74ea022..17b6909 100644 (file)
@@ -239,7 +239,7 @@ namespace System.Xml.Xsl.IlGen
 
             if (!_useLRE)
             {
-                typBaked = _typeBldr!.CreateTypeInfo()!.AsType();
+                typBaked = _typeBldr!.CreateType();
 
                 // Replace all MethodInfos in this.methods
                 methodsBaked = new Hashtable(_methods.Count);
index ed5b976..c3210fe 100644 (file)
@@ -309,7 +309,7 @@ namespace System.Reflection
             internal GeneratedTypeInfo CreateType()
             {
                 this.Complete();
-                return new GeneratedTypeInfo(_tb.CreateType()!, _methodInfos.ToArray());
+                return new GeneratedTypeInfo(_tb.CreateType(), _methodInfos.ToArray());
             }
 
             internal void AddInterfaceImpl([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type iface)
index 9b170d6..60e3199 100644 (file)
@@ -422,7 +422,7 @@ namespace System.Reflection.Emit.Tests
             setMethodGenerator.Emit(OpCodes.Ret);
             propertyBuilder.SetSetMethod(setMethod);
 
-            Type createdType = typeBuilder.CreateTypeInfo().AsType();
+            Type createdType = typeBuilder.CreateType();
 
             // ConstructorBuilder, PropertyInfo, FieldInfo
             yield return new object[]
@@ -555,7 +555,7 @@ namespace System.Reflection.Emit.Tests
             ConstructorBuilder constructorBuilder = typeBuilder.DefineConstructor(MethodAttributes.Public, callingConvention, new Type[0]);
             constructorBuilder.GetILGenerator().Emit(OpCodes.Ret);
 
-            ConstructorInfo con = typeBuilder.CreateTypeInfo().AsType().GetConstructor(new Type[0]);
+            ConstructorInfo con = typeBuilder.CreateType().GetConstructor(new Type[0]);
 
             AssertExtensions.Throws<ArgumentException>(null, () => new CustomAttributeBuilder(con, new object[0]));
             AssertExtensions.Throws<ArgumentException>(null, () => new CustomAttributeBuilder(con, new object[0], new FieldInfo[0], new object[0]));
@@ -1068,7 +1068,7 @@ namespace System.Reflection.Emit.Tests
             {
                 enumBuilder.DefineLiteral("Value" + i, literalValues[i]);
             }
-            return enumBuilder.CreateTypeInfo().AsType();
+            return enumBuilder.CreateType();
         }
     }
 
index c7bfc39..8b92a1d 100644 (file)
@@ -22,7 +22,7 @@ namespace System.Reflection.Emit.Tests
             ilgen.Emit(OpCodes.Ret);
 
             // Create the type where this method is in
-            Type createdType1 = type.CreateTypeInfo().AsType();
+            Type createdType1 = type.CreateType();
             MethodInfo createdMethod1 = createdType1.GetMethod("meth1");
 
             TypeBuilder type2 = module.DefineType("C2", TypeAttributes.Public);
@@ -35,7 +35,7 @@ namespace System.Reflection.Emit.Tests
             ilgen2.Emit(OpCodes.Ret);
 
             // Create the type whose method will be invoking the MethodInfo method
-            Type createdType2 = type2.CreateTypeInfo().AsType();
+            Type createdType2 = type2.CreateType();
             MethodInfo createdMethod2 = createdType2.GetMethod("meth2");
 
             // meth2 should invoke meth1 which should return value from meth1
@@ -56,7 +56,7 @@ namespace System.Reflection.Emit.Tests
             ilGenerator1.Emit(OpCodes.Ret);
 
             // Create the type where this method is in
-            Type createdType1 = type1.CreateTypeInfo().AsType();
+            Type createdType1 = type1.CreateType();
             MethodInfo createdMethod1 = createdType1.GetMethod("meth1");
 
             TypeBuilder type2 = module.DefineType("C2", TypeAttributes.Public);
@@ -69,7 +69,7 @@ namespace System.Reflection.Emit.Tests
             ilGenerator2.Emit(OpCodes.Ret);
 
             // Create the type whose method will be invoking the MethodInfo method
-            Type createdType2 = type2.CreateTypeInfo().AsType();
+            Type createdType2 = type2.CreateType();
             MethodInfo createdMethod2 = createdType2.GetMethod("meth2");
 
             // meth2 should invoke meth1 which should return value 'methodRet'
@@ -93,7 +93,7 @@ namespace System.Reflection.Emit.Tests
             ilGenerator.Emit(OpCodes.Ret);
 
             // Create the type where this method is in
-            Type createdType1 = type1.CreateTypeInfo().AsType();
+            Type createdType1 = type1.CreateType();
             MethodInfo createdMethod1 = createdType1.GetMethod("meth1");
             MethodInfo genericMethod = createdMethod1.MakeGenericMethod(typeof(int));
 
@@ -107,7 +107,7 @@ namespace System.Reflection.Emit.Tests
             ilGenerator2.Emit(OpCodes.Ret);
 
             // Create the type whose method will be invoking the MethodInfo method
-            Type createdType2 = type2.CreateTypeInfo().AsType();
+            Type createdType2 = type2.CreateType();
             MethodInfo createdMethod2 = createdType2.GetMethod("meth2");
 
             // meth2 should invoke meth1 which should return value 'methodRet'
@@ -131,7 +131,7 @@ namespace System.Reflection.Emit.Tests
             ilGenerator1.Emit(OpCodes.Ret);
 
             // Create the type where this method is in
-            Type createdType1 = type1.CreateTypeInfo().AsType();
+            Type createdType1 = type1.CreateType();
             Type genericType = createdType1.MakeGenericType(typeof(int));
             MethodInfo genericMethod = genericType.GetMethod("meth1");
 
@@ -145,7 +145,7 @@ namespace System.Reflection.Emit.Tests
             ilGenerator2.Emit(OpCodes.Ret);
 
             // Create the type whose method will be invoking the MethodInfo method
-            Type createdType2 = type2.CreateTypeInfo().AsType();
+            Type createdType2 = type2.CreateType();
             MethodInfo createdMethod2 = createdType2.GetMethod("meth2");
 
             // meth2 should invoke meth1 which should return value 'methodRet'
@@ -170,7 +170,7 @@ namespace System.Reflection.Emit.Tests
             ilGenerator1.Emit(OpCodes.Ret);
 
             // create the type where this method is in
-            Type createdType1 = type1.CreateTypeInfo().AsType();
+            Type createdType1 = type1.CreateType();
             Type genericType = createdType1.MakeGenericType(typeof(int));
             MethodInfo createdMethod1 = genericType.GetMethod("meth1");
             MethodInfo genericMethod = createdMethod1.MakeGenericMethod(typeof(string));
@@ -185,7 +185,7 @@ namespace System.Reflection.Emit.Tests
             ilGenerator2.Emit(OpCodes.Ret);
 
             // Create the type whose method will be invoking the MethodInfo method
-            Type createdType2 = type2.CreateTypeInfo().AsType();
+            Type createdType2 = type2.CreateType();
             MethodInfo createdMethod2 = createdType2.GetMethod("meth2");
 
             // meth2 should invoke meth1 which should return value 'methodRet'
index 2a1d4e9..f3ceecb 100644 (file)
@@ -81,7 +81,7 @@ namespace System.Reflection.Emit.Tests
             ilGenerator.Emit(OpCodes.Ret);
 
             // Create the type where this method is in
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
             MethodInfo createdMethod = createdType.GetMethod("meth1");
 
             Assert.True((bool)createdMethod.Invoke(null, null));
@@ -105,7 +105,7 @@ namespace System.Reflection.Emit.Tests
             ilGenerator.Emit(OpCodes.Ret);
 
             // Create the type where this method is in
-            Type createdType = tb.CreateTypeInfo().AsType();
+            Type createdType = tb.CreateType();
             MethodInfo createdMethod = createdType.GetMethod("meth1");
 
             Assert.True((bool)createdMethod.Invoke(null, null));
@@ -126,7 +126,7 @@ namespace System.Reflection.Emit.Tests
             ilGenerator.Emit(OpCodes.Ret);
 
             // create the type where this method is in
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
             MethodInfo createdMethod = createdType.GetMethod("meth1");
 
             Assert.True((bool)createdMethod.Invoke(null, null));
@@ -205,7 +205,7 @@ namespace System.Reflection.Emit.Tests
             ilGenerator.Emit(OpCodes.Ret);
 
             // Create the type where this method is in
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
             MethodInfo createdMethod = createdType.GetMethod("meth1");
 
             Assert.True((bool)createdMethod.Invoke(null, null));
index 7a11fd4..1ff3baf 100644 (file)
@@ -69,7 +69,7 @@ namespace System.Reflection.Emit.Tests
                 ilg.Emit(OpCodes.Ret);
 
                 // Create the type where this method is in
-                Type createdType = type.CreateTypeInfo().AsType();
+                Type createdType = type.CreateType();
                 MethodInfo createdMethod = createdType.GetMethod("meth1");
 
                 return createdMethod;
@@ -135,7 +135,7 @@ namespace System.Reflection.Emit.Tests
                 ilg.Emit(OpCodes.Ret);
 
                 // Create the type where this method is in
-                Type createdType = type.CreateTypeInfo().AsType();
+                Type createdType = type.CreateType();
                 return createdType.GetMethod("meth1");
             }
         }
@@ -209,7 +209,7 @@ namespace System.Reflection.Emit.Tests
                 ilg.Emit(OpCodes.Ret);
 
                 // Create the type where this method is in
-                Type createdType = type.CreateTypeInfo().AsType();
+                Type createdType = type.CreateType();
                 return createdType.GetMethod("meth1");
             }
         }
@@ -256,7 +256,7 @@ namespace System.Reflection.Emit.Tests
                 ilg.Emit(OpCodes.Ret);
 
                 // Create the type where this method is in
-                Type createdType = type.CreateTypeInfo().AsType();
+                Type createdType = type.CreateType();
                 return createdType.GetMethod("meth1");
             }
         }
@@ -297,7 +297,7 @@ namespace System.Reflection.Emit.Tests
                 ilg.Emit(OpCodes.Ret);
 
                 // Create the type where this method is in
-                Type createdType = type.CreateTypeInfo().AsType();
+                Type createdType = type.CreateType();
                 return createdType.GetMethod("meth1");
             }
         }
index 392ecfd..c9017ff 100644 (file)
@@ -23,7 +23,7 @@ namespace System.Reflection.Emit.Tests
             ilGenerator1.Emit(OpCodes.Ret);
 
             // Create the type where this method is in
-            Type createdType1 = type1.CreateTypeInfo().AsType();
+            Type createdType1 = type1.CreateType();
             FieldInfo createdField = createdType1.GetField("field1");
 
             TypeBuilder type2 = module.DefineType("C2", TypeAttributes.Public);
@@ -39,7 +39,7 @@ namespace System.Reflection.Emit.Tests
             ilGenerator2.Emit(OpCodes.Ret);
 
             // Create the type whose method will be invoking the MethodInfo method
-            Type createdType2 = type2.CreateTypeInfo().AsType();
+            Type createdType2 = type2.CreateType();
             MethodInfo createdMethod = createdType2.GetMethod("meth2");
 
             // meth2 should invoke meth1 which should return value from meth1
index e99a27e..f12d211 100644 (file)
@@ -44,7 +44,7 @@ namespace System.Reflection.Emit.Tests
             ilGenerator.Emit(OpCodes.Ldloc_S, tmp1);
             ilGenerator.Emit(OpCodes.Ret);
 
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
             MethodInfo createdMethod = createdType.GetMethod("DoThrow");
 
             Assert.Equal(-1, createdMethod.Invoke(null, new object[] { true })); // Throws
index e1733c0..2309727 100644 (file)
@@ -24,7 +24,7 @@ namespace System.Reflection.Emit.Tests
 
             CustomAttributeBuilder attribute = new CustomAttributeBuilder(constructor, new object[] { 4 }, new FieldInfo[] { field }, new object[] { "hello" });
             parameter.SetCustomAttribute(attribute);
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
             MethodInfo createdMethod = createdType.GetMethod("method1");
             ParameterInfo createdParameter = createdMethod.GetParameters()[0];
 
@@ -46,7 +46,7 @@ namespace System.Reflection.Emit.Tests
             ilGenerator.Emit(OpCodes.Ret);
 
             parameter.SetCustomAttribute(typeof(ParameterBuilderCustomAttribute).GetConstructor(new Type[] { typeof(bool)}), new byte[] { 1, 0, 1, 0, 0});
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
             MethodInfo createdMethod = createdType.GetMethod("method1");
             ParameterInfo createdParameter = createdMethod.GetParameters()[0];
 
index fe1f97b..3a5a482 100644 (file)
@@ -109,9 +109,9 @@ namespace System.Reflection.Emit
         public System.Reflection.Emit.FieldBuilder UnderlyingField { get { throw null; } }
         public override System.Type UnderlyingSystemType { get { throw null; } }
         [return: System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)]
-        public System.Type? CreateType() { throw null; }
+        public System.Type CreateType() { throw null; }
         [return: System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)]
-        public System.Reflection.TypeInfo? CreateTypeInfo() { throw null; }
+        public System.Reflection.TypeInfo CreateTypeInfo() { throw null; }
         public System.Reflection.Emit.FieldBuilder DefineLiteral(string literalName, object? literalValue) { throw null; }
         protected override System.Reflection.TypeAttributes GetAttributeFlagsImpl() { throw null; }
         [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicConstructors | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)]
@@ -485,9 +485,9 @@ namespace System.Reflection.Emit
         public override System.Type UnderlyingSystemType { get { throw null; } }
         public void AddInterfaceImplementation([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)] System.Type interfaceType) { }
         [return: System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)]
-        public System.Type? CreateType() { throw null; }
+        public System.Type CreateType() { throw null; }
         [return: System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)]
-        public System.Reflection.TypeInfo? CreateTypeInfo() { throw null; }
+        public System.Reflection.TypeInfo CreateTypeInfo() { throw null; }
         public System.Reflection.Emit.ConstructorBuilder DefineConstructor(System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, System.Type[]? parameterTypes) { throw null; }
         public System.Reflection.Emit.ConstructorBuilder DefineConstructor(System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, System.Type[]? parameterTypes, System.Type[][]? requiredCustomModifiers, System.Type[][]? optionalCustomModifiers) { throw null; }
         public System.Reflection.Emit.ConstructorBuilder DefineDefaultConstructor(System.Reflection.MethodAttributes attributes) { throw null; }
index 132f6b9..20e3eeb 100644 (file)
@@ -37,7 +37,7 @@ namespace System.Reflection.Emit.Tests
                 ilGenerator.Emit(OpCodes.Call, typeof(object).GetConstructor(new Type[0]));
                 ilGenerator.Emit(OpCodes.Ret);
 
-                type.CreateTypeInfo().AsType();
+                type.CreateType();
 
                 ParameterInfo[] definedParams = constructor.GetParameters();
                 Assert.Equal(2, definedParams.Length);
@@ -61,7 +61,7 @@ namespace System.Reflection.Emit.Tests
                 ilGenerator.Emit(OpCodes.Call, typeof(object).GetConstructor(new Type[0]));
                 ilGenerator.Emit(OpCodes.Ret);
 
-                type.CreateTypeInfo().AsType();
+                type.CreateType();
 
                 ParameterInfo[] definedParams = constructor.GetParameters();
                 Assert.Equal(1, definedParams.Length);
@@ -85,7 +85,7 @@ namespace System.Reflection.Emit.Tests
                 ilGenerator.Emit(OpCodes.Call, typeof(object).GetConstructor(new Type[0]));
                 ilGenerator.Emit(OpCodes.Ret);
 
-                type.CreateTypeInfo().AsType();
+                type.CreateType();
 
                 ParameterInfo[] definedParams = constructor.GetParameters();
                 Assert.Equal(1, definedParams.Length);
@@ -110,7 +110,7 @@ namespace System.Reflection.Emit.Tests
                 ilGenerator.Emit(OpCodes.Call, typeof(object).GetConstructor(new Type[0]));
                 ilGenerator.Emit(OpCodes.Ret);
 
-                type.CreateTypeInfo().AsType();
+                type.CreateType();
 
                 ParameterInfo[] definedParams = constructor.GetParameters();
                 Assert.Equal(2, definedParams.Length);
@@ -159,7 +159,7 @@ namespace System.Reflection.Emit.Tests
             ConstructorBuilder constructor = type.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, new Type[] { typeof(int) });
 
             constructor.GetILGenerator().Emit(OpCodes.Ret);
-            type.CreateTypeInfo().AsType();
+            type.CreateType();
 
             Assert.Throws<InvalidOperationException>(() => constructor.DefineParameter(1, ParameterAttributes.None, "p"));
         }
index c44615d..1e3b1d5 100644 (file)
@@ -18,7 +18,7 @@ namespace System.Reflection.Emit.Tests
             constructor.SetCustomAttribute(attributeConstructor, new byte[] { 1, 0, 5, 0, 0, 0 });
             constructor.GetILGenerator().Emit(OpCodes.Ret);
 
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
             ConstructorInfo createdConstructor = createdType.GetConstructor(new Type[] { typeof(int) });
             Attribute[] attributes = createdConstructor.GetCustomAttributes().ToArray();
             IntAllAttribute attribute = Assert.IsType<IntAllAttribute>(attributes[0]);
@@ -45,7 +45,7 @@ namespace System.Reflection.Emit.Tests
             CustomAttributeBuilder attributeBuilder = new CustomAttributeBuilder(attributeConstructor, new object[] { 2 });
 
             constructor.SetCustomAttribute(attributeBuilder);
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
 
             ConstructorInfo createdConstructor = createdType.GetConstructor(new Type[0]);
             Attribute[] customAttributes = (Attribute[])CustomAttributeExtensions.GetCustomAttributes(createdConstructor, true).ToArray();
index 935f75d..40284d5 100644 (file)
@@ -34,7 +34,7 @@ namespace System.Reflection.Emit.Tests
             ConstructorBuilder constructor = type.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, new Type[0]);
             constructor.GetILGenerator().Emit(OpCodes.Ret);
 
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
             Assert.Throws<InvalidOperationException>(() => constructor.SetImplementationFlags(MethodImplAttributes.Runtime));
         }
     }
index 81d0f87..32133e7 100644 (file)
@@ -71,7 +71,7 @@ namespace System.Reflection.Emit.Tests
             Assert.Equal(enumBuilder.AsType(), literal.FieldType);
 
             Type createdEnum = useCreateTypeInfo ?
-                enumBuilder.CreateTypeInfo().AsType() :
+                enumBuilder.CreateType() :
                 enumBuilder.CreateType();
 
             FieldInfo createdLiteral = createdEnum.GetField("FieldOne");
@@ -234,7 +234,7 @@ namespace System.Reflection.Emit.Tests
         public void SetCustomAttribute_ConstructorInfo_ByteArray()
         {
             EnumBuilder enumBuilder = Helpers.DynamicEnum(TypeAttributes.Public, typeof(int));
-            enumBuilder.CreateTypeInfo().AsType();
+            enumBuilder.CreateType();
 
             ConstructorInfo attributeConstructor = typeof(BoolAttribute).GetConstructor(new Type[] { typeof(bool) });
             enumBuilder.SetCustomAttribute(attributeConstructor, new byte[] { 01, 00, 01 });
@@ -248,7 +248,7 @@ namespace System.Reflection.Emit.Tests
         public void SetCustomAttribute_CustomAttributeBuilder()
         {
             EnumBuilder enumBuilder = Helpers.DynamicEnum(TypeAttributes.Public, typeof(int));
-            enumBuilder.CreateTypeInfo().AsType();
+            enumBuilder.CreateType();
 
             ConstructorInfo attributeConstructor = typeof(BoolAttribute).GetConstructor(new Type[] { typeof(bool) });
             CustomAttributeBuilder attributeBuilder = new CustomAttributeBuilder(attributeConstructor, new object[] { true });
index 4c27d3c..0463667 100644 (file)
@@ -12,7 +12,7 @@ namespace System.Reflection.Emit.Tests
         public void Guid_TypeCreated()
         {
             EnumBuilder enumBuilder = Helpers.DynamicEnum(TypeAttributes.Public, typeof(int));
-            enumBuilder.CreateTypeInfo().AsType();
+            enumBuilder.CreateType();
             Assert.NotEqual(Guid.Empty, enumBuilder.GUID);
         }
 
index 79aa3e4..fdcf9e4 100644 (file)
@@ -89,7 +89,7 @@ namespace System.Reflection.Emit.Tests
             TypeBuilder type = Helpers.DynamicType(TypeAttributes.Abstract);
             EventBuilder eventBuilder = type.DefineEvent("TestEvent", EventAttributes.None, typeof(TestEventHandler));
             MethodBuilder method = type.DefineMethod("TestMethod", MethodAttributes.Abstract | MethodAttributes.Virtual);
-            type.CreateTypeInfo().AsType();
+            type.CreateType();
 
             Assert.Throws<InvalidOperationException>(() => eventBuilder.AddOtherMethod(method));
         }
index 2eb9605..4836e4a 100644 (file)
@@ -90,7 +90,7 @@ namespace System.Reflection.Emit.Tests
             TypeBuilder type = Helpers.DynamicType(TypeAttributes.Abstract);
             EventBuilder eventBuilder = type.DefineEvent("TestEvent", EventAttributes.None, typeof(TestEventHandler));
             MethodBuilder method = type.DefineMethod("TestMethod", MethodAttributes.Abstract | MethodAttributes.Virtual);
-            type.CreateTypeInfo().AsType();
+            type.CreateType();
 
             Assert.Throws<InvalidOperationException>(() => eventBuilder.SetAddOnMethod(method));
         }
index ae86bf4..d46062e 100644 (file)
@@ -46,7 +46,7 @@ namespace System.Reflection.Emit.Tests
             EventBuilder eventBuilder = type.DefineEvent("TestEvent", EventAttributes.None, typeof(TestEventHandler));
             ConstructorInfo attributeConstructor = typeof(EmptyAttribute).GetConstructor(new Type[0]);
             byte[] bytes = Enumerable.Range(0, 256).Select(i => (byte)i).ToArray();
-            type.CreateTypeInfo().AsType();
+            type.CreateType();
 
             Assert.Throws<InvalidOperationException>(() => eventBuilder.SetCustomAttribute(attributeConstructor, bytes));
         }
@@ -77,7 +77,7 @@ namespace System.Reflection.Emit.Tests
             EventBuilder eventBuilder = type.DefineEvent("TestEvent", EventAttributes.None, typeof(TestEventHandler));
             ConstructorInfo attributeConstructor = typeof(EmptyAttribute).GetConstructor(new Type[0]);
             CustomAttributeBuilder attribute = new CustomAttributeBuilder(attributeConstructor, new object[0]);
-            type.CreateTypeInfo().AsType();
+            type.CreateType();
 
             Assert.Throws<InvalidOperationException>(() => eventBuilder.SetCustomAttribute(attribute));
         }
index 80c701c..7456379 100644 (file)
@@ -89,7 +89,7 @@ namespace System.Reflection.Emit.Tests
             TypeBuilder type = Helpers.DynamicType(TypeAttributes.Abstract);
             EventBuilder eventBuilder = type.DefineEvent("TestEvent", EventAttributes.None, typeof(TestEventHandler));
             MethodBuilder method = type.DefineMethod("TestMethod", MethodAttributes.Abstract | MethodAttributes.Virtual);
-            type.CreateTypeInfo().AsType();
+            type.CreateType();
 
             Assert.Throws<InvalidOperationException>(() => eventBuilder.SetRaiseMethod(method));
         }
index 030b4e2..4183bcd 100644 (file)
@@ -90,7 +90,7 @@ namespace System.Reflection.Emit.Tests
             TypeBuilder type = Helpers.DynamicType(TypeAttributes.Abstract);
             EventBuilder eventBuilder = type.DefineEvent("TestEvent", EventAttributes.None, typeof(TestEventHandler));
             MethodBuilder method = type.DefineMethod("TestMethod", MethodAttributes.Abstract | MethodAttributes.Virtual);
-            type.CreateTypeInfo().AsType();
+            type.CreateType();
 
             Assert.Throws<InvalidOperationException>(() => { eventBuilder.SetRemoveOnMethod(method); });
         }
index 7a7e39b..bc2a435 100644 (file)
@@ -179,7 +179,7 @@ namespace System.Reflection.Emit.Tests
             TypeBuilder type = Helpers.DynamicType(TypeAttributes.Abstract);
             FieldBuilder field = type.DefineField("Field_NegTest1", typeof(int), FieldAttributes.Public);
 
-            type.CreateTypeInfo().AsType();
+            type.CreateType();
 
             Assert.Throws<InvalidOperationException>(() => field.SetConstant(0));
         }
index 71df5c4..abe02c4 100644 (file)
@@ -43,7 +43,7 @@ namespace System.Reflection.Emit.Tests
             FieldBuilder field = type.DefineField("TestField", typeof(object), FieldAttributes.Public);
             ConstructorInfo attributeConstructor = typeof(EmptyAttribute).GetConstructor(new Type[0]);
             byte[] bytes = Enumerable.Range(0, 256).Select(i => (byte)i).ToArray();
-            type.CreateTypeInfo().AsType();
+            type.CreateType();
 
             Assert.Throws<InvalidOperationException>(() => field.SetCustomAttribute(attributeConstructor, bytes));
         }
@@ -74,7 +74,7 @@ namespace System.Reflection.Emit.Tests
             FieldBuilder field = type.DefineField("TestField", typeof(object), FieldAttributes.Public);
             ConstructorInfo con = typeof(EmptyAttribute).GetConstructor(new Type[0]);
             CustomAttributeBuilder attribute = new CustomAttributeBuilder(con, new object[0]);
-            type.CreateTypeInfo().AsType();
+            type.CreateType();
 
             Assert.Throws<InvalidOperationException>(() => { field.SetCustomAttribute(attribute); });
         }
index 8275d4f..7014325 100644 (file)
@@ -51,7 +51,7 @@ namespace System.Reflection.Emit.Tests
         {
             TypeBuilder type = Helpers.DynamicType(TypeAttributes.Abstract);
             FieldBuilder field = type.DefineField("TestField", typeof(int), FieldAttributes.Public);
-            type.CreateTypeInfo().AsType();
+            type.CreateType();
 
             Assert.Throws<InvalidOperationException>(() => field.SetOffset(0));
         }
index 1aa3c2a..ed0bc7b 100644 (file)
@@ -16,7 +16,7 @@ namespace System.Reflection.Emit.Tests
             GenericTypeParameterBuilder[] typeParams = type.DefineGenericParameters(typeParamNames);
 
             typeParams[0].SetInterfaceConstraints(typeof(EmptyNonGenericInterface1));
-            Type resultType = type.CreateTypeInfo().AsType();
+            Type resultType = type.CreateType();
             Type[] genericTypeParams = resultType.GetGenericArguments();
 
             Assert.Equal(1, genericTypeParams.Length);
@@ -31,7 +31,7 @@ namespace System.Reflection.Emit.Tests
             GenericTypeParameterBuilder[] typeParams = type.DefineGenericParameters(typeParamNames);
 
             typeParams[0].SetInterfaceConstraints(null);
-            Type resultType = type.CreateTypeInfo().AsType();
+            Type resultType = type.CreateType();
             Type[] genericTypeParams = resultType.GetGenericArguments();
 
             Assert.Equal(1, genericTypeParams.Length);
@@ -47,7 +47,7 @@ namespace System.Reflection.Emit.Tests
             GenericTypeParameterBuilder[] typeParams = type.DefineGenericParameters(typeParamNames);
 
             typeParams[0].SetInterfaceConstraints(new Type[] { typeof(EmptyNonGenericInterface1), typeof(EmptyNonGenericInterface2) });
-            Type resultType = type.CreateTypeInfo().AsType();
+            Type resultType = type.CreateType();
             Type[] genericTypeParams = resultType.GetGenericArguments();
 
             Assert.Equal(1, genericTypeParams.Length);
index 147659f..7b47b9e 100644 (file)
@@ -47,7 +47,7 @@ namespace System.Reflection.Emit.Tests
             ilGenerator.Emit(OpCodes.Ldc_I4, 100);
             ilGenerator.Emit(OpCodes.Ret);
 
-            Type resultType = type.CreateTypeInfo().AsType();
+            Type resultType = type.CreateType();
             Type[] typeArguments = { typeof(int), typeof(string), typeof(object) };
             MethodInfo constructedMethod = resultType.GetMethod("TestMethod").MakeGenericMethod(typeArguments);
             Assert.Equal(typeArguments, constructedMethod.GetGenericArguments());
@@ -135,7 +135,7 @@ namespace System.Reflection.Emit.Tests
             MethodBuilder method = type.DefineMethod("method1", MethodAttributes.Public | MethodAttributes.Static);
             method.GetILGenerator().Emit(OpCodes.Ret);
 
-            Type resultType = type.CreateTypeInfo().AsType();
+            Type resultType = type.CreateType();
             Assert.Throws<InvalidOperationException>(() => method.DefineGenericParameters("T", "U"));
         }
     }
index a36dffc..e6e5f79 100644 (file)
@@ -28,7 +28,7 @@ namespace System.Reflection.Emit.Tests
             ilGenerator.Emit(OpCodes.Ldc_I4, expectedReturn);
             ilGenerator.Emit(OpCodes.Ret);
 
-            Type resultType = type.CreateTypeInfo().AsType();
+            Type resultType = type.CreateType();
 
             ParameterInfo[] parameters = method.GetParameters();
             Assert.Equal("System.String Param1", parameters[0].ToString());
@@ -119,7 +119,7 @@ namespace System.Reflection.Emit.Tests
             ILGenerator ilGenerator = method.GetILGenerator();
             ilGenerator.Emit(OpCodes.Ret);
 
-            Type resultType = type.CreateTypeInfo().AsType();
+            Type resultType = type.CreateType();
 
             Assert.Throws<InvalidOperationException>(() => method.DefineParameter(1, ParameterAttributes.Retval, "param1"));
         }
@@ -130,7 +130,7 @@ namespace System.Reflection.Emit.Tests
             TypeBuilder type = Helpers.DynamicType(TypeAttributes.Abstract);
             MethodBuilder builder = type.DefineMethod("TestMethod", TestMethodAttributes, typeof(void), new Type[] { typeof(int) });
 
-            type.CreateTypeInfo().AsType();
+            type.CreateType();
 
             Assert.Throws<InvalidOperationException>(() => builder.DefineParameter(1, ParameterAttributes.HasDefault, "TestParam"));
         }
index 3d1c4ad..554b2e3 100644 (file)
@@ -20,7 +20,7 @@ namespace System.Reflection.Emit.Tests
             ilGenerator.Emit(OpCodes.Ldc_I4, expectedReturn);
             ilGenerator.Emit(OpCodes.Ret);
 
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
             MethodInfo createdMethod = createdType.GetMethod("TestMethod");
             Assert.Equal(expectedReturn, createdMethod.Invoke(null, null));
 
index 6c3ed86..973b420 100644 (file)
@@ -16,7 +16,7 @@ namespace System.Reflection.Emit.Tests
             ILGenerator ilGenerator = method.GetILGenerator();
             ilGenerator.Emit(OpCodes.Ret);
 
-            type.CreateTypeInfo().AsType();
+            type.CreateType();
             Assert.Equal(typeof(void), method.ReturnParameter.ParameterType);
         }
 
@@ -33,7 +33,7 @@ namespace System.Reflection.Emit.Tests
             ILGenerator ilGenerator = method.GetILGenerator();
             ilGenerator.Emit(OpCodes.Ret);
 
-            type.CreateTypeInfo().AsType();
+            type.CreateType();
             Assert.Equal(returnType, method.ReturnParameter.ParameterType);
         }
 
@@ -53,7 +53,7 @@ namespace System.Reflection.Emit.Tests
             TypeBuilder type = Helpers.DynamicType(TypeAttributes.Abstract);
             MethodBuilder method = type.DefineMethod("TestMethod", MethodAttributes.Public | MethodAttributes.Abstract | MethodAttributes.Virtual);
 
-            type.CreateTypeInfo().AsType();
+            type.CreateType();
             Assert.Throws<InvalidOperationException>(() => method.ReturnParameter);
         }
     }
index 1b29764..42fea51 100644 (file)
@@ -81,7 +81,7 @@ namespace System.Reflection.Emit.Tests
 
             CustomAttributeBuilder attribute = new CustomAttributeBuilder(constructor, new object[] { 4 }, new FieldInfo[] { field }, new object[] { "hello" });
             method.SetCustomAttribute(attribute);
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
 
             object[] attributes = createdType.GetMethod("TestMethod").GetCustomAttributes(false).ToArray();
             Assert.Equal(1, attributes.Length);
index b95b159..c40a233 100644 (file)
@@ -33,7 +33,7 @@ namespace System.Reflection.Emit.Tests
             TypeBuilder type = Helpers.DynamicType(TypeAttributes.Abstract);
             MethodBuilder method = type.DefineMethod("TestMethod", MethodAttributes.Public | MethodAttributes.Abstract | MethodAttributes.Virtual);
 
-            type.CreateTypeInfo().AsType();
+            type.CreateType();
             Assert.Throws<InvalidOperationException>(() => method.SetImplementationFlags(MethodImplAttributes.Unmanaged));
         }
     }
index 2e5297e..4fedfe7 100644 (file)
@@ -30,7 +30,7 @@ namespace System.Reflection.Emit.Tests
             ILGenerator ilGenerator = method.GetILGenerator();
             ilGenerator.Emit(OpCodes.Ret);
 
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
             MethodInfo createdMethod = createdType.GetMethod(method.Name);
             VerifyParameters(createdMethod.GetParameters(), typeParameters, typeParamNames);
         }
@@ -46,7 +46,7 @@ namespace System.Reflection.Emit.Tests
             ILGenerator ilGenerator = method.GetILGenerator();
             ilGenerator.Emit(OpCodes.Ret);
 
-            type.CreateTypeInfo().AsType();
+            type.CreateType();
             method.SetParameters(typeParameters);
         }
 
@@ -60,7 +60,7 @@ namespace System.Reflection.Emit.Tests
             ILGenerator ilGenerator = method.GetILGenerator();
             ilGenerator.Emit(OpCodes.Ret);
 
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
             MethodInfo createdMethod = createdType.GetMethod(method.Name);
             ParameterInfo[] parameters = createdMethod.GetParameters();
             VerifyParameters(parameters, new Type[0], null);
@@ -76,7 +76,7 @@ namespace System.Reflection.Emit.Tests
             ILGenerator ilGenerator = builder.GetILGenerator();
             ilGenerator.Emit(OpCodes.Ret);
 
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
 
             MethodInfo method = createdType.GetMethod(builder.Name);
             ParameterInfo[] parameters = builder.GetParameters();
@@ -93,7 +93,7 @@ namespace System.Reflection.Emit.Tests
             ILGenerator ilGenerator = builder.GetILGenerator();
             ilGenerator.Emit(OpCodes.Ret);
 
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
 
             MethodInfo method = createdType.GetMethod(builder.Name);
             ParameterInfo[] parameters = method.GetParameters();
@@ -119,7 +119,7 @@ namespace System.Reflection.Emit.Tests
             ILGenerator ilGenerator = builder.GetILGenerator();
             ilGenerator.Emit(OpCodes.Ret);
 
-            AssertExtensions.Throws<ArgumentNullException>("argument", () => type.CreateTypeInfo().AsType());
+            AssertExtensions.Throws<ArgumentNullException>("argument", () => type.CreateType());
         }
 
         private void VerifyParameters(ParameterInfo[] parameters, Type[] parameterTypes, string[] parameterName)
index 05f8489..6245fbb 100644 (file)
@@ -17,7 +17,7 @@ namespace System.Reflection.Emit.Tests
             Type returnType = typeParameters[0].AsType();
             method.SetReturnType(returnType);
 
-            type.CreateTypeInfo().AsType();
+            type.CreateType();
             VerifyReturnType(method, returnType);
         }
 
@@ -33,7 +33,7 @@ namespace System.Reflection.Emit.Tests
             Type returnType = typeParameters[1].AsType();
             method.SetReturnType(returnType);
 
-            type.CreateTypeInfo().AsType();
+            type.CreateType();
             VerifyReturnType(method, returnType);
         }
 
@@ -49,7 +49,7 @@ namespace System.Reflection.Emit.Tests
             Type returnType = typeof(void);
             method.SetReturnType(returnType);
 
-            type.CreateTypeInfo().AsType();
+            type.CreateType();
             VerifyReturnType(method, returnType);
         }
 
@@ -62,7 +62,7 @@ namespace System.Reflection.Emit.Tests
             Type returnType = typeof(void);
             method.SetReturnType(returnType);
 
-            type.CreateTypeInfo().AsType();
+            type.CreateType();
             VerifyReturnType(method, returnType);
         }
 
@@ -80,7 +80,7 @@ namespace System.Reflection.Emit.Tests
             method.SetReturnType(typeParameters[0].AsType());
             method.SetReturnType(returnType);
 
-            type.CreateTypeInfo().AsType();
+            type.CreateType();
             VerifyReturnType(method, returnType);
         }
 
@@ -97,7 +97,7 @@ namespace System.Reflection.Emit.Tests
             method.SetReturnType(typeParameters[0].AsType());
             method.SetReturnType(returnType);
 
-            type.CreateTypeInfo().AsType();
+            type.CreateType();
             VerifyReturnType(method, returnType);
         }
 
@@ -113,7 +113,7 @@ namespace System.Reflection.Emit.Tests
             Type returnType = typeParameters[0].AsType();
             method.SetReturnType(returnType);
 
-            type.CreateTypeInfo().AsType();
+            type.CreateType();
             VerifyReturnType(method, returnType);
         }
 
@@ -127,7 +127,7 @@ namespace System.Reflection.Emit.Tests
             GenericTypeParameterBuilder[] typeParameters = method.DefineGenericParameters(typeParamNames);
 
             Type returnType = typeParameters[0].AsType();
-            type.CreateTypeInfo().AsType();
+            type.CreateType();
             method.SetReturnType(returnType);
         }
 
@@ -139,7 +139,7 @@ namespace System.Reflection.Emit.Tests
             MethodBuilder method = type.DefineMethod("TestMethod", MethodAttributes.Public | MethodAttributes.Abstract | MethodAttributes.Virtual);
 
             method.SetReturnType(null);
-            type.CreateTypeInfo().AsType();
+            type.CreateType();
             VerifyReturnType(method, typeof(void));
         }
 
index 82eefbc..34d3098 100644 (file)
@@ -258,7 +258,7 @@ namespace System.Reflection.Emit.Tests
 
         private void VerifyMethodSignature(TypeBuilder type, MethodBuilder method, Type desiredReturnType)
         {
-            Type ret = type.CreateTypeInfo().AsType();
+            Type ret = type.CreateType();
             MethodInfo methodInfo = method.GetBaseDefinition();
             Type actualReturnType = methodInfo.ReturnType;
 
index 088de0c..c52f27c 100644 (file)
@@ -17,6 +17,10 @@ namespace System.Reflection.Emit.Tests
             ilGenerator.Emit(OpCodes.Ret);
 
             module.CreateGlobalFunctions();
+            if (!PlatformDetection.IsMonoRuntime) // [ActiveIssue("https://github.com/dotnet/runtime/issues/72858", TestRuntimes.Mono)]
+            {
+                Assert.Null(method.DeclaringType);
+            }
         }
 
         [Fact]
@@ -34,6 +38,10 @@ namespace System.Reflection.Emit.Tests
             ilGenerator.EmitWriteLine("Hello World from global method again!");
 
             module.CreateGlobalFunctions();
+            if (!PlatformDetection.IsMonoRuntime) // [ActiveIssue("https://github.com/dotnet/runtime/issues/72858", TestRuntimes.Mono)]
+            {
+                Assert.Null(method.DeclaringType);
+            }
         }
 
         [Fact]
@@ -46,6 +54,10 @@ namespace System.Reflection.Emit.Tests
             ilGenerator.Emit(OpCodes.Ret);
 
             module.CreateGlobalFunctions();
+            if (!PlatformDetection.IsMonoRuntime) // [ActiveIssue("https://github.com/dotnet/runtime/issues/72858", TestRuntimes.Mono)]
+            {
+                Assert.Null(method.DeclaringType);
+            }
             Assert.Throws<InvalidOperationException>(() => module.CreateGlobalFunctions());
         }
     }
index e1d927c..6173ffd 100644 (file)
@@ -82,10 +82,10 @@ namespace System.Reflection.Emit.Tests
         {
             ModuleBuilder module = Helpers.DynamicModule();
             EnumBuilder underlyingEnumTypeBuilder = module.DefineEnum("Enum1", TypeAttributes.Public, typeof(int));
-            Type underlyingEnumType = underlyingEnumTypeBuilder.CreateTypeInfo().AsType();
+            Type underlyingEnumType = underlyingEnumTypeBuilder.CreateType();
 
             EnumBuilder enumBuilder = module.DefineEnum("Enum2", TypeAttributes.Public, underlyingEnumType);
-            Type enumType = enumBuilder.CreateTypeInfo().AsType();
+            Type enumType = enumBuilder.CreateType();
 
             Assert.Equal(typeof(int), Enum.GetUnderlyingType(enumType));
         }
@@ -183,7 +183,7 @@ namespace System.Reflection.Emit.Tests
             ModuleBuilder module = Helpers.DynamicModule();
             EnumBuilder enumBuilder = module.DefineEnum("Name", TypeAttributes.Public, underlyingType);
             Assert.Equal(underlyingType, enumBuilder.UnderlyingField.FieldType);
-            Assert.Throws<TypeLoadException>(() => enumBuilder.CreateTypeInfo().AsType());
+            Assert.Throws<TypeLoadException>(() => enumBuilder.CreateType());
         }
 
         protected enum Int32Enum { }
index 8dc6645..120906b 100644 (file)
@@ -58,11 +58,16 @@ namespace System.Reflection.Emit.Tests
             ModuleBuilder module = Helpers.DynamicModule();
             FieldBuilder field = module.DefineInitializedData("MyField", new byte[] { 1, 0, 1 }, FieldAttributes.Public);
             module.CreateGlobalFunctions();
+            if (!PlatformDetection.IsMonoRuntime) // [ActiveIssue("https://github.com/dotnet/runtime/issues/72858", TestRuntimes.Mono)]
+            {
+                Assert.Null(field.DeclaringType);
+            }
             Assert.Throws<InvalidOperationException>(() => module.DefineInitializedData("MyField2", new byte[] { 1, 0, 1 }, FieldAttributes.Public));
         }
 
         [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
         [ActiveIssue("https://github.com/dotnet/runtime/issues/65558", typeof(PlatformDetection), nameof(PlatformDetection.IsAndroid), nameof(PlatformDetection.Is32BitProcess))]
+
         public void DefineInitializedData_EnsureAlignmentIsMinimumNeededForUseOfCreateSpan()
         {
             ModuleBuilder module = Helpers.DynamicModule();
@@ -81,6 +86,14 @@ namespace System.Reflection.Emit.Tests
             FieldBuilder field8Byte_2 = module.DefineInitializedData("Field8Bytes_2", field8Byte_2_data, FieldAttributes.Public);
             module.CreateGlobalFunctions();
 
+            if (!PlatformDetection.IsMonoRuntime) // [ActiveIssue("https://github.com/dotnet/runtime/issues/72858", TestRuntimes.Mono)]
+            {
+                Assert.Null(field4Byte_1.DeclaringType);
+                Assert.Null(field8Byte_1.DeclaringType);
+                Assert.Null(field4Byte_2.DeclaringType);
+                Assert.Null(field8Byte_2.DeclaringType);
+            }
+
             var checkTypeBuilder = module.DefineType("CheckType", TypeAttributes.Public);
             CreateLoadAddressMethod("LoadAddress1", field1Byte);
             CreateLoadAddressMethod("LoadAddress4_1", field4Byte_1);
index 7c5bf90..88eed88 100644 (file)
@@ -99,10 +99,10 @@ namespace System.Reflection.Emit.Tests
         {
             ModuleBuilder module = Helpers.DynamicModule();
             TypeBuilder type1 = module.DefineType("TestType1");
-            Type parent = type1.CreateTypeInfo().AsType();
+            Type parent = type1.CreateType();
 
             TypeBuilder type2 = module.DefineType("TestType2", TypeAttributes.NotPublic, parent);
-            Type createdType = type2.CreateTypeInfo().AsType();
+            Type createdType = type2.CreateType();
             Assert.Equal("TestType2", createdType.Name);
             Assert.Equal(TypeAttributes.NotPublic, createdType.GetTypeInfo().Attributes);
             Assert.Equal(parent, createdType.GetTypeInfo().BaseType);
index 48d87c9..013bcb2 100644 (file)
@@ -90,7 +90,7 @@ namespace System.Reflection.Emit.Tests
 
         private static ParameterInfo GetCreatedParameter(TypeBuilder type, string methodName, int parameterIndex)
         {
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
             MethodInfo createdMethod = createdType.GetMethod(methodName);
             if (parameterIndex > 0)
             {
index 86a0de2..bd105a7 100644 (file)
@@ -26,7 +26,7 @@ namespace System.Reflection.Emit.Tests
             methodILGenerator.Emit(OpCodes.Ret);
 
             property.AddOtherMethod(method);
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
             PropertyInfo createdProperty = createdType.GetProperty("TestProperty", bindingFlags);
 
             MethodInfo[] actualMethods = createdProperty.GetAccessors(true);
@@ -57,7 +57,7 @@ namespace System.Reflection.Emit.Tests
             methodILGenerator.Emit(OpCodes.Ldarg_1);
             methodILGenerator.Emit(OpCodes.Ret);
 
-            type.CreateTypeInfo().AsType();
+            type.CreateType();
             Assert.Throws<InvalidOperationException>(() => property.AddOtherMethod(method));
         }
     }
index a1a5b49..958d0c9 100644 (file)
@@ -19,7 +19,7 @@ namespace System.Reflection.Emit.Tests
             methodILGenerator.Emit(OpCodes.Ret);
             property.AddOtherMethod(method);
 
-            Type myType = type.CreateTypeInfo().AsType();
+            Type myType = type.CreateType();
             Assert.Throws<NotSupportedException>(() => property.GetIndexParameters());
         }
     }
index e50f79e..be8ca12 100644 (file)
@@ -19,7 +19,7 @@ namespace System.Reflection.Emit.Tests
             methodILGenerator.Emit(OpCodes.Ret);
             property.AddOtherMethod(method);
 
-            type.CreateTypeInfo().AsType();
+            type.CreateType();
             Assert.Throws<NotSupportedException>(() => property.GetValue(null, null));
         }
     }
index 516539e..c020324 100644 (file)
@@ -61,7 +61,7 @@ namespace System.Reflection.Emit.Tests
 
             property.SetGetMethod(method);
 
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
             PropertyInfo createdProperty = createdType.GetProperty("TestProperty", bindingAttributes);
             Assert.Equal(defaultValue, createdProperty.GetConstantValue());
         }
@@ -78,7 +78,7 @@ namespace System.Reflection.Emit.Tests
             methodILGenerator.Emit(OpCodes.Ldarg_1);
             methodILGenerator.Emit(OpCodes.Ret);
 
-            type.CreateTypeInfo().AsType();
+            type.CreateType();
             Assert.Throws<InvalidOperationException>(() => property.SetConstant(1));
         }
 
index ee50310..11e7077 100644 (file)
@@ -33,7 +33,7 @@ namespace System.Reflection.Emit.Tests
             property.SetGetMethod(method);
 
             BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Static;
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
             PropertyInfo createdProperty = createdType.GetProperty("TestProperty", bindingFlags);
             object[] attributes = createdProperty.GetCustomAttributes(false).ToArray();
 
@@ -62,7 +62,7 @@ namespace System.Reflection.Emit.Tests
             object[] ctorParamValues = new object[] { 10 };
             CustomAttributeBuilder customAttrBuilder = new CustomAttributeBuilder(typeof(IntPropertyAttribute).GetConstructor(ctorParamTypes), ctorParamValues);
 
-            type.CreateTypeInfo().AsType();
+            type.CreateType();
             Assert.Throws<InvalidOperationException>(() => property.SetCustomAttribute(customAttrBuilder));
         }
 
@@ -96,7 +96,7 @@ namespace System.Reflection.Emit.Tests
             property.SetGetMethod(method);
 
             BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Static;
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
             PropertyInfo createdProperty = createdType.GetProperty("TestProperty", bindingFlags);
             object[] attributes = createdProperty.GetCustomAttributes(false).ToArray();
 
@@ -124,7 +124,7 @@ namespace System.Reflection.Emit.Tests
 
             ConstructorInfo con = typeof(IntPropertyAttribute).GetConstructor(new Type[] { typeof(int) });
 
-            type.CreateTypeInfo().AsType();
+            type.CreateType();
             Assert.Throws<InvalidOperationException>(() => property.SetCustomAttribute(con, new byte[6]));
         }
     }
index 40cdaea..4506c2d 100644 (file)
@@ -53,7 +53,7 @@ namespace System.Reflection.Emit.Tests
             methodILGenerator.Emit(OpCodes.Ldfld, field);
             methodILGenerator.Emit(OpCodes.Ret);
 
-            type.CreateTypeInfo().AsType();
+            type.CreateType();
             Assert.Throws<InvalidOperationException>(() => property.SetGetMethod(method));
         }
     }
index 1d90d96..7eb7de6 100644 (file)
@@ -44,7 +44,7 @@ namespace System.Reflection.Emit.Tests
             MethodAttributes setMethodAttributes = MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig;
             MethodBuilder method = ImplementMethod(type, "TestMethod", setMethodAttributes, null, new Type[] { typeof(int) }, field);
 
-            type.CreateTypeInfo().AsType();
+            type.CreateType();
             Assert.Throws<InvalidOperationException>(() => { property.SetSetMethod(method); });
         }
 
index 4069900..21e9f9f 100644 (file)
@@ -24,7 +24,7 @@ namespace System.Reflection.Emit.Tests
             methodILGenerator.Emit(OpCodes.Ret);
             property.SetGetMethod(method);
 
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
             object obj = createdType.GetConstructor(new Type[0]).Invoke(null);
             Assert.Throws<NotSupportedException>(() => property.SetValue(obj, 99, null));
         }
index da3e695..ba7e017 100644 (file)
@@ -19,12 +19,12 @@ namespace System.Reflection.Emit.Tests
                 MethodAttributes.Abstract | MethodAttributes.Virtual | MethodAttributes.Public,
                 typeof(int),
                 new Type[] { typeof(int), typeof(int) });
-            Type createdInterface = interfaceBuilder.CreateTypeInfo().AsType();
+            Type createdInterface = interfaceBuilder.CreateType();
 
             TypeBuilder type = Helpers.DynamicType(typeAttributes);
             type.AddInterfaceImplementation(createdInterface);
 
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
             Assert.Equal(createdInterface, createdType.GetTypeInfo().ImplementedInterfaces.Single(i => i.Name == createdInterface.Name));
         }
 
@@ -37,7 +37,7 @@ namespace System.Reflection.Emit.Tests
                 typeof(int),
                 new Type[] { typeof(int), typeof(int) });
 
-            Type createdInterface = interfaceBuilder.CreateTypeInfo().AsType();
+            Type createdInterface = interfaceBuilder.CreateType();
 
             TypeBuilder type = Helpers.DynamicType(TypeAttributes.Class | TypeAttributes.Public);
             type.AddInterfaceImplementation(createdInterface);
@@ -50,7 +50,7 @@ namespace System.Reflection.Emit.Tests
             MethodInfo createdMethod = createdInterface.GetMethod("TestMethod");
             type.DefineMethodOverride(methodBuilder, createdMethod);
 
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
             Assert.Equal(createdInterface, createdType.GetTypeInfo().ImplementedInterfaces.Single(i => i.Name == createdInterface.Name));
         }
 
@@ -65,7 +65,7 @@ namespace System.Reflection.Emit.Tests
         public void AddInterfaceImplementation_TypeAlreadyCreated_ThrowsInvalidOperationException()
         {
             TypeBuilder type = Helpers.DynamicType(TypeAttributes.Public);
-            type.CreateTypeInfo().AsType();
+            type.CreateType();
 
             Assert.Throws<InvalidOperationException>(() => type.AddInterfaceImplementation(typeof(EmptyNonGenericInterface1)));
         }
index 4989266..d0d58e7 100644 (file)
@@ -24,6 +24,10 @@ namespace System.Reflection.Emit.Tests
         {
             TypeBuilder type = Helpers.DynamicType(attributes);
             Type createdType = type.CreateType();
+            if (!PlatformDetection.IsMonoRuntime) // [ActiveIssue("https://github.com/dotnet/runtime/issues/72858", TestRuntimes.Mono)]
+            {
+                Assert.NotNull(createdType);
+            }
             Assert.Equal(type.Name, createdType.Name);
 
             TypeInfo typeInfo = type.CreateTypeInfo();
@@ -75,6 +79,10 @@ namespace System.Reflection.Emit.Tests
             type.DefineNestedType("NestedType");
 
             Type createdType = type.CreateType();
+            if (!PlatformDetection.IsMonoRuntime) // [ActiveIssue("https://github.com/dotnet/runtime/issues/72858", TestRuntimes.Mono)]
+            {
+                Assert.NotNull(createdType);
+            }
             Assert.Equal(type.Name, createdType.Name);
         }
 
@@ -85,6 +93,10 @@ namespace System.Reflection.Emit.Tests
             type.DefineGenericParameters("T");
 
             Type createdType = type.CreateType();
+            if (!PlatformDetection.IsMonoRuntime) // [ActiveIssue("https://github.com/dotnet/runtime/issues/72858", TestRuntimes.Mono)]
+            {
+                Assert.NotNull(createdType);
+            }
             Assert.Equal(type.Name, createdType.Name);
         }
     }
index c7fee2f..4cd6391 100644 (file)
@@ -23,7 +23,7 @@ namespace System.Reflection.Emit.Tests
         public void CreateType(TypeAttributes attributes)
         {
             TypeBuilder type = Helpers.DynamicType(attributes);
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
             Assert.Equal(type.Name, createdType.Name);
 
             Assert.Equal(type.CreateTypeInfo(), createdType.GetTypeInfo());
@@ -35,7 +35,7 @@ namespace System.Reflection.Emit.Tests
             TypeBuilder type = Helpers.DynamicType(TypeAttributes.NotPublic);
             type.DefineNestedType("NestedType");
 
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
             Assert.Equal(type.Name, createdType.Name);
         }
 
@@ -45,7 +45,7 @@ namespace System.Reflection.Emit.Tests
             TypeBuilder type = Helpers.DynamicType(TypeAttributes.NotPublic);
             type.DefineGenericParameters("T");
 
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
             Assert.Equal(type.Name, createdType.Name);
         }
 
index b58e7d3..e580474 100644 (file)
@@ -82,7 +82,7 @@ namespace System.Reflection.Emit.Tests
             ConstructorBuilder constructor = type.DefineConstructor(MethodAttributes.Static, CallingConventions.Standard, new Type[0]);
             constructor.GetILGenerator().Emit(OpCodes.Ret);
 
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
             Assert.Equal(1, createdType.GetConstructors(BindingFlags.Static | BindingFlags.NonPublic).Length);
         }
 
@@ -94,7 +94,7 @@ namespace System.Reflection.Emit.Tests
             type.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, new Type[0]).GetILGenerator().Emit(OpCodes.Ret);
             type.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, new Type[0]).GetILGenerator().Emit(OpCodes.Ret);
 
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
             ConstructorInfo[] constructors = createdType.GetConstructors();
             Assert.Equal(2, constructors.Length);
             Assert.Equal(constructors[0].GetParameters(), constructors[1].GetParameters());
@@ -104,7 +104,7 @@ namespace System.Reflection.Emit.Tests
         public void DefineConstructor_TypeAlreadyCreated_ThrowsInvalidOperationException()
         {
             TypeBuilder type = Helpers.DynamicType(TypeAttributes.Public);
-            type.CreateTypeInfo().AsType();
+            type.CreateType();
             Assert.Throws<InvalidOperationException>(() => type.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, new Type[0]));
         }
 
index 95e3bb5..d53ccb5 100644 (file)
@@ -56,7 +56,7 @@ namespace System.Reflection.Emit.Tests
             type.SetParent(genericParent);
             type.DefineDefaultConstructor(MethodAttributes.Public);
 
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
             ConstructorInfo defaultConstructor = createdType.GetConstructor(new Type[0]);
             defaultConstructor.Invoke(null);
             Assert.True(s_ranConstructor);
@@ -70,7 +70,7 @@ namespace System.Reflection.Emit.Tests
             type.DefineDefaultConstructor(MethodAttributes.Public);
             type.DefineDefaultConstructor(MethodAttributes.Public);
 
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
             ConstructorInfo[] constructors = createdType.GetConstructors();
             Assert.Equal(2, constructors.Length);
             Assert.Equal(constructors[0].GetParameters(), constructors[1].GetParameters());
@@ -80,7 +80,7 @@ namespace System.Reflection.Emit.Tests
         public void DefineDefaultConstructor_TypeCreated_ThrowsInvalidOperationException()
         {
             TypeBuilder type = Helpers.DynamicType(TypeAttributes.Public);
-            type.CreateTypeInfo().AsType();
+            type.CreateType();
             Assert.Throws<InvalidOperationException>(() => type.DefineDefaultConstructor(MethodAttributes.Public));
         }
 
@@ -110,7 +110,7 @@ namespace System.Reflection.Emit.Tests
 
             constructorIlGenerator.Emit(OpCodes.Ret);
 
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
             TypeBuilder nestedType = Helpers.DynamicType(TypeAttributes.Public | TypeAttributes.Class);
             nestedType.SetParent(createdType);
 
@@ -126,7 +126,7 @@ namespace System.Reflection.Emit.Tests
             ConstructorBuilder constructor = baseType.DefineConstructor(attributes, CallingConventions.HasThis, new Type[] { typeof(int) });
             constructor.GetILGenerator().Emit(OpCodes.Ret);
 
-            Type createdParentType = baseType.CreateTypeInfo().AsType();
+            Type createdParentType = baseType.CreateType();
 
             TypeBuilder type = Helpers.DynamicType(TypeAttributes.Public | TypeAttributes.Class);
             type.SetParent(createdParentType);
index 59ebb7f..05cda03 100644 (file)
@@ -43,7 +43,7 @@ namespace System.Reflection.Emit.Tests
             eventBuilder.SetAddOnMethod(addOnMethod);
             eventBuilder.SetRemoveOnMethod(removeOnMethod);
 
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
             Assert.Equal(type.AsType().GetEvents(Helpers.AllFlags), createdType.GetEvents(Helpers.AllFlags));
             Assert.Equal(type.AsType().GetEvent(expectedName, Helpers.AllFlags), createdType.GetEvent(expectedName, Helpers.AllFlags));
 
@@ -75,7 +75,7 @@ namespace System.Reflection.Emit.Tests
                 eventBuilder.SetRemoveOnMethod(removeOnMethod);
             }
 
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
             EventInfo[] events = createdType.GetEvents();
             Assert.Equal(1, events.Length);
             Assert.Equal("EventName", events[0].Name);
@@ -88,7 +88,7 @@ namespace System.Reflection.Emit.Tests
             type.DefineGenericParameters("T");
 
             type.DefineEvent("TestEvent", EventAttributes.None, typeof(int));
-            type.CreateTypeInfo().AsType();
+            type.CreateType();
             Assert.Throws<InvalidOperationException>(() => type.DefineEvent("TestEvent2", EventAttributes.None, typeof(int)));
         }
 
@@ -110,7 +110,7 @@ namespace System.Reflection.Emit.Tests
         {
             TypeBuilder type = Helpers.DynamicType(TypeAttributes.Class | TypeAttributes.Public);
             type.DefineEvent("Name", EventAttributes.None, typeof(int).MakeByRefType());
-            type.CreateTypeInfo().AsType();
+            type.CreateType();
         }
 
         [Fact]
index a09e69f..c81709b 100644 (file)
@@ -45,7 +45,7 @@ namespace System.Reflection.Emit.Tests
             Assert.Equal(type.AsType(), field.DeclaringType);
             Assert.Equal(field.Module, field.Module);
 
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
             Assert.Equal(type.AsType().GetFields(Helpers.AllFlags), createdType.GetFields(Helpers.AllFlags));
 
             FieldInfo fieldInfo = createdType.GetField(name, Helpers.AllFlags);
@@ -67,7 +67,7 @@ namespace System.Reflection.Emit.Tests
             type.DefineField("Name", typeof(int), FieldAttributes.Public);
             type.DefineField("Name", typeof(int), FieldAttributes.Public);
 
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
             FieldInfo[] fields = createdType.GetFields();
             Assert.Equal(2, fields.Length);
             Assert.Equal(fields[0].Name, fields[1].Name);
@@ -136,11 +136,11 @@ namespace System.Reflection.Emit.Tests
             TypeBuilder fieldType = module.DefineType("FieldType", TypeAttributes.Public);
             type.DefineField("Name", fieldType.AsType(), FieldAttributes.Public);
 
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
             FieldInfo field = createdType.GetField("Name");
             Assert.Throws<TypeLoadException>(() => field.FieldType);
 
-            Type createdFieldType = fieldType.CreateTypeInfo().AsType();
+            Type createdFieldType = fieldType.CreateType();
             Assert.Equal(createdFieldType, field.FieldType);
         }
 
@@ -173,7 +173,7 @@ namespace System.Reflection.Emit.Tests
 
             type.DefineField("Name", typeof(int).MakeByRefType(), FieldAttributes.Public);
 
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
             FieldInfo[] fields = createdType.GetFields();
             Assert.Equal(1, fields.Length);
             Assert.True(fields[0].FieldType.IsByRef);
@@ -200,7 +200,7 @@ namespace System.Reflection.Emit.Tests
                 il.Emit(OpCodes.Ret);
             }
 
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
 
             var ctorToCall = createdType.GetConstructor(BindingFlags.Public | BindingFlags.Instance, new[] { typeof(string) });
             var str = "12345";
index 41597d7..3070afe 100644 (file)
@@ -31,7 +31,7 @@ namespace System.Reflection.Emit.Tests
             MethodInfo declaration = typeof(DefineMethodOverrideInterface).GetMethod("M");
             type.DefineMethodOverride(method, declaration);
 
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
 
             MethodInfo createdMethod = typeof(DefineMethodOverrideInterface).GetMethod("M");
             Assert.Equal(2, createdMethod.Invoke(Activator.CreateInstance(createdType), null));
@@ -51,7 +51,7 @@ namespace System.Reflection.Emit.Tests
             MethodInfo declaration = typeof(DefineMethodOverrideInterface).GetMethod("M");
             type.DefineMethodOverride(method, declaration);
 
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
             MethodInfo createdMethod = typeof(DefineMethodOverrideInterface).GetMethod("M");
 
             ConstructorInfo createdTypeCtor = createdType.GetConstructor(new Type[0]);
@@ -74,7 +74,7 @@ namespace System.Reflection.Emit.Tests
             MethodInfo interfaceMethod = typeof(GenericInterface<string>).GetMethod(nameof(GenericInterface<string>.Method));
             type.DefineMethodOverride(method, interfaceMethod);
 
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
             Assert.Equal("Hello World", interfaceMethod.Invoke(Activator.CreateInstance(createdType), null));
         }
 
@@ -92,7 +92,7 @@ namespace System.Reflection.Emit.Tests
             type.DefineMethodOverride(method, declaration);
             type.DefineMethodOverride(method, declaration);
 
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
 
             MethodInfo createdMethod = typeof(DefineMethodOverrideInterface).GetMethod("M");
             Assert.Equal(2, createdMethod.Invoke(Activator.CreateInstance(createdType), null));
@@ -143,7 +143,7 @@ namespace System.Reflection.Emit.Tests
             method.GetILGenerator().Emit(OpCodes.Ret);
             type.AddInterfaceImplementation(typeof(DefineMethodOverrideInterface));
 
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
             MethodInfo body = createdType.GetMethod(method.Name);
             MethodInfo declaration = typeof(DefineMethodOverrideInterface).GetMethod(method.Name);
 
index 064d39d..84d27ee 100644 (file)
@@ -39,7 +39,7 @@ namespace System.Reflection.Emit.Tests
             Assert.Equal(attributes, property.Attributes);
             Assert.Equal(returnType, property.PropertyType);
 
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
             Assert.Equal(type.AsType().GetProperties(Helpers.AllFlags), createdType.GetProperties(Helpers.AllFlags));
 
             PropertyInfo createdProperty = createdType.GetProperty(expectedName, Helpers.AllFlags);
@@ -77,7 +77,7 @@ namespace System.Reflection.Emit.Tests
             ilGenerator.Emit(OpCodes.Ret);
             property.SetGetMethod(getMethod);
 
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
             object obj = Activator.CreateInstance(createdType);
             Assert.Equal(5, createdType.GetProperty("Property").GetGetMethod().Invoke(obj, null));
         }
@@ -99,7 +99,7 @@ namespace System.Reflection.Emit.Tests
             ilGenerator.Emit(OpCodes.Ret);
             property.SetGetMethod(getMethod);
 
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
             object obj = Activator.CreateInstance(createdType);
             Assert.Equal(5, createdType.GetProperty("Property").GetGetMethod().Invoke(obj, null));
         }
@@ -129,7 +129,7 @@ namespace System.Reflection.Emit.Tests
         public void DefineProperty_TypeCreated_ThrowsInvalidOperationException()
         {
             TypeBuilder type = Helpers.DynamicType(TypeAttributes.Class | TypeAttributes.Public);
-            type.CreateTypeInfo().AsType();
+            type.CreateType();
 
             Assert.Throws<InvalidOperationException>(() => type.DefineProperty("TestProperty", PropertyAttributes.HasDefault, typeof(int), null, null, new Type[] { typeof(int) }, null, null));
 
@@ -143,7 +143,7 @@ namespace System.Reflection.Emit.Tests
             TypeBuilder type = Helpers.DynamicType(TypeAttributes.Public);
             type.DefineProperty("Name", PropertyAttributes.None, typeof(EmptyGenericStruct<>), new Type[0]);
 
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
             PropertyInfo createdProperty = createdType.GetProperty("Name", BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
             Assert.Throws<BadImageFormatException>(() => createdProperty.PropertyType);
         }
@@ -163,7 +163,7 @@ namespace System.Reflection.Emit.Tests
             TypeBuilder type = Helpers.DynamicType(TypeAttributes.Public);
             type.DefineProperty("Name", PropertyAttributes.None, typeof(int), new Type[] { typeof(EmptyGenericStruct<>) });
 
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
             PropertyInfo createdProperty = createdType.GetProperty("Name", BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
             Assert.Throws<BadImageFormatException>(() => createdProperty.PropertyType);
         }
@@ -177,11 +177,11 @@ namespace System.Reflection.Emit.Tests
             TypeBuilder propertyType = module.DefineType("PropertyType", TypeAttributes.Public);
             type.DefineProperty("Name", PropertyAttributes.None, propertyType.AsType(), new Type[0]);
 
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
             PropertyInfo property = createdType.GetProperty("Name", BindingFlags.NonPublic | BindingFlags.Instance);
             Assert.Throws<TypeLoadException>(() => property.PropertyType);
 
-            Type createdPropertyType = propertyType.CreateTypeInfo().AsType();
+            Type createdPropertyType = propertyType.CreateType();
             Assert.Equal(createdPropertyType, property.PropertyType);
         }
 
@@ -194,11 +194,11 @@ namespace System.Reflection.Emit.Tests
             TypeBuilder propertyType = module.DefineType("PropertyType", TypeAttributes.Public);
             type.DefineProperty("Name", PropertyAttributes.None, typeof(int), new Type[] { propertyType.AsType() });
 
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
             PropertyInfo property = createdType.GetProperty("Name", BindingFlags.NonPublic | BindingFlags.Instance);
             Assert.Throws<TypeLoadException>(() => property.PropertyType);
 
-            Type createdPropertyType = propertyType.CreateTypeInfo().AsType();
+            Type createdPropertyType = propertyType.CreateType();
             Assert.Equal(typeof(int), property.PropertyType);
         }
 
@@ -210,7 +210,7 @@ namespace System.Reflection.Emit.Tests
             type.DefineProperty("PropertyName", PropertyAttributes.None, typeof(int), new Type[0]);
             type.DefineProperty("PropertyName", PropertyAttributes.None, typeof(int), new Type[0]);
 
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
             PropertyInfo[] properties = createdType.GetProperties(BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
             Assert.Equal(1, properties.Length);
             Assert.Equal("PropertyName", properties[0].Name);
index a75f8b0..6758f93 100644 (file)
@@ -25,7 +25,7 @@ namespace System.Reflection.Emit.Tests
 
             Helpers.VerifyConstructor(constructor, type, MethodAttributes.Private | MethodAttributes.Static | MethodAttributes.SpecialName, CallingConventions.Standard, new Type[0]);
 
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
             FieldInfo createdField = createdType.GetField("Greeting", BindingFlags.NonPublic | BindingFlags.Static);
             Assert.Equal("hello", createdField.GetValue(Activator.CreateInstance(createdType)));
         }
@@ -34,7 +34,7 @@ namespace System.Reflection.Emit.Tests
         public void DefineTypeInitializer_TypeCreated_ThrowsInvalidOperationException()
         {
             TypeBuilder type = Helpers.DynamicType(TypeAttributes.Public);
-            type.CreateTypeInfo().AsType();
+            type.CreateType();
 
             Assert.Throws<InvalidOperationException>(() => type.DefineTypeInitializer());
         }
index cee5ef3..6a4a46e 100644 (file)
@@ -12,7 +12,7 @@ namespace System.Reflection.Emit.Tests
         public void Guid_TypeCreated_NotEmpty()
         {
             TypeBuilder type = Helpers.DynamicType(TypeAttributes.NotPublic);
-            type.CreateTypeInfo().AsType();
+            type.CreateType();
             Assert.NotEqual(Guid.Empty, type.GUID);
         }
 
index daec1bf..aa39c01 100644 (file)
@@ -57,7 +57,7 @@ namespace System.Reflection.Emit.Tests
             ilGenerator.EmitCall(OpCodes.Call, genericStringMethod, null);
             ilGenerator.Emit(OpCodes.Ret);
 
-            type1.CreateTypeInfo().AsType();
+            type1.CreateType();
             Assert.True(type1.IsGenericTypeDefinition);
         }
 
@@ -73,7 +73,7 @@ namespace System.Reflection.Emit.Tests
             ilGenerator.EmitCall(OpCodes.Call, writeLine, null);
             ilGenerator.Emit(OpCodes.Ret);
 
-            type.CreateTypeInfo().AsType();
+            type.CreateType();
             Assert.False(type.IsGenericTypeDefinition);
         }
     }
index eabcd69..1d905a5 100644 (file)
@@ -19,7 +19,7 @@ namespace System.Reflection.Emit.Tests
 
             CustomAttributeBuilder attribute = new CustomAttributeBuilder(attriubteConstructor, new object[] { 4 }, new FieldInfo[] { attributeField }, new object[] { "hello" });
             type.SetCustomAttribute(attribute);
-            type.CreateTypeInfo().AsType();
+            type.CreateType();
 
             object[] attributes = type.GetCustomAttributes(false).ToArray();
             Assert.Equal(1, attributes.Length);
@@ -44,7 +44,7 @@ namespace System.Reflection.Emit.Tests
             CustomAttributeBuilder cuatbu = new CustomAttributeBuilder(constructor, new object[] { "hello" });
             type.SetCustomAttribute(cuatbu);
 
-            type.CreateTypeInfo().AsType();
+            type.CreateType();
 
             object[] attributes = type.GetCustomAttributes(false).ToArray();
             Assert.Equal(1, attributes.Length);
index 5c985d5..7393bde 100644 (file)
@@ -34,7 +34,7 @@ namespace System.Reflection.Emit.Tests
         public void SetParent_TypeCreated_ThrowsInvalidOperationException()
         {
             TypeBuilder type = Helpers.DynamicType(TypeAttributes.NotPublic);
-            type.CreateTypeInfo().AsType();
+            type.CreateType();
             Assert.Throws<InvalidOperationException>(() => type.SetParent(typeof(string)));
         }
 
index bc327f0..4c01aba 100644 (file)
@@ -98,7 +98,7 @@ namespace System.Reflection.Emit.Tests
 
             if (declaringType == null && !type.IsInterface && (implementedInterfaces == null || implementedInterfaces.Length == 0))
             {
-                Type createdType = type.CreateTypeInfo().AsType();
+                Type createdType = type.CreateType();
                 Assert.Equal(createdType, module.GetType(name, false, false));
                 Assert.Equal(createdType, module.GetType(name, true, false));
 
@@ -125,7 +125,7 @@ namespace System.Reflection.Emit.Tests
             Assert.Throws<NotSupportedException>(() => constructor.Invoke(null));
             Assert.Throws<NotSupportedException>(() => constructor.Invoke(null, null));
 
-            Type createdType = type.CreateTypeInfo().AsType();
+            Type createdType = type.CreateType();
             Assert.Equal(type.AsType().GetConstructors(AllFlags), createdType.GetConstructors(AllFlags));
             Assert.Equal(type.AsType().GetConstructor(parameterTypes), createdType.GetConstructor(parameterTypes));
 
index 659d03b..071b850 100644 (file)
@@ -54,7 +54,7 @@ namespace System.Runtime.Loader.Tests
             ilGenerator.Emit(OpCodes.Ret);
 
             // Generate the type and return the associated assembly
-            return typeBuilder.CreateTypeInfo().AsType().Assembly;
+            return typeBuilder.CreateType().Assembly;
         }
     }
 }
index 8ca1c73..245840e 100644 (file)
@@ -2083,7 +2083,7 @@ namespace System.Tests
             enumBuilder.DefineLiteral("Value1", true);
             enumBuilder.DefineLiteral("Value2", false);
 
-            return enumBuilder.CreateTypeInfo().AsType();
+            return enumBuilder.CreateType();
         }
 
         private static Type s_charEnumType = GetCharEnumType();
@@ -2104,7 +2104,7 @@ namespace System.Tests
             enumBuilder.DefineLiteral("Value0x0010", (char)0x0010);
             enumBuilder.DefineLiteral("Value0x3f16", (char)0x3f16);
 
-            return enumBuilder.CreateTypeInfo().AsType();
+            return enumBuilder.CreateType();
         }
 
         private static Type s_floatEnumType = GetFloatEnumType();
@@ -2125,7 +2125,7 @@ namespace System.Tests
             enumBuilder.DefineLiteral("Value0x0010", (float)0x0010);
             enumBuilder.DefineLiteral("Value0x3f16", (float)0x3f16);
 
-            return enumBuilder.CreateTypeInfo().AsType();
+            return enumBuilder.CreateType();
         }
 
         private static Type s_doubleEnumType = GetDoubleEnumType();
@@ -2146,7 +2146,7 @@ namespace System.Tests
             enumBuilder.DefineLiteral("Value0x0010", (double)0x0010);
             enumBuilder.DefineLiteral("Value0x3f16", (double)0x3f16);
 
-            return enumBuilder.CreateTypeInfo().AsType();
+            return enumBuilder.CreateType();
         }
 
         private static Type s_intPtrEnumType = GetIntPtrEnumType();
@@ -2156,7 +2156,7 @@ namespace System.Tests
             if (enumBuilder == null)
                 return null;
 
-            return enumBuilder.CreateTypeInfo().AsType();
+            return enumBuilder.CreateType();
         }
 
         private static Type s_uintPtrEnumType = GetUIntPtrEnumType();
@@ -2166,7 +2166,7 @@ namespace System.Tests
             if (enumBuilder == null)
                 return null;
 
-            return enumBuilder.CreateTypeInfo().AsType();
+            return enumBuilder.CreateType();
         }
     }
 }
index 1d2c182..613d9f3 100644 (file)
@@ -123,7 +123,7 @@ class Test_EmittingIgnoresAccessChecksToAttributeIsRespected
         attributeTypeBuilder.SetCustomAttribute(customAttributeBuilder);
 
         // Make the TypeInfo real so the constructor can be used.
-        return attributeTypeBuilder.CreateTypeInfo()!.DeclaredConstructors.Single();
+        return attributeTypeBuilder.CreateTypeInfo().DeclaredConstructors.Single();
     }
 }