From 09eea2ddd591f356bf09978a16d3374d7b7c227a Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 5 Sep 2019 16:46:55 +0200 Subject: [PATCH] Minor code tweaks --- src/ComputeSharp.Shaders/Extensions/TypeExtensions.cs | 10 ++++++++++ src/ComputeSharp.Shaders/Translation/ShaderLoader.cs | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/ComputeSharp.Shaders/Extensions/TypeExtensions.cs b/src/ComputeSharp.Shaders/Extensions/TypeExtensions.cs index 852dd8b1..3b82188e 100644 --- a/src/ComputeSharp.Shaders/Extensions/TypeExtensions.cs +++ b/src/ComputeSharp.Shaders/Extensions/TypeExtensions.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Diagnostics.Contracts; using System.Linq; +using System.Runtime.CompilerServices; namespace ComputeSharp.Shaders.Extensions { @@ -10,6 +11,15 @@ namespace ComputeSharp.Shaders.Extensions /// internal static class TypeExtensions { + /// + /// Gets whether or not the input represents a + /// + /// The input type to analyze + [Pure] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool IsDelegate(this Type type) => type.IsClass && + type.IsSubclassOf(typeof(Delegate)); + /// /// The mapping of supported known types to display string /// diff --git a/src/ComputeSharp.Shaders/Translation/ShaderLoader.cs b/src/ComputeSharp.Shaders/Translation/ShaderLoader.cs index d75d8439..56c4f75b 100644 --- a/src/ComputeSharp.Shaders/Translation/ShaderLoader.cs +++ b/src/ComputeSharp.Shaders/Translation/ShaderLoader.cs @@ -159,7 +159,7 @@ namespace ComputeSharp.Shaders.Translation foreach (FieldInfo fieldInfo in action.Method.DeclaringType.GetFields()) { - if (fieldInfo.FieldType.IsClass && fieldInfo.FieldType.IsGenericType && + if (fieldInfo.FieldType.IsDelegate() && fieldInfo.GetValue(action.Target) is Delegate func && func.Method.IsStatic && (HlslKnownTypes.IsKnownScalarType(func.Method.ReturnType) || HlslKnownTypes.IsKnownVectorType(func.Method.ReturnType)) && fieldInfo.FieldType.GenericTypeArguments.All(type => HlslKnownTypes.IsKnownScalarType(type) || @@ -270,7 +270,7 @@ namespace ComputeSharp.Shaders.Translation LoadFieldInfo(fieldInfo, null, updatedParents); } } - else if (fieldType.IsClass && fieldType.IsGenericType && + else if (fieldType.IsDelegate() && memberInfo.GetValue(Action.Target) is Delegate func && func.Method.IsStatic && (HlslKnownTypes.IsKnownScalarType(func.Method.ReturnType) || HlslKnownTypes.IsKnownVectorType(func.Method.ReturnType)) && fieldType.GenericTypeArguments.All(type => HlslKnownTypes.IsKnownScalarType(type) ||