Removed unnecessary code

このコミットが含まれているのは:
Sergio Pedri committed 2020-12-01 12:47:23 +01:00
1 親 dea3a477ef
コミット 0714dedf1f
6ファイル変更
+15 -74

検索条件に一致するファイルはありません

+5 -2
ファイルの表示
@@ -1,8 +1,11 @@
using System.Runtime.CompilerServices;
using System;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Microsoft.Toolkit.Diagnostics;
namespace System.Reflection.Emit
namespace ComputeSharp.Shaders.Extensions
{
/// <summary>
/// A <see langword="class"/> that provides extension methods for the <see langword="ILGenerator"/> type
-27
ファイルの表示
@@ -1,27 +0,0 @@
using System.Diagnostics.Contracts;
using System.Linq;
using System.Text.RegularExpressions;
namespace System
{
/// <summary>
/// A <see langword="class"/> that provides extension methods for the <see langword="string"/> type
/// </summary>
internal static class StringExtensions
{
/// <summary>
/// Removes the left padding for an input multiline <see langword="string"/>
/// </summary>
/// <param name="text">The input <see langword="string"/> to process</param>
/// <returns>A left-aligned <see langword="string"/> with the same text as the input</returns>
[Pure]
public static string RemoveLeftPadding(this string text)
{
string[] lines = text.Split(Environment.NewLine);
int spaces = text.TakeWhile(c => c == ' ').Count();
Regex regex = new Regex($"^{new string(Enumerable.Repeat(' ', spaces).ToArray())}");
return lines.Aggregate(string.Empty, (result, line) => $"{result}{Environment.NewLine}{regex.Replace(line, string.Empty)}");
}
}
}
+7 -39
ファイルの表示
@@ -1,53 +1,21 @@
using System.Diagnostics.CodeAnalysis;
using System;
using System.Diagnostics.Contracts;
using System.Reflection;
using System.Runtime.CompilerServices;
namespace System
namespace ComputeSharp.Shaders.Extensions
{
/// <summary>
/// A <see langword="class"/> that provides extension methods for the <see cref="Type"/> type
/// A <see langword="class"/> that provides extension methods for the <see cref="Type"/> type.
/// </summary>
internal static class TypeExtensions
{
/// <summary>
/// Gets whether or not the input <see cref="Type"/> represents a <see cref="Delegate"/>
/// Gets whether or not the input <see cref="Type"/> represents a <see cref="Delegate"/>.
/// </summary>
/// <param name="type">The input type to analyze</param>
/// <param name="type">The input type to analyze.</param>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsDelegate(this Type type) => type.IsClass &&
type.IsSubclassOf(typeof(Delegate));
/// <summary>
/// Gets whether or not the input <see cref="Type"/> represents a <see cref="Delegate"/> with no captured variables
/// </summary>
/// <param name="type">The input type to analyze</param>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsStatelessDelegateContainer(this Type type) => type.GetFields(BindingFlags.Static | BindingFlags.Public).Length > 0;
/// <summary>
/// Tries to find an ancestor member starting from the input <see cref="Type"/>
/// </summary>
/// <param name="type">The input type to start the search from</param>
/// <param name="name">The name of the member to retrieve</param>
/// <param name="bindingAttr">A bitmask comprised of one or more <see cref="BindingFlags"></see> that specify how the search is conducted</param>
/// <returns><see langword="true"/> when a member with the given name is found, <see langword="false"/> otherwise</returns>
public static bool TryFindAncestorMember(this Type type, string name, BindingFlags bindingAttr, [NotNullWhen(true)] out (Type DeclaringType, MemberInfo MemberInfo)? result)
public static bool IsDelegate(this Type type)
{
while ((type = type.DeclaringType!) != null)
{
MemberInfo[] memberInfos = type.GetMember(name, bindingAttr);
if (memberInfos.Length > 0)
{
result = (type, memberInfos[0]);
return true;
}
}
result = null;
return false;
return type.IsSubclassOf(typeof(Delegate));
}
}
}
+1
ファイルの表示
@@ -5,6 +5,7 @@ using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using ComputeSharp.Shaders.Extensions;
namespace ComputeSharp.Shaders.Translation
{
+1
ファイルの表示
@@ -8,6 +8,7 @@ using System.Runtime.InteropServices;
using ComputeSharp.Core.Interop;
using ComputeSharp.Graphics;
using ComputeSharp.Graphics.Buffers.Abstract;
using ComputeSharp.Shaders.Extensions;
using ComputeSharp.Shaders.Mappings;
using ComputeSharp.Shaders.Translation.Models;
using Microsoft.Toolkit.Diagnostics;
+1 -6
ファイルの表示
@@ -178,12 +178,7 @@ namespace ComputeSharp.Shaders.Translation
this.capturedFields.Add(fieldInfo);
this.fieldsInfo.Add(new CapturedFieldInfo(hlslType, hlslName));
}
else if (fieldType.IsDelegate() &&
fieldInfo.GetValue(shader) is Delegate func &&
(func.Method.IsStatic || func.Method.DeclaringType!.IsStatelessDelegateContainer()) &&
(HlslKnownTypes.IsKnownScalarType(func.Method.ReturnType) || HlslKnownTypes.IsKnownVectorType(func.Method.ReturnType)) &&
fieldType.GenericTypeArguments.All(type => HlslKnownTypes.IsKnownScalarType(type) ||
HlslKnownTypes.IsKnownVectorType(type)))
else if (fieldInfo.GetValue(shader) is Delegate { Method: { IsStatic: true } } func)
{
// Captured static delegates with a return type
throw new NotImplementedException();