Skip to content

Commit

Permalink
Remove those pesky .GetTypeInfo()
Browse files Browse the repository at this point in the history
  • Loading branch information
stakx committed May 14, 2020
1 parent c328a6b commit f22a484
Show file tree
Hide file tree
Showing 79 changed files with 235 additions and 240 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,42 +29,42 @@ public class BasicClassProxyTestCase : BasePEVerifyTestCase
public void ProxyForBaseTypeFromUnsignedAssembly()
{
Type t = typeof(Class);
Assert.False(StrongNameUtil.IsAssemblySigned(t.GetTypeInfo().Assembly));
Assert.False(StrongNameUtil.IsAssemblySigned(t.Assembly));
object proxy = generator.CreateClassProxy(t, new StandardInterceptor());
Assert.False(StrongNameUtil.IsAssemblySigned(proxy.GetType().GetTypeInfo().Assembly));
Assert.False(StrongNameUtil.IsAssemblySigned(proxy.GetType().Assembly));
}

[Test]
public void ProxyForBaseTypeAndInterfaceFromUnsignedAssembly()
{
Type t1 = typeof(Class);
Type t2 = typeof(IInterface);
Assert.IsFalse(StrongNameUtil.IsAssemblySigned(t1.GetTypeInfo().Assembly));
Assert.IsFalse(StrongNameUtil.IsAssemblySigned(t2.GetTypeInfo().Assembly));
Assert.IsFalse(StrongNameUtil.IsAssemblySigned(t1.Assembly));
Assert.IsFalse(StrongNameUtil.IsAssemblySigned(t2.Assembly));
object proxy = generator.CreateClassProxy(t1, new Type[] { t2 }, new StandardInterceptor());
Assert.IsFalse(StrongNameUtil.IsAssemblySigned(proxy.GetType().GetTypeInfo().Assembly));
Assert.IsFalse(StrongNameUtil.IsAssemblySigned(proxy.GetType().Assembly));
}

[Test]
public void ProxyForBaseTypeAndInterfaceFromSignedAndUnsignedAssemblies1()
{
Type t1 = typeof(Class);
Type t2 = typeof(IServiceProvider);
Assert.IsFalse(StrongNameUtil.IsAssemblySigned(t1.GetTypeInfo().Assembly));
Assert.IsTrue(StrongNameUtil.IsAssemblySigned(t2.GetTypeInfo().Assembly));
Assert.IsFalse(StrongNameUtil.IsAssemblySigned(t1.Assembly));
Assert.IsTrue(StrongNameUtil.IsAssemblySigned(t2.Assembly));
object proxy = generator.CreateClassProxy(t1, new Type[] { t2 }, new StandardInterceptor());
Assert.IsFalse(StrongNameUtil.IsAssemblySigned(proxy.GetType().GetTypeInfo().Assembly));
Assert.IsFalse(StrongNameUtil.IsAssemblySigned(proxy.GetType().Assembly));
}

[Test]
public void ProxyForBaseTypeAndInterfaceFromSignedAndUnsignedAssemblies2()
{
Type t1 = typeof(List<int>);
Type t2 = typeof(IInterface);
Assert.IsTrue(StrongNameUtil.IsAssemblySigned(t1.GetTypeInfo().Assembly));
Assert.IsFalse(StrongNameUtil.IsAssemblySigned(t2.GetTypeInfo().Assembly));
Assert.IsTrue(StrongNameUtil.IsAssemblySigned(t1.Assembly));
Assert.IsFalse(StrongNameUtil.IsAssemblySigned(t2.Assembly));
object proxy = generator.CreateClassProxy(t1, new Type[] { t2 }, new StandardInterceptor());
Assert.IsFalse(StrongNameUtil.IsAssemblySigned(proxy.GetType().GetTypeInfo().Assembly));
Assert.IsFalse(StrongNameUtil.IsAssemblySigned(proxy.GetType().Assembly));
}

