Skip to content

Commit 8e21f69

Browse files
committed
Miscellaneous clean up
* Removed unnecessary usings * Made `Ubiquity.NET.Extensions.DisposableAction` a class * Added ObjectDisposedException in the case of multiple calls to IDispose() * Renamed `ValidationExtensions` to better reflect intent for fluent extensions. * Removed RuntimeToolMessages as the only thing left from that is the `MsgLevel` enum, which is moved to `DiagnosticMessage.cs`
1 parent 2cbd6cd commit 8e21f69

11 files changed

Lines changed: 48 additions & 123 deletions

File tree

IgnoredWords.dic

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
ABI
22
Accessor
3+
accessors
34
Addr
45
addref
56
alloca
@@ -72,6 +73,7 @@ Globalization
7273
Hashtable
7374
Identifier
7475
Impl
76+
initializer
7577
inline
7678
inlined
7779
inlining

src/Samples/CodeGenWithDebugInfo/ITargetABI.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright (c) Ubiquity.NET Contributors. All rights reserved.
22
// Licensed under the Apache-2.0 WITH LLVM-exception license. See the LICENSE.md file in the project root for full license information.
33

4-
using System;
54
using System.Collections.Immutable;
65

76
using Ubiquity.NET.Llvm;

src/Ubiquity.NET.ANTLR.Utils/LocationExtensions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using Antlr4.Runtime;
77
using Antlr4.Runtime.Tree;
88

9-
using Ubiquity.NET.Runtime.Utils;
109
using Ubiquity.NET.TextUX;
1110

1211
namespace Ubiquity.NET.ANTLR.Utils

src/Ubiquity.NET.Extensions/ByteSpanHelpers.cs

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/Ubiquity.NET.Extensions/DisposableAction.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the Apache-2.0 WITH LLVM-exception license. See the LICENSE.md file in the project root for full license information.
33

44
using System;
5+
using System.Threading;
56

67
namespace Ubiquity.NET.Extensions
78
{
@@ -11,22 +12,24 @@ namespace Ubiquity.NET.Extensions
1112
/// valuable when the scope extends beyond a single function (as a return of
1213
/// <see cref="IDisposable"/>) where a try/finally simply won't work.
1314
/// </remarks>
14-
public readonly record struct DisposableAction
15+
public sealed class DisposableAction
1516
: IDisposable
1617
{
17-
/// <summary>Initializes a new instance of the <see cref="DisposableAction"/> struct.</summary>
18+
/// <summary>Initializes a new instance of the <see cref="DisposableAction"/> class.</summary>
1819
/// <param name="onDispose">Action to run when <see cref="Dispose"/>is called.</param>
1920
public DisposableAction( Action onDispose )
2021
{
2122
OnDispose = onDispose ?? throw new ArgumentNullException( nameof( onDispose ) );
2223
}
2324

24-
/// <summary>Runs the action provided in the constructor (<see cref="DisposableAction(System.Action)" /></summary>
25+
/// <summary>Runs the action provided in the constructor (<see cref="DisposableAction(System.Action)"/>)</summary>
2526
public void Dispose( )
2627
{
27-
OnDispose();
28+
var disposeOp = Interlocked.Exchange(ref OnDispose, null);
29+
ObjectDisposedException.ThrowIf(disposeOp is null, this);
30+
disposeOp!();
2831
}
2932

30-
private readonly Action OnDispose;
33+
private Action? OnDispose;
3134
}
3235
}

src/Ubiquity.NET.Extensions/ValidationExtensions.cs renamed to src/Ubiquity.NET.Extensions/FluentValidationExtensions.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.ComponentModel;
6+
using System.Diagnostics;
67
using System.Diagnostics.CodeAnalysis;
78
using System.Runtime.CompilerServices;
89

