Added ThrowHelper type

このコミットが含まれているのは:
Sergio Pedri committed 2020-11-20 11:46:19 +01:00
1 親 0c3f8f92c3
コミット 3d48a6fb0c
11ファイル変更
+125 -27

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

+2 -1
ファイルの表示
@@ -7,6 +7,7 @@ using System.Linq;
using System.Reflection;
using System.Reflection.Metadata;
using System.Text.RegularExpressions;
using ComputeSharp.Core.Helpers;
using ComputeSharp.Shaders.Mappings;
using ComputeSharp.Shaders.Translation.Enums;
using ICSharpCode.Decompiler;
@@ -139,7 +140,7 @@ namespace ComputeSharp.Shaders.Translation
{
MethodType.Execute => GetSyntaxTreeForExecuteMethod(methodInfo),
MethodType.Static => GetSyntaxTreeForStaticMethod(methodInfo),
_ => throw new ArgumentOutOfRangeException(nameof(methodType), $"Invalid method type: {methodType}")
_ => ThrowHelper.ThrowArgumentException<string>("Invalid method type")
};
// Load the type syntax tree
+3 -2
ファイルの表示
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Reflection;
using ComputeSharp.Core.Helpers;
namespace ComputeSharp.Shaders.Translation.Models
{
@@ -39,7 +40,7 @@ namespace ComputeSharp.Shaders.Translation.Models
IsStatic = propertyInfo.GetMethod!.IsStatic;
MemberType = propertyInfo.PropertyType;
}
else throw new InvalidOperationException("Field and property can't both be null at the same time");
else ThrowHelper.ThrowArgumentException("Field and property can't both be null at the same time");
}
/// <summary>
@@ -78,7 +79,7 @@ namespace ComputeSharp.Shaders.Translation.Models
{
FieldInfo field => field.GetValue(instance)!,
PropertyInfo property => property.GetValue(instance)!,
_ => throw new InvalidOperationException("Field and property can't both be null at the same time")
_ => ThrowHelper.ThrowArgumentException<object>("Field and property can't both be null at the same time")
};
}
+3 -3
ファイルの表示
@@ -1,11 +1,11 @@
using System;
using System.Buffers;
using System.Buffers;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using ComputeSharp.Core.Helpers;
using ComputeSharp.Graphics.Buffers.Abstract;
using ComputeSharp.Shaders.Mappings;
using ComputeSharp.Shaders.Translation.Models;
@@ -129,7 +129,7 @@ namespace ComputeSharp.Shaders.Translation
this.totalVariablesByteSize += size;
}
else throw new InvalidOperationException($"Invalid captured member of type {member.MemberType}");
else ThrowHelper.ThrowArgumentException("Invalid captured member type");
}
il.Emit(OpCodes.Ret);
+6 -2
ファイルの表示
@@ -5,6 +5,7 @@ using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using ComputeSharp.Core.Helpers;
using ComputeSharp.Graphics.Extensions;
using ComputeSharp.Shaders.Mappings;
using ComputeSharp.Shaders.Renderer.Models.Fields;
@@ -148,7 +149,10 @@ namespace ComputeSharp.Shaders.Translation
BindingFlags.Public |
BindingFlags.NonPublic).ToArray();
if (shaderFields.Count == 0) throw new InvalidOperationException("Empty shader body");
if (shaderFields.Count == 0)
{
ThrowHelper.ThrowInvalidOperationException("The shader body must contain at least one field");
}
// Descriptor for the buffer for captured scalar/vector variables
D3D12_DESCRIPTOR_RANGE1 d3D12DescriptorRange1 = new(D3D12_DESCRIPTOR_RANGE_TYPE_CBV, 1, this.constantBuffersCount++);
@@ -230,7 +234,7 @@ namespace ComputeSharp.Shaders.Translation
// Captured static delegates with a return type
LoadStaticMethodSource(shader, fieldName, func.Method);
}
else throw new ArgumentException($"Invalid captured variable of type {fieldType} with name \"{memberInfo.Name}\"");
else ThrowHelper.ThrowArgumentException("Invalid captured variable");
}
/// <summary>