public abstract class Class
Expand Down
2 changes: 1 addition & 1 deletion src/Castle.Core.Tests.WeakNamed/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ internal class Program
{
public static int Main(string[] args)
{
return new AutoRun(typeof(Program).GetTypeInfo().Assembly)
return new AutoRun(typeof(Program).Assembly)
.Execute(args, new ExtendedTextWrapper(Console.Out), Console.In);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1322,7 +1322,7 @@ public void CanGetNewGuidPropertyOnDemand()
public void CanDetermineTheAdaptedInterface()
{
var person = factory.GetAdapter<IPerson>(dictionary);
var type = person.GetType().GetTypeInfo().GetCustomAttributes(
var type = person.GetType().GetCustomAttributes(
typeof(DictionaryAdapterAttribute), false).Cast<DictionaryAdapterAttribute>()
.FirstOrDefault();
Assert.IsNotNull(type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void EnumeratorIteration()
public void Using_anonymous_types_works_without_exception()
{
var target = new { foo = 1, name = "john", age = 25 };
Assert.IsFalse(target.GetType().GetTypeInfo().IsPublic);
Assert.IsFalse(target.GetType().IsPublic);
var dict = new ReflectionBasedDictionaryAdapter(target);

Assert.AreEqual(3, dict.Count);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void SetUp()
}

private AssemblyResourceFactory resFactory;
private static readonly String AssemblyName = typeof(AssemblyResourceFactoryTestCase).GetTypeInfo().Assembly.FullName;
private static readonly String AssemblyName = typeof(AssemblyResourceFactoryTestCase).Assembly.FullName;
private const String ResPath = "Resources";

[Test]
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public class AttributedClass_ReflectionPermission
private int AttributeCount<TAttribute>(object proxy)
where TAttribute : Attribute
{
return proxy.GetType().GetTypeInfo().GetCustomAttributes(typeof(TAttribute), false).Count();
return proxy.GetType().GetCustomAttributes(typeof(TAttribute), false).Count();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void ProxyForNonPublicClass()
{
// We need to use a type that is not from our assembly, because we are marked as internals visible to DynamicProxy2
var type = Type.GetType("System.Text.Latin1Encoding");
Assert.True(type.GetTypeInfo().IsNotPublic); // Just ensure it is internal as a good use case for this test
Assert.True(type.IsNotPublic); // Just ensure it is internal as a good use case for this test

var ex = Assert.Throws<GeneratorException>(() => generator.CreateClassProxy(type, new StandardInterceptor()));
StringAssert.StartsWith(
Expand Down Expand Up @@ -307,9 +307,9 @@ public void ProxyForBaseTypeFromSignedAssembly()
{
const bool shouldBeSigned = true;
Type t = typeof(List<object>);
Assert.IsTrue(StrongNameUtil.IsAssemblySigned(t.GetTypeInfo().Assembly));
Assert.IsTrue(StrongNameUtil.IsAssemblySigned(t.Assembly));
object proxy = generator.CreateClassProxy(t, new StandardInterceptor());
Assert.AreEqual(shouldBeSigned, StrongNameUtil.IsAssemblySigned(proxy.GetType().GetTypeInfo().Assembly));
Assert.AreEqual(shouldBeSigned, StrongNameUtil.IsAssemblySigned(proxy.GetType().Assembly));
}

[Test]
Expand All @@ -318,10 +318,10 @@ public void ProxyForBaseTypeAndInterfaceFromSignedAssembly()
const bool shouldBeSigned = true;
Type t1 = typeof(List<object>);
Type t2 = typeof(IServiceProvider);
Assert.IsTrue(StrongNameUtil.IsAssemblySigned(t1.GetTypeInfo().Assembly));
Assert.IsTrue(StrongNameUtil.IsAssemblySigned(t2.GetTypeInfo().Assembly));
Assert.IsTrue(StrongNameUtil.IsAssemblySigned(t1.Assembly));
Assert.IsTrue(StrongNameUtil.IsAssemblySigned(t2.Assembly));
object proxy = generator.CreateClassProxy(t1, new Type[] { t2 }, new StandardInterceptor());
Assert.AreEqual(shouldBeSigned, StrongNameUtil.IsAssemblySigned(proxy.GetType().GetTypeInfo().Assembly));
Assert.AreEqual(shouldBeSigned, StrongNameUtil.IsAssemblySigned(proxy.GetType().Assembly));
}

[Test]
Expand Down Expand Up @@ -400,7 +400,7 @@ public void ClassImplementingInterfaceVitrually()
var baseMethod = @class.GetMethod("Do");
var interceptor = new SetReturnValueInterceptor(123);
var proxy = generator.CreateClassProxy(@class, new[] {@interface}, interceptor);
var mapping = proxy.GetType().GetTypeInfo().GetRuntimeInterfaceMap(@interface);
var mapping = proxy.GetType().GetInterfaceMap(@interface);

Assert.AreEqual(mapping.TargetMethods[0].GetBaseDefinition(), baseMethod);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public void Should_implement_explicitly_duplicate_interface_members()
generator.CreateInterfaceProxyWithoutTarget(typeof(IIdenticalOne), new[] { typeof(IIdenticalTwo) }).GetType();
MethodInfo method = type.GetMethod("Foo", BindingFlags.Instance | BindingFlags.Public);
Assert.IsNotNull(method);
Assert.AreSame(method, type.GetTypeInfo().GetRuntimeInterfaceMap(typeof(IIdenticalOne)).TargetMethods[0]);
Assert.AreSame(method, type.GetInterfaceMap(typeof(IIdenticalOne)).TargetMethods[0]);
MethodInfo method2 = type.GetMethod("Castle.DynamicProxy.Tests.Interfaces.IIdenticalTwo.Foo", BindingFlags.Instance | BindingFlags.Public);
Assert.IsNotNull(method2);
}
Expand All @@ -225,15 +225,15 @@ public void Should_choose_noncolliding_method_names_when_implementing_same_gener
boolInterfaceType,
new[] { intInterfaceType, nestedGenericBoolInterfaceType });

var type = proxy.GetType().GetTypeInfo();
var type = proxy.GetType();

var boolMethod = type.GetRuntimeInterfaceMap(boolInterfaceType).TargetMethods[0];
var boolMethod = type.GetInterfaceMap(boolInterfaceType).TargetMethods[0];
Assert.AreEqual("SomeMethod", boolMethod.Name);

var intMethod = type.GetRuntimeInterfaceMap(intInterfaceType).TargetMethods[0];
var intMethod = type.GetInterfaceMap(intInterfaceType).TargetMethods[0];
Assert.AreEqual("Castle.DynamicProxy.Tests.Interfaces.IGenericWithNonGenericMethod`1[Int32].SomeMethod", intMethod.Name);

var nestedGenericBoolMethod = type.GetRuntimeInterfaceMap(nestedGenericBoolInterfaceType).TargetMethods[0];
var nestedGenericBoolMethod = type.GetInterfaceMap(nestedGenericBoolInterfaceType).TargetMethods[0];
Assert.AreEqual("Castle.DynamicProxy.Tests.Interfaces.IGenericWithNonGenericMethod`1[IGenericWithNonGenericMethod`1[Boolean]].SomeMethod", nestedGenericBoolMethod.Name);
}

Expand All @@ -248,20 +248,20 @@ public void Should_choose_noncolliding_property_accessor_names_when_implementing
boolInterfaceType,
new[] { intInterfaceType, nestedGenericBoolInterfaceType });

var type = proxy.GetType().GetTypeInfo();
var type = proxy.GetType();

var boolGetter = type.GetRuntimeInterfaceMap(boolInterfaceType).TargetMethods[0];
var boolSetter = type.GetRuntimeInterfaceMap(boolInterfaceType).TargetMethods[1];
var boolGetter = type.GetInterfaceMap(boolInterfaceType).TargetMethods[0];
var boolSetter = type.GetInterfaceMap(boolInterfaceType).TargetMethods[1];
Assert.AreEqual("get_SomeProperty", boolGetter.Name);
Assert.AreEqual("set_SomeProperty", boolSetter.Name);

var intGetter = type.GetRuntimeInterfaceMap(intInterfaceType).TargetMethods[0];
var intSetter = type.GetRuntimeInterfaceMap(intInterfaceType).TargetMethods[1];
var intGetter = type.GetInterfaceMap(intInterfaceType).TargetMethods[0];
var intSetter = type.GetInterfaceMap(intInterfaceType).TargetMethods[1];
Assert.AreEqual("Castle.DynamicProxy.Tests.Interfaces.IGenericWithProperty`1[Int32].get_SomeProperty", intGetter.Name);
Assert.AreEqual("Castle.DynamicProxy.Tests.Interfaces.IGenericWithProperty`1[Int32].set_SomeProperty", intSetter.Name);

var nestedGenericBoolGetter = type.GetRuntimeInterfaceMap(nestedGenericBoolInterfaceType).TargetMethods[0];
var nestedGenericBoolSetter = type.GetRuntimeInterfaceMap(nestedGenericBoolInterfaceType).TargetMethods[1];
var nestedGenericBoolGetter = type.GetInterfaceMap(nestedGenericBoolInterfaceType).TargetMethods[0];
var nestedGenericBoolSetter = type.GetInterfaceMap(nestedGenericBoolInterfaceType).TargetMethods[1];
Assert.AreEqual("Castle.DynamicProxy.Tests.Interfaces.IGenericWithProperty`1[IGenericWithProperty`1[Boolean]].get_SomeProperty", nestedGenericBoolGetter.Name);
Assert.AreEqual("Castle.DynamicProxy.Tests.Interfaces.IGenericWithProperty`1[IGenericWithProperty`1[Boolean]].set_SomeProperty", nestedGenericBoolSetter.Name);
}
Expand All @@ -277,20 +277,20 @@ public void Should_choose_noncolliding_event_accessor_names_when_implementing_sa
boolInterfaceType,
new[] { intInterfaceType, nestedGenericBoolInterfaceType });

var type = proxy.GetType().GetTypeInfo();
var type = proxy.GetType();

var boolAdder = type.GetRuntimeInterfaceMap(boolInterfaceType).TargetMethods[0];
var boolRemover = type.GetRuntimeInterfaceMap(boolInterfaceType).TargetMethods[1];
var boolAdder = type.GetInterfaceMap(boolInterfaceType).TargetMethods[0];
var boolRemover = type.GetInterfaceMap(boolInterfaceType).TargetMethods[1];
Assert.AreEqual("add_SomeEvent", boolAdder.Name);
Assert.AreEqual("remove_SomeEvent", boolRemover.Name);

var intAdder = type.GetRuntimeInterfaceMap(intInterfaceType).TargetMethods[0];
var intRemover = type.GetRuntimeInterfaceMap(intInterfaceType).TargetMethods[1];
var intAdder = type.GetInterfaceMap(intInterfaceType).TargetMethods[0];
var intRemover = type.GetInterfaceMap(intInterfaceType).TargetMethods[1];
Assert.AreEqual("Castle.DynamicProxy.Tests.Interfaces.IGenericWithEvent`1[Int32].add_SomeEvent", intAdder.Name);
Assert.AreEqual("Castle.DynamicProxy.Tests.Interfaces.IGenericWithEvent`1[Int32].remove_SomeEvent", intRemover.Name);

var nestedGenericBoolAdder = type.GetRuntimeInterfaceMap(nestedGenericBoolInterfaceType).TargetMethods[0];
var nestedGenericBoolRemover = type.GetRuntimeInterfaceMap(nestedGenericBoolInterfaceType).TargetMethods[1];
var nestedGenericBoolAdder = type.GetInterfaceMap(nestedGenericBoolInterfaceType).TargetMethods[0];
var nestedGenericBoolRemover = type.GetInterfaceMap(nestedGenericBoolInterfaceType).TargetMethods[1];
Assert.AreEqual("Castle.DynamicProxy.Tests.Interfaces.IGenericWithEvent`1[IGenericWithEvent`1[Boolean]].add_SomeEvent", nestedGenericBoolAdder.Name);
Assert.AreEqual("Castle.DynamicProxy.Tests.Interfaces.IGenericWithEvent`1[IGenericWithEvent`1[Boolean]].remove_SomeEvent", nestedGenericBoolRemover.Name);
}
Expand All @@ -306,15 +306,15 @@ public void Should_choose_noncolliding_member_names_when_implementing_same_gener
boolIntInterfaceType,
new[] { intBoolInterfaceType, intNestedGenericBoolInterfaceType });

