Skip to content

Commit

Permalink
Rename ThrowHelper to avoid potential conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyrest committed Aug 14, 2024
1 parent 82652b3 commit e4d859d
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ public override CodeGenerationResult Generate(in GeneratorOptions options)
builder.AppendKeyword("static partial class");
builder.Append(ClassName);
builder.StartBlock(1);

builder.AppendLine($@"
/// <summary>
/// <para>Create an instance of <typeparamref name=""T"" /></para>
/// <para>Returns <c><see langword=""new"" /> <typeparamref name=""T"" />()</c> if <typeparamref name=""T""/> is a <see cref=""ValueType""/>(struct)</para>
/// <para>This <b>CAN</b> call the Parameterless Constructor of the <see cref=""ValueType""/>(struct)</para>
/// <para>This <b>CAN</b> call the Parameterless Constructor for <see cref=""ValueType""/>(struct)</para>
/// </summary>
/// <typeparam name=""T"">The type to create.</typeparam>
/// <returns>A new instance of <typeparamref name=""T"" /></returns>
Expand All @@ -39,7 +38,7 @@ public static T CreateInstance<
return {options.GlobalNSDot()}{FastNewCoreGenerator.ClassName}<T>.{FastNewCoreGenerator.CompiledDelegateName}();
#else
return typeof(T).IsValueType
? System.Activator.CreateInstance<T>() // This will be optimized by JIT
? System.Activator.CreateInstance<T>() // Value Types will be optimized by JIT in CoreCLR
#if {ClrAllocatorGenerator.ppEnabled}
: ({options.GlobalNSDot()}{ClrAllocatorGenerator.ClassName}<T>.IsSupported
Expand All @@ -54,7 +53,7 @@ public static T CreateInstance<
/// <summary>
/// Create an instance of <typeparamref name=""T"" /> <br/>
/// Returns <c><see langword=""default"" />(<typeparamref name=""T"" />)</c> if <typeparamref name=""T""/> is a <see cref=""ValueType""/>(struct) <br/>
/// This <b>WILL NOT</b> call the Parameterless Constructor of the <see cref=""ValueType""/>(struct)
/// This <b>WILL NOT</b> call the Parameterless Constructor for <see cref=""ValueType""/>(struct)
/// </summary>
/// <typeparam name=""T"">The type to create.</typeparam>
/// <returns>A new instance of <typeparamref name=""T"" /></returns>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public class ThrowHelperGenerator : CodeGenerator<ThrowHelperGenerator>
{
public override string Filename => "ThrowHelper.g.cs";

internal const string ClassName = "ThrowHelper";
internal const string ClassName = "FastNewThrowHelper";

internal const string SmartThrowName = "SmartThrowImpl";

Expand All @@ -15,15 +15,15 @@ public override CodeGenerationResult Generate(in GeneratorOptions options)
builder.StartNamespace();
builder.AppendLine(@$"
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never)]
internal static partial class ThrowHelper
internal static partial class {ClassName}
{{
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.NoInlining | global::System.Runtime.CompilerServices.MethodImplOptions.NoOptimization)]
#if NET5_0_OR_GREATER
[global::System.Diagnostics.CodeAnalysis.DynamicDependencyAttribute(""SmartThrowImpl``1()"", typeof({options.GlobalNSDot()}{ClassName}))]
#endif
");
builder.AppendLine(@$"
public static global::System.Reflection.MethodInfo GetSmartThrow<T>() => typeof({options.GlobalNSDot()}ThrowHelper).GetMethod(""SmartThrowImpl"", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static)!.MakeGenericMethod(typeof(T));
public static global::System.Reflection.MethodInfo GetSmartThrow<T>() => typeof({options.GlobalNSDot()}{ClassName}).GetMethod(""SmartThrowImpl"", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static)!.MakeGenericMethod(typeof(T));
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.NoInlining | global::System.Runtime.CompilerServices.MethodImplOptions.NoOptimization)]
public static T SmartThrowImpl<T>()
Expand Down
1 change: 0 additions & 1 deletion src/FastGenericNew/FastGenericNew.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
<!-- Nuget Package Properties-->
<PropertyGroup>
<PackageId>FastGenericNew</PackageId>
<DescriptionPrefix>Pre-Compiled FastGenericNew</DescriptionPrefix>
<PackageTagsPostfix>Generated</PackageTagsPostfix>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static void CtorNoopStub(object _) { }
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.NoInlining | global::System.Runtime.CompilerServices.MethodImplOptions.NoOptimization)]
public static object ThrowNotSupported(void* _) => throw new global::System.NotSupportedException();
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.NoInlining | global::System.Runtime.CompilerServices.MethodImplOptions.NoOptimization)]
public static object SmartThrow<T>(void* _) => (object)global::@FastGenericNew.ThrowHelper.SmartThrowImpl<T>()!;
public static object SmartThrow<T>(void* _) => (object)global::@FastGenericNew.FastNewThrowHelper.SmartThrowImpl<T>()!;
}

[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ static partial class FastNew {
/// <summary>
/// <para>Create an instance of <typeparamref name="T" /></para>
/// <para>Returns <c><see langword="new" /> <typeparamref name="T" />()</c> if <typeparamref name="T"/> is a <see cref="ValueType"/>(struct)</para>
/// <para>This <b>CAN</b> call the Parameterless Constructor of the <see cref="ValueType"/>(struct)</para>
/// <para>This <b>CAN</b> call the Parameterless Constructor for <see cref="ValueType"/>(struct)</para>
/// </summary>
/// <typeparam name="T">The type to create.</typeparam>
/// <returns>A new instance of <typeparamref name="T" /></returns>
Expand All @@ -38,7 +38,7 @@ public static T CreateInstance<
return global::@FastGenericNew.FastNew<T>.CompiledDelegate();
#else
return typeof(T).IsValueType
? System.Activator.CreateInstance<T>() // This will be optimized by JIT
? System.Activator.CreateInstance<T>() // Value Types will be optimized by JIT in CoreCLR

#if NET6_0_OR_GREATER && FastNewPX_AllowUnsafeImplementation
: (global::@FastGenericNew.ClrAllocator<T>.IsSupported
Expand All @@ -53,7 +53,7 @@ public static T CreateInstance<
/// <summary>
/// Create an instance of <typeparamref name="T" /> <br/>
/// Returns <c><see langword="default" />(<typeparamref name="T" />)</c> if <typeparamref name="T"/> is a <see cref="ValueType"/>(struct) <br/>
/// This <b>WILL NOT</b> call the Parameterless Constructor of the <see cref="ValueType"/>(struct)
/// This <b>WILL NOT</b> call the Parameterless Constructor for <see cref="ValueType"/>(struct)
/// </summary>
/// <typeparam name="T">The type to create.</typeparam>
/// <returns>A new instance of <typeparamref name="T" /></returns>
Expand Down
Loading

0 comments on commit e4d859d

Please sign in to comment.