Skip to content

Commit

Permalink
Get rid of TypeInfo (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
sungam3r authored Jan 24, 2024
1 parent 6adae75 commit 3e081e6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ public bool TryDestructure(object value, ILogEventPropertyValueFactory propertyV

private CacheEntry CreateCacheEntry(Type type)
{
var ti = type.GetTypeInfo();
var classDestructurer = ti.GetCustomAttribute<ITypeDestructuringAttribute>();
var classDestructurer = type.GetCustomAttribute<ITypeDestructuringAttribute>();
if (classDestructurer != null)
return new(classDestructurer.CreateLogEventPropertyValue);

Expand Down
2 changes: 1 addition & 1 deletion src/Destructurama.Attributed/Util/AttributeFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Destructurama.Util;

internal static class AttributeFinder
{
public static T GetCustomAttribute<T>(this TypeInfo typeInfo) =>
public static T GetCustomAttribute<T>(this Type typeInfo) =>
typeInfo.GetCustomAttributes().OfType<T>().FirstOrDefault();

public static T GetCustomAttribute<T>(this PropertyInfo propertyInfo) =>
Expand Down
9 changes: 3 additions & 6 deletions src/Destructurama.Attributed/Util/GetablePropertyFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,11 @@ public static IEnumerable<PropertyInfo> GetPropertiesRecursive(this Type type)
{
var seenNames = new HashSet<string>();

var currentTypeInfo = type.GetTypeInfo();

while (currentTypeInfo.AsType() != typeof(object))
while (type != typeof(object))
{
var unseenProperties = currentTypeInfo.DeclaredProperties
var unseenProperties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)
.Where(p => p.CanRead &&
p.GetMethod.IsPublic &&
!p.GetMethod.IsStatic &&
(p.Name != "Item" || p.GetIndexParameters().Length == 0) &&
!seenNames.Contains(p.Name));

Expand All @@ -39,7 +36,7 @@ public static IEnumerable<PropertyInfo> GetPropertiesRecursive(this Type type)
yield return propertyInfo;
}

currentTypeInfo = currentTypeInfo.BaseType.GetTypeInfo();
type = type.BaseType;
}
}
}

0 comments on commit 3e081e6

Please sign in to comment.