Skip to content

Commit

Permalink
remove GetTypeInfo usage (#6727)
Browse files Browse the repository at this point in the history
Co-authored-by: Aaron Stannard <aaron@petabridge.com>
  • Loading branch information
SimonCropp and Aaronontheweb authored May 5, 2023
1 parent 30fbb2d commit 8f13c74
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace Akka.TestKit.Xunit.Internals
public class AkkaAssertEqualityComparer<T> : IEqualityComparer<T>
{
private static readonly IEqualityComparer DefaultInnerComparer = new AkkaAssertEqualityComparerAdapter<object>(new AkkaAssertEqualityComparer<object>());
private static readonly TypeInfo NullableTypeInfo = typeof(Nullable<>).GetTypeInfo();
private static readonly Type NullableType = typeof(Nullable<>);

private readonly Func<IEqualityComparer> _innerComparerFactory;
private readonly bool _skipTypeCheck;
Expand All @@ -43,10 +43,10 @@ public AkkaAssertEqualityComparer(bool skipTypeCheck = false, IEqualityComparer

public bool Equals(T x, T y)
{
var typeInfo = typeof(T).GetTypeInfo();
var type = typeof(T);

// Null?
if(!typeInfo.IsValueType || (typeInfo.IsGenericType && typeInfo.GetGenericTypeDefinition().GetTypeInfo().IsAssignableFrom(NullableTypeInfo)))
if(!type.IsValueType || (type.IsGenericType && type.GetGenericTypeDefinition().IsAssignableFrom(NullableType)))
{
if(object.Equals(x, default(T)))
return object.Equals(y, default(T));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace Akka.TestKit.Xunit2.Internals
public class AkkaAssertEqualityComparer<T> : IEqualityComparer<T>
{
private static readonly IEqualityComparer DefaultInnerComparer = new AkkaAssertEqualityComparerAdapter<object>(new AkkaAssertEqualityComparer<object>());
private static readonly TypeInfo NullableTypeInfo = typeof(Nullable<>).GetTypeInfo();
private static readonly Type NullableType = typeof(Nullable<>);

private readonly Func<IEqualityComparer> _innerComparerFactory;
private readonly bool _skipTypeCheck;
Expand All @@ -43,10 +43,10 @@ public AkkaAssertEqualityComparer(bool skipTypeCheck = false, IEqualityComparer

public bool Equals(T x, T y)
{
var typeInfo = typeof(T).GetTypeInfo();
var type = typeof(T);

// Null?
if(!typeInfo.IsValueType || (typeInfo.IsGenericType && typeInfo.GetGenericTypeDefinition().GetTypeInfo().IsAssignableFrom(NullableTypeInfo)))
if(!type.IsValueType || (type.IsGenericType && type.GetGenericTypeDefinition().IsAssignableFrom(NullableType)))
{
if(object.Equals(x, default(T)))
return object.Equals(y, default(T));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static Config Default()
/// <returns>The configuration defined in the current executing assembly.</returns>
internal static Config FromResource(string resourceName)
{
var assembly = typeof(ClusterConfigFactory).GetTypeInfo().Assembly;
var assembly = typeof(ClusterConfigFactory).Assembly;

using (var stream = assembly.GetManifestResourceStream(resourceName))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public override byte[] ToBinary(object obj)
if (obj is AtomicWrite aw) return GetAtomicWrite(aw).ToByteArray();
if (obj is AtLeastOnceDeliverySnapshot snap) return GetAtLeastOnceDeliverySnapshot(snap).ToByteArray();
if (obj is PersistentFSM.StateChangeEvent stateEvent) return GetStateChangeEvent(stateEvent).ToByteArray();
if (obj.GetType().GetTypeInfo().IsGenericType
if (obj.GetType().IsGenericType
&& obj.GetType().GetGenericTypeDefinition() == typeof(PersistentFSM.PersistentFSMSnapshot<>)) return GetPersistentFSMSnapshot(obj).ToByteArray();

throw new ArgumentException($"Can't serialize object of type [{obj.GetType()}] in [{GetType()}]");
Expand Down Expand Up @@ -156,7 +156,7 @@ public override object FromBinary(byte[] bytes, Type type)
if (type == typeof(AtomicWrite)) return GetAtomicWrite(bytes);
if (type == typeof(AtLeastOnceDeliverySnapshot)) return GetAtLeastOnceDeliverySnapshot(bytes);
if (type == typeof(PersistentFSM.StateChangeEvent)) return GetStateChangeEvent(bytes);
if (type.GetTypeInfo().IsGenericType
if (type.IsGenericType
&& type.GetGenericTypeDefinition() == typeof(PersistentFSM.PersistentFSMSnapshot<>)) return GetPersistentFSMSnapshot(type, bytes);

throw new SerializationException($"Unimplemented deserialization of message with type [{type}] in [{GetType()}]");
Expand Down
2 changes: 1 addition & 1 deletion src/core/Akka.Remote/Configuration/RemoteConfigFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static Config Default()
/// <returns>The configuration defined in the current executing assembly.</returns>
internal static Config FromResource(string resourceName)
{
var assembly = typeof(RemoteConfigFactory).GetTypeInfo().Assembly;
var assembly = typeof(RemoteConfigFactory).Assembly;

using (var stream = assembly.GetManifestResourceStream(resourceName))
{
Expand Down
2 changes: 1 addition & 1 deletion src/core/Akka.Streams/Implementation/Fusing/Fusing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ private bool IsCopiedModuleWithGraphStageAndMaterializedValue(IModule module)
Type stageType;
return copiedModule != null
&& (graphStageModule = copiedModule.CopyOf as GraphStageModule) != null
&& (stageType = graphStageModule.Stage.GetType()).GetTypeInfo().IsGenericType
&& (stageType = graphStageModule.Stage.GetType()).IsGenericType
&& stageType.GetGenericTypeDefinition() == typeof(MaterializedValueSource<>);
}

Expand Down
4 changes: 2 additions & 2 deletions src/core/Akka.Streams/Util/TypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static Type GetSubscribedType(this Type type)
return
type
.GetInterfaces()
.Single(i => i.GetTypeInfo().IsGenericType && i.GetGenericTypeDefinition() == typeof (ISubscriber<>))
.Single(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof (ISubscriber<>))
.GetGenericArguments()
.First();
}
Expand All @@ -42,7 +42,7 @@ public static Type GetPublishedType(this Type type)
return
type
.GetInterfaces()
.Single(i => i.GetTypeInfo().IsGenericType && i.GetGenericTypeDefinition() == typeof (IPublisher<>))
.Single(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof (IPublisher<>))
.GetGenericArguments()
.First();
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/Akka.TestKit.Tests/TestKit_Config_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void DefaultValues_should_be_correct()
TestKitSettings.SingleExpectDefault.ShouldBe(TimeSpan.FromSeconds(3));
TestKitSettings.TestEventFilterLeeway.ShouldBe(TimeSpan.FromSeconds(3));
TestKitSettings.TestTimeFactor.ShouldBe(1);
var callingThreadDispatcherTypeName = typeof(CallingThreadDispatcherConfigurator).FullName + ", " + typeof(CallingThreadDispatcher).GetTypeInfo().Assembly.GetName().Name;
var callingThreadDispatcherTypeName = typeof(CallingThreadDispatcherConfigurator).FullName + ", " + typeof(CallingThreadDispatcher).Assembly.GetName().Name;
Assert.False(Sys.Settings.Config.IsEmpty);
Sys.Settings.Config.GetString("akka.test.calling-thread-dispatcher.type", null).ShouldBe(callingThreadDispatcherTypeName);
Sys.Settings.Config.GetString("akka.test.test-actor.dispatcher.type", null).ShouldBe(callingThreadDispatcherTypeName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ private static void AssertAreSame(object[] delegateArguments, object[] updatedAr
{
for(int i = 0; i < delegateArguments.Length; i++)
{
if(delegateArguments[i].GetType().GetTypeInfo().IsValueType)
if(delegateArguments[i].GetType().IsValueType)
Assert.Equal(delegateArguments[i], updatedArgs[i]);
else
Assert.Same(delegateArguments[i], updatedArgs[i]);
Expand Down
8 changes: 4 additions & 4 deletions src/core/Akka.Tests/Serialization/SerializationSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -562,11 +562,11 @@ public void Can_apply_a_config_based_serializer_by_the_binding()

private static string LegacyTypeQualifiedName(Type type)
{
string coreAssemblyName = typeof(object).GetTypeInfo().Assembly.GetName().Name;
var assemblyName = type.GetTypeInfo().Assembly.GetName().Name;
string coreAssemblyName = typeof(object).Assembly.GetName().Name;
var assemblyName = type.Assembly.GetName().Name;
var shortened = assemblyName.Equals(coreAssemblyName)
? type.GetTypeInfo().FullName
: $"{type.GetTypeInfo().FullName}, {assemblyName}";
? type.FullName
: $"{type.FullName}, {assemblyName}";
return shortened;
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/Akka/Actor/Internal/ActorSystemImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ private void LoadExtensions()
foreach(var extensionFqn in _settings.Config.GetStringList("akka.extensions", new string[] { }))
{
var extensionType = Type.GetType(extensionFqn);
if(extensionType == null || !typeof(IExtensionId).IsAssignableFrom(extensionType) || extensionType.GetTypeInfo().IsAbstract || !extensionType.GetTypeInfo().IsClass)
if(extensionType == null || !typeof(IExtensionId).IsAssignableFrom(extensionType) || extensionType.IsAbstract || !extensionType.IsClass)
{
_log.Error("[{0}] is not an 'ExtensionId', skipping...", extensionFqn);
continue;
Expand Down
8 changes: 4 additions & 4 deletions src/core/Akka/Configuration/ConfigurationFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public static Config Default()
/// <returns>The configuration defined in the current executing assembly.</returns>
internal static Config FromResource(string resourceName)
{
var assembly = typeof(ConfigurationFactory).GetTypeInfo().Assembly;
var assembly = typeof(ConfigurationFactory).Assembly;

return FromResource(resourceName, assembly);
}
Expand All @@ -98,9 +98,9 @@ internal static Config FromResource(string resourceName)
public static Config FromResource(string resourceName, object instanceInAssembly)
{
if (instanceInAssembly is Type type)
return FromResource(resourceName, type.GetTypeInfo().Assembly);
return FromResource(resourceName, type.Assembly);
var assembly = instanceInAssembly as Assembly;
return FromResource(resourceName, assembly != null ? assembly : instanceInAssembly.GetType().GetTypeInfo().Assembly);
return FromResource(resourceName, assembly != null ? assembly : instanceInAssembly.GetType().Assembly);
}

/// <summary>
Expand All @@ -112,7 +112,7 @@ public static Config FromResource(string resourceName, object instanceInAssembly
/// <returns>The configuration defined in the assembly that contains the type <typeparamref name="TAssembly"/>.</returns>
public static Config FromResource<TAssembly>(string resourceName)
{
return FromResource(resourceName, typeof(TAssembly).GetTypeInfo().Assembly);
return FromResource(resourceName, typeof(TAssembly).Assembly);
}

/// <summary>
Expand Down
16 changes: 8 additions & 8 deletions src/core/Akka/Dispatch/Mailboxes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ public Mailboxes(ActorSystem system)
/// <returns><c>true</c> if this actor has a message queue type requirement. <c>false</c> otherwise.</returns>
public bool HasRequiredType(Type actorType)
{
var interfaces = actorType.GetTypeInfo().GetInterfaces();
var interfaces = actorType.GetInterfaces();
for (int i = 0; i < interfaces.Length; i++)
{
var element = interfaces[i];
if (element.GetTypeInfo().IsGenericType && element.GetGenericTypeDefinition() == RequiresMessageQueueGenericType)
if (element.IsGenericType && element.GetGenericTypeDefinition() == RequiresMessageQueueGenericType)
{
return true;
}
Expand All @@ -108,11 +108,11 @@ public bool HasRequiredType(Type actorType)
/// <returns><c>true</c> if this mailboxtype produces queues. <c>false</c> otherwise.</returns>
public bool ProducesMessageQueue(Type mailboxType)
{
var interfaces = mailboxType.GetTypeInfo().GetInterfaces();
var interfaces = mailboxType.GetInterfaces();
for (int i = 0; i < interfaces.Length; i++)
{
var element = interfaces[i];
if (element.GetTypeInfo().IsGenericType && element.GetGenericTypeDefinition() == ProducesMessageQueueGenericType)
if (element.IsGenericType && element.GetGenericTypeDefinition() == ProducesMessageQueueGenericType)
{
return true;
}
Expand Down Expand Up @@ -229,11 +229,11 @@ private Config Config(string id)
/// <returns>TBD</returns>
public Type GetRequiredType(Type actorType)
{
var interfaces = actorType.GetTypeInfo().GetInterfaces();
var interfaces = actorType.GetInterfaces();
for (int i = 0; i < interfaces.Length; i++)
{
var element = interfaces[i];
if (element.GetTypeInfo().IsGenericType && element.GetGenericTypeDefinition() == RequiresMessageQueueGenericType)
if (element.IsGenericType && element.GetGenericTypeDefinition() == RequiresMessageQueueGenericType)
{
return element.GetGenericArguments()[0];
}
Expand All @@ -245,11 +245,11 @@ public Type GetRequiredType(Type actorType)
private static readonly Type ProducesMessageQueueGenericType = typeof (IProducesMessageQueue<>);
private Type GetProducedMessageQueueType(MailboxType mailboxType)
{
var interfaces = mailboxType.GetType().GetTypeInfo().GetInterfaces();
var interfaces = mailboxType.GetType().GetInterfaces();
for (int i = 0; i < interfaces.Length; i++)
{
var element = interfaces[i];
if (element.GetTypeInfo().IsGenericType && element.GetGenericTypeDefinition() == ProducesMessageQueueGenericType)
if (element.IsGenericType && element.GetGenericTypeDefinition() == ProducesMessageQueueGenericType)
{
return element.GetGenericArguments()[0];
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/Akka/Util/MatchHandler/MatchExpressionBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public MatchExpressionBuilderResult BuildLambdaExpression(IReadOnlyList<TypeHand
}
else
{
if(handlesType.GetTypeInfo().IsValueType)
if(handlesType.IsValueType)
{
//For value types we cannot use as-operator and check for nu, s0 we create the following code:
// if(inputVariable is HandlesType)
Expand Down

0 comments on commit 8f13c74

Please sign in to comment.