@@ -16,14 +17,18 @@ namespace Ubiquity.NET.Extensions
1617
/// They also serve to provide validation when using body expressions for property
1718
/// method implementations etc...
1819
/// </remarks>
19-
public static class ValidationExtensions
20+
public static class FluentValidationExtensions
2021
{
22+
// NOTE: These DO NOT use the new `extension` keyword syntax as it is not clear
23+
// how CallerArgumentExpression is supposed to be used for those...
24+
2125
/// <summary>Throws an exception if <paramref name="obj"/> is <see langword="null"/></summary>
2226
/// <typeparam name="T">Type of reference parameter to test for</typeparam>
2327
/// <param name="obj">Instance to test</param>
2428
/// <param name="exp">Name or expression of the value in <paramref name="obj"/> [Default: provided by compiler]</param>
2529
/// <returns><paramref name="obj"/></returns>
2630
/// <exception cref="ArgumentNullException"><paramref name="obj"/> is <see langword="null"/></exception>
31+
[DebuggerStepThrough]
2732
public static T ThrowIfNull<T>( [NotNull] this T? obj, [CallerArgumentExpression( nameof( obj ) )] string? exp = null )
2833
{
2934
ArgumentNullException.ThrowIfNull( obj, exp );
@@ -38,9 +43,11 @@ public static T ThrowIfNull<T>( [NotNull] this T? obj, [CallerArgumentExpression
3843
/// <param name="max">Maximum value allowed for <paramref name="self"/></param>
3944
/// <param name="exp">Name or expression of the value in <paramref name="self"/> [Default: provided by compiler]</param>
4045
/// <returns><paramref name="self"/></returns>
46+
[DebuggerStepThrough]
4147
public static T ThrowIfOutOfRange<T>( this T self, T min, T max, [CallerArgumentExpression( nameof( self ) )] string? exp = null )
4248
where T : struct, IComparable<T>
4349
{
50+
ArgumentNullException.ThrowIfNull(self, exp);
4451
ArgumentOutOfRangeException.ThrowIfLessThan( self, min, exp );
4552
ArgumentOutOfRangeException.ThrowIfGreaterThan( self, max, exp );
4653

@@ -59,10 +66,12 @@ public static T ThrowIfOutOfRange<T>( this T self, T min, T max, [CallerArgument
5966
/// <see cref="FlagsAttribute"/> as a legit value that is a combination of flags does not have
6067
/// a defined value (Only single bit values do)
6168
/// </remarks>
69+
[DebuggerStepThrough]
6270
public static T ThrowIfNotDefined<T>( this T self, [CallerArgumentExpression( nameof( self ) )] string? exp = null )
6371
where T : struct, Enum
6472
{
65-
return Enum.IsDefined<T>( self ) ? self : throw new InvalidEnumArgumentException( exp );
73+
ArgumentNullException.ThrowIfNull(self, exp);
74+
return Enum.IsDefined( typeof(T), self ) ? self : throw new InvalidEnumArgumentException( exp );
6675
}
6776
}
6877
}

src/Ubiquity.NET.Extensions/Readme.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ normally used when the value itself isn't passed on but some transformed value i
4141
* `ThrowIfNotDefined()`
4242

4343
## PolyFill
44-
|Fully Qualified Name| Framework requirements |
45-
|--------------------|-------------|
46-
|System.Diagnostics.CodeAnalysis.StringSyntaxAttribute`| Target framework is .NET 7 or less. |
44+
While it isn't `impossible` to make polyfill this to work on .NET standard 2.0 it is a HUGE
45+
amount of effort to do so and there's no compelling reason to do so. Roslyn extensions/VSIX
46+
extensions are the most likely candidates left. VS extensions are shifting to external
47+
processes for extensions for this reason, leaving Roslyn generators. The bottom line is
48+
that too much of MODERN .NET and C# is incompatible with .NET Standard 2.0 that a distinct
49+
PolyFill library can only cover some of it. (Even the PolySharp generator covers only
50+
some of the missing functionality)

src/Ubiquity.NET.Extensions/Ubiquity.NET.Extensions.csproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,5 @@
2929
<None Include="ReadMe.md" Pack="true" PackagePath="\" />
3030
</ItemGroup>
3131

32-
<ItemGroup>
33-
<PackageReference Include="System.IO.Hashing" />
34-
</ItemGroup>
3532

3633
</Project>

src/Ubiquity.NET.Llvm.Tests/CallTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using Microsoft.VisualStudio.TestTools.UnitTesting;
55

6-
using Ubiquity.NET.Llvm.DebugInfo;
76
using Ubiquity.NET.Llvm.Instructions;
87
using Ubiquity.NET.Llvm.Values;
98

src/Ubiquity.NET.TextUX/DiagnosticMessage.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,25 @@
88

99
namespace Ubiquity.NET.TextUX
1010
{
11+
/// <summary>Tool Message category</summary>
12+
public enum MsgLevel
13+
{
14+
/// <summary>All channels off</summary>
15+
None = 0,
16+
17+
/// <summary>Verbose messages (or higher) are enabled</summary>
18+
Verbose = 1,
19+
20+
/// <summary>Informational messages (or higher) are enabled.</summary>
21+
Information = 2,
22+
23+
/// <summary>Warning messages (or higher) are enabled. [This is the default value]</summary>
24+
Warning = 3, // Default level is warning & error only
25+
26+
/// <summary>Error messages (or higher) are enabled.</summary>
27+
Error = 4,
28+
}
29+
1130
/// <summary>Diagnostic message for reporting diagnostics as part of end-user facing experience (UX)</summary>
1231
/// <remarks>
1332
/// <see cref="Code"/> must NOT be localized. It is required to universally identify a
@@ -54,7 +73,7 @@ public string Text
5473
get;
5574
init
5675
{
57-
ArgumentNullException.ThrowIfNull( value );
76+
ArgumentNullException.ThrowIfNull(value);
5877
field = value;
5978
}
6079
}

0 commit comments

Comments
 (0)