var type = proxy.GetType().GetTypeInfo();
var type = proxy.GetType();

var boolIntMethod = type.GetRuntimeInterfaceMap(boolIntInterfaceType).TargetMethods[0];
var boolIntMethod = type.GetInterfaceMap(boolIntInterfaceType).TargetMethods[0];
Assert.AreEqual("SomeMethod", boolIntMethod.Name);

var intBoolMethod = type.GetRuntimeInterfaceMap(intBoolInterfaceType).TargetMethods[0];
var intBoolMethod = type.GetInterfaceMap(intBoolInterfaceType).TargetMethods[0];
Assert.AreEqual("Castle.DynamicProxy.Tests.Interfaces.IGenericWithNonGenericMethod`2[Int32,Boolean].SomeMethod", intBoolMethod.Name);

var intNestedGenericBoolMethod = type.GetRuntimeInterfaceMap(intNestedGenericBoolInterfaceType).TargetMethods[0];
var intNestedGenericBoolMethod = type.GetInterfaceMap(intNestedGenericBoolInterfaceType).TargetMethods[0];
Assert.AreEqual("Castle.DynamicProxy.Tests.Interfaces.IGenericWithNonGenericMethod`2[Int32,IGenericWithNonGenericMethod`1[Boolean]].SomeMethod", intNestedGenericBoolMethod.Name);
}

