}
[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();
}
// cannot create globals twice
throw new InvalidOperationException(SR.InvalidOperation_NotADebugModule);
}
- _globalTypeBuilder.CreateType();
+ _globalTypeBuilder.CreateTypeInfoImpl();
_hasGlobalBeenCreated = true;
}
#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)
{
attributeTypeBuilder.SetCustomAttribute(customAttributeBuilder);
// Make the TypeInfo real so the constructor can be used.
- return attributeTypeBuilder.CreateTypeInfo()!.DeclaredConstructors.Single();
+ return attributeTypeBuilder.CreateTypeInfo().DeclaredConstructors.Single();
}
}
}
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
{
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;
ilg.EndMethod();
}
typedSerializerTypeBuilder.DefineDefaultConstructor(CodeGenerator.PublicMethodAttributes);
- Type typedSerializerType = typedSerializerTypeBuilder.CreateTypeInfo()!.AsType();
+ Type typedSerializerType = typedSerializerTypeBuilder.CreateType();
CreatedTypes.Add(typedSerializerType.Name, typedSerializerType);
return typedSerializerType.Name;
ilg.Call(baseCtor);
ilg.EndMethod();
// Instantiate type
- Type serializerContractType = serializerContractTypeBuilder.CreateTypeInfo()!.AsType();
+ Type serializerContractType = serializerContractTypeBuilder.CreateType();
CreatedTypes.Add(serializerContractType.Name, serializerContractType);
}
this.typeBuilder.DefineDefaultConstructor(
CodeGenerator.PublicMethodAttributes);
- Type readerType = this.typeBuilder.CreateTypeInfo()!.AsType();
+ Type readerType = this.typeBuilder.CreateType();
CreatedTypes.Add(readerType.Name, readerType);
}
GenerateInitCallbacksMethod();
this.typeBuilder.DefineDefaultConstructor(
CodeGenerator.PublicMethodAttributes);
- return this.typeBuilder.CreateTypeInfo()!.AsType();
+ return this.typeBuilder.CreateType();
}
[RequiresUnreferencedCode("calls GenerateTypeElement")]
if (!_useLRE)
{
- typBaked = _typeBldr!.CreateTypeInfo()!.AsType();
+ typBaked = _typeBldr!.CreateType();
// Replace all MethodInfos in this.methods
methodsBaked = new Hashtable(_methods.Count);
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)
setMethodGenerator.Emit(OpCodes.Ret);
propertyBuilder.SetSetMethod(setMethod);
- Type createdType = typeBuilder.CreateTypeInfo().AsType();
+ Type createdType = typeBuilder.CreateType();
// ConstructorBuilder, PropertyInfo, FieldInfo
yield return new object[]
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]));
{
enumBuilder.DefineLiteral("Value" + i, literalValues[i]);
}
- return enumBuilder.CreateTypeInfo().AsType();
+ return enumBuilder.CreateType();
}
}
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);
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
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);
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'
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));
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'
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");
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'
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));
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'
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));
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));
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));
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));
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;
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");
}
}
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");
}
}
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");
}
}
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");
}
}
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);
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
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
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];
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];
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)]
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; }
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);
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);
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);
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);
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"));
}
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]);
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();
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));
}
}
Assert.Equal(enumBuilder.AsType(), literal.FieldType);
Type createdEnum = useCreateTypeInfo ?
- enumBuilder.CreateTypeInfo().AsType() :
+ enumBuilder.CreateType() :
enumBuilder.CreateType();
FieldInfo createdLiteral = createdEnum.GetField("FieldOne");
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 });
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 });
public void Guid_TypeCreated()
{
EnumBuilder enumBuilder = Helpers.DynamicEnum(TypeAttributes.Public, typeof(int));
- enumBuilder.CreateTypeInfo().AsType();
+ enumBuilder.CreateType();
Assert.NotEqual(Guid.Empty, enumBuilder.GUID);
}
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));
}
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));
}
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));
}
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));
}
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));
}
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); });
}
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));
}
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));
}
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); });
}
{
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));
}
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);
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);
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);
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());
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"));
}
}
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());
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"));
}
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"));
}
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));
ILGenerator ilGenerator = method.GetILGenerator();
ilGenerator.Emit(OpCodes.Ret);
- type.CreateTypeInfo().AsType();
+ type.CreateType();
Assert.Equal(typeof(void), method.ReturnParameter.ParameterType);
}
ILGenerator ilGenerator = method.GetILGenerator();
ilGenerator.Emit(OpCodes.Ret);
- type.CreateTypeInfo().AsType();
+ type.CreateType();
Assert.Equal(returnType, method.ReturnParameter.ParameterType);
}
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);
}
}
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);
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));
}
}
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);
}
ILGenerator ilGenerator = method.GetILGenerator();
ilGenerator.Emit(OpCodes.Ret);
- type.CreateTypeInfo().AsType();
+ type.CreateType();
method.SetParameters(typeParameters);
}
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);
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();
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();
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)
Type returnType = typeParameters[0].AsType();
method.SetReturnType(returnType);
- type.CreateTypeInfo().AsType();
+ type.CreateType();
VerifyReturnType(method, returnType);
}
Type returnType = typeParameters[1].AsType();
method.SetReturnType(returnType);
- type.CreateTypeInfo().AsType();
+ type.CreateType();
VerifyReturnType(method, returnType);
}
Type returnType = typeof(void);
method.SetReturnType(returnType);
- type.CreateTypeInfo().AsType();
+ type.CreateType();
VerifyReturnType(method, returnType);
}
Type returnType = typeof(void);
method.SetReturnType(returnType);
- type.CreateTypeInfo().AsType();
+ type.CreateType();
VerifyReturnType(method, returnType);
}
method.SetReturnType(typeParameters[0].AsType());
method.SetReturnType(returnType);
- type.CreateTypeInfo().AsType();
+ type.CreateType();
VerifyReturnType(method, returnType);
}
method.SetReturnType(typeParameters[0].AsType());
method.SetReturnType(returnType);
- type.CreateTypeInfo().AsType();
+ type.CreateType();
VerifyReturnType(method, returnType);
}
Type returnType = typeParameters[0].AsType();
method.SetReturnType(returnType);
- type.CreateTypeInfo().AsType();
+ type.CreateType();
VerifyReturnType(method, returnType);
}
GenericTypeParameterBuilder[] typeParameters = method.DefineGenericParameters(typeParamNames);
Type returnType = typeParameters[0].AsType();
- type.CreateTypeInfo().AsType();
+ type.CreateType();
method.SetReturnType(returnType);
}
MethodBuilder method = type.DefineMethod("TestMethod", MethodAttributes.Public | MethodAttributes.Abstract | MethodAttributes.Virtual);
method.SetReturnType(null);
- type.CreateTypeInfo().AsType();
+ type.CreateType();
VerifyReturnType(method, typeof(void));
}
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;
ilGenerator.Emit(OpCodes.Ret);
module.CreateGlobalFunctions();
+ if (!PlatformDetection.IsMonoRuntime) // [ActiveIssue("https://github.com/dotnet/runtime/issues/72858", TestRuntimes.Mono)]
+ {
+ Assert.Null(method.DeclaringType);
+ }
}
[Fact]
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]
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());
}
}
{
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));
}
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 { }
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();
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);
{
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);
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)
{
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);
methodILGenerator.Emit(OpCodes.Ldarg_1);
methodILGenerator.Emit(OpCodes.Ret);
- type.CreateTypeInfo().AsType();
+ type.CreateType();
Assert.Throws<InvalidOperationException>(() => property.AddOtherMethod(method));
}
}
methodILGenerator.Emit(OpCodes.Ret);
property.AddOtherMethod(method);
- Type myType = type.CreateTypeInfo().AsType();
+ Type myType = type.CreateType();
Assert.Throws<NotSupportedException>(() => property.GetIndexParameters());
}
}
methodILGenerator.Emit(OpCodes.Ret);
property.AddOtherMethod(method);
- type.CreateTypeInfo().AsType();
+ type.CreateType();
Assert.Throws<NotSupportedException>(() => property.GetValue(null, null));
}
}
property.SetGetMethod(method);
- Type createdType = type.CreateTypeInfo().AsType();
+ Type createdType = type.CreateType();
PropertyInfo createdProperty = createdType.GetProperty("TestProperty", bindingAttributes);
Assert.Equal(defaultValue, createdProperty.GetConstantValue());
}
methodILGenerator.Emit(OpCodes.Ldarg_1);
methodILGenerator.Emit(OpCodes.Ret);
- type.CreateTypeInfo().AsType();
+ type.CreateType();
Assert.Throws<InvalidOperationException>(() => property.SetConstant(1));
}
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();
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));
}
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();
ConstructorInfo con = typeof(IntPropertyAttribute).GetConstructor(new Type[] { typeof(int) });
- type.CreateTypeInfo().AsType();
+ type.CreateType();
Assert.Throws<InvalidOperationException>(() => property.SetCustomAttribute(con, new byte[6]));
}
}
methodILGenerator.Emit(OpCodes.Ldfld, field);
methodILGenerator.Emit(OpCodes.Ret);
- type.CreateTypeInfo().AsType();
+ type.CreateType();
Assert.Throws<InvalidOperationException>(() => property.SetGetMethod(method));
}
}
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); });
}
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));
}
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));
}
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);
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));
}
public void AddInterfaceImplementation_TypeAlreadyCreated_ThrowsInvalidOperationException()
{
TypeBuilder type = Helpers.DynamicType(TypeAttributes.Public);
- type.CreateTypeInfo().AsType();
+ type.CreateType();
Assert.Throws<InvalidOperationException>(() => type.AddInterfaceImplementation(typeof(EmptyNonGenericInterface1)));
}
{
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();
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);
}
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);
}
}
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());
TypeBuilder type = Helpers.DynamicType(TypeAttributes.NotPublic);
type.DefineNestedType("NestedType");
- Type createdType = type.CreateTypeInfo().AsType();
+ Type createdType = type.CreateType();
Assert.Equal(type.Name, createdType.Name);
}
TypeBuilder type = Helpers.DynamicType(TypeAttributes.NotPublic);
type.DefineGenericParameters("T");
- Type createdType = type.CreateTypeInfo().AsType();
+ Type createdType = type.CreateType();
Assert.Equal(type.Name, createdType.Name);
}
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);
}
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());
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]));
}
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);
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());
public void DefineDefaultConstructor_TypeCreated_ThrowsInvalidOperationException()
{
TypeBuilder type = Helpers.DynamicType(TypeAttributes.Public);
- type.CreateTypeInfo().AsType();
+ type.CreateType();
Assert.Throws<InvalidOperationException>(() => type.DefineDefaultConstructor(MethodAttributes.Public));
}
constructorIlGenerator.Emit(OpCodes.Ret);
- Type createdType = type.CreateTypeInfo().AsType();
+ Type createdType = type.CreateType();
TypeBuilder nestedType = Helpers.DynamicType(TypeAttributes.Public | TypeAttributes.Class);
nestedType.SetParent(createdType);
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);
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));
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);
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)));
}
{
TypeBuilder type = Helpers.DynamicType(TypeAttributes.Class | TypeAttributes.Public);
type.DefineEvent("Name", EventAttributes.None, typeof(int).MakeByRefType());
- type.CreateTypeInfo().AsType();
+ type.CreateType();
}
[Fact]
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);
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);
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);
}
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);
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";
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));
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]);
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));
}
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));
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);
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);
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));
}
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));
}
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));
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);
}
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);
}
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);
}
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);
}
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);
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)));
}
public void DefineTypeInitializer_TypeCreated_ThrowsInvalidOperationException()
{
TypeBuilder type = Helpers.DynamicType(TypeAttributes.Public);
- type.CreateTypeInfo().AsType();
+ type.CreateType();
Assert.Throws<InvalidOperationException>(() => type.DefineTypeInitializer());
}
public void Guid_TypeCreated_NotEmpty()
{
TypeBuilder type = Helpers.DynamicType(TypeAttributes.NotPublic);
- type.CreateTypeInfo().AsType();
+ type.CreateType();
Assert.NotEqual(Guid.Empty, type.GUID);
}
ilGenerator.EmitCall(OpCodes.Call, genericStringMethod, null);
ilGenerator.Emit(OpCodes.Ret);
- type1.CreateTypeInfo().AsType();
+ type1.CreateType();
Assert.True(type1.IsGenericTypeDefinition);
}
ilGenerator.EmitCall(OpCodes.Call, writeLine, null);
ilGenerator.Emit(OpCodes.Ret);
- type.CreateTypeInfo().AsType();
+ type.CreateType();
Assert.False(type.IsGenericTypeDefinition);
}
}
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);
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);
public void SetParent_TypeCreated_ThrowsInvalidOperationException()
{
TypeBuilder type = Helpers.DynamicType(TypeAttributes.NotPublic);
- type.CreateTypeInfo().AsType();
+ type.CreateType();
Assert.Throws<InvalidOperationException>(() => type.SetParent(typeof(string)));
}
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));
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));
ilGenerator.Emit(OpCodes.Ret);
// Generate the type and return the associated assembly
- return typeBuilder.CreateTypeInfo().AsType().Assembly;
+ return typeBuilder.CreateType().Assembly;
}
}
}
enumBuilder.DefineLiteral("Value1", true);
enumBuilder.DefineLiteral("Value2", false);
- return enumBuilder.CreateTypeInfo().AsType();
+ return enumBuilder.CreateType();
}
private static Type s_charEnumType = GetCharEnumType();
enumBuilder.DefineLiteral("Value0x0010", (char)0x0010);
enumBuilder.DefineLiteral("Value0x3f16", (char)0x3f16);
- return enumBuilder.CreateTypeInfo().AsType();
+ return enumBuilder.CreateType();
}
private static Type s_floatEnumType = GetFloatEnumType();
enumBuilder.DefineLiteral("Value0x0010", (float)0x0010);
enumBuilder.DefineLiteral("Value0x3f16", (float)0x3f16);
- return enumBuilder.CreateTypeInfo().AsType();
+ return enumBuilder.CreateType();
}
private static Type s_doubleEnumType = GetDoubleEnumType();
enumBuilder.DefineLiteral("Value0x0010", (double)0x0010);
enumBuilder.DefineLiteral("Value0x3f16", (double)0x3f16);
- return enumBuilder.CreateTypeInfo().AsType();
+ return enumBuilder.CreateType();
}
private static Type s_intPtrEnumType = GetIntPtrEnumType();
if (enumBuilder == null)
return null;
- return enumBuilder.CreateTypeInfo().AsType();
+ return enumBuilder.CreateType();
}
private static Type s_uintPtrEnumType = GetUIntPtrEnumType();
if (enumBuilder == null)
return null;
- return enumBuilder.CreateTypeInfo().AsType();
+ return enumBuilder.CreateType();
}
}
}
attributeTypeBuilder.SetCustomAttribute(customAttributeBuilder);
// Make the TypeInfo real so the constructor can be used.
- return attributeTypeBuilder.CreateTypeInfo()!.DeclaredConstructors.Single();
+ return attributeTypeBuilder.CreateTypeInfo().DeclaredConstructors.Single();
}
}