Expand Down
8 changes: 4 additions & 4 deletions src/Castle.Core.Tests/DynamicProxy.Tests/CacheKeyTestCase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ public void EquivalentOptions()
[Test]
public void EqualWithProxyForType()
{
CacheKey key1 = new CacheKey(typeof (NonPublicConstructorClass).GetTypeInfo(), null, null, ProxyGenerationOptions.Default);
CacheKey key2 = new CacheKey(typeof (NonPublicConstructorClass).GetTypeInfo(), null, null, ProxyGenerationOptions.Default);
CacheKey key1 = new CacheKey(typeof (NonPublicConstructorClass), null, null, ProxyGenerationOptions.Default);
CacheKey key2 = new CacheKey(typeof (NonPublicConstructorClass), null, null, ProxyGenerationOptions.Default);

Assert.AreEqual(key1, key2);

Expand All @@ -127,8 +127,8 @@ public void EqualWithProxyForType()
[Test]
public void EqualNullAndEmptyInterfaces()
{
CacheKey key1 = new CacheKey(typeof (NonPublicConstructorClass).GetTypeInfo(), null, null, ProxyGenerationOptions.Default);
CacheKey key2 = new CacheKey(typeof (NonPublicConstructorClass).GetTypeInfo(), null, Type.EmptyTypes,
CacheKey key1 = new CacheKey(typeof (NonPublicConstructorClass), null, null, ProxyGenerationOptions.Default);
CacheKey key2 = new CacheKey(typeof (NonPublicConstructorClass), null, Type.EmptyTypes,
ProxyGenerationOptions.Default);

Assert.AreEqual(key1, key2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void On_class()

var proxy = generator.CreateClassProxy(typeof(CanDefineAdditionalCustomAttributes), options);

Assert.IsTrue(proxy.GetType().GetTypeInfo().IsDefined(typeof(__Protect), false));
Assert.IsTrue(proxy.GetType().IsDefined(typeof(__Protect), false));
}

[Test]
Expand All @@ -63,7 +63,7 @@ public void On_interfaces()

var proxy = generator.CreateInterfaceProxyWithoutTarget(typeof(IDisposable), new Type[0], options);

Assert.IsTrue(proxy.GetType().GetTypeInfo().IsDefined(typeof(__Protect), false));
Assert.IsTrue(proxy.GetType().IsDefined(typeof(__Protect), false));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void ForceUnsignedFalseWithSignedTypes()
ClassEmitter emitter = new ClassEmitter(generator.ProxyBuilder.ModuleScope, "Foo", typeof (object), Type.EmptyTypes,
TypeAttributes.Public, false);
Type t = emitter.BuildType();
Assert.AreEqual(shouldBeSigned, StrongNameUtil.IsAssemblySigned(t.GetTypeInfo().Assembly));
Assert.AreEqual(shouldBeSigned, StrongNameUtil.IsAssemblySigned(t.Assembly));
}

[Test]
Expand All @@ -82,7 +82,7 @@ public void ForceUnsignedTrueWithSignedTypes()
ClassEmitter emitter = new ClassEmitter(generator.ProxyBuilder.ModuleScope, "Foo", typeof (object), Type.EmptyTypes,
TypeAttributes.Public, true);
Type t = emitter.BuildType();
Assert.IsFalse(StrongNameUtil.IsAssemblySigned(t.GetTypeInfo().Assembly));
Assert.IsFalse(StrongNameUtil.IsAssemblySigned(t.Assembly));
}

[Test]
Expand Down Expand Up @@ -115,7 +115,7 @@ public void UsingClassEmitterForInterfaces()
emitter.CreateMethod("MyMethod", MethodAttributes.Public | MethodAttributes.Abstract | MethodAttributes.Virtual,
typeof(void), Type.EmptyTypes);
Type t = emitter.BuildType();
Assert.IsTrue(t.GetTypeInfo().IsInterface);
Assert.IsTrue(t.IsInterface);
MethodInfo method = t.GetMethod("MyMethod");
Assert.IsNotNull(method);
}
Expand Down Expand Up @@ -169,7 +169,7 @@ public void NestedInterface()
typeof(void), Type.EmptyTypes);
Type inner = innerEmitter.BuildType();
Type outer = outerEmitter.BuildType();
Assert.IsTrue(inner.GetTypeInfo().IsInterface);
Assert.IsTrue(inner.IsInterface);
MethodInfo method = inner.GetMethod("MyMethod");
Assert.IsNotNull(method);
Assert.AreSame(inner, outer.GetNestedType("IInner", BindingFlags.Public));
Expand Down
Loading

0 comments on commit f22a484

Please sign in to comment.