MmsCore.Utilities
0.1.3
See the version list below for details.
dotnet add package MmsCore.Utilities --version 0.1.3
NuGet\Install-Package MmsCore.Utilities -Version 0.1.3
<PackageReference Include="MmsCore.Utilities" Version="0.1.3" />
paket add MmsCore.Utilities --version 0.1.3
#r "nuget: MmsCore.Utilities, 0.1.3"
// Install MmsCore.Utilities as a Cake Addin #addin nuget:?package=MmsCore.Utilities&version=0.1.3 // Install MmsCore.Utilities as a Cake Tool #tool nuget:?package=MmsCore.Utilities&version=0.1.3
[!IMPORTANT] This Project is not yet stable. Breaking changes may occur at any time.
MmsCore.Utilities
MmsCore.Utilitiesは、文字列表現からNULL可能な型を解析したり、値域を表現したり、値域に対する操作を実行したりするような一般的なタスクのためのユーティリティクラスや拡張機能を提供します。
🚀 Getting Started
JsonCopier
![TIPS]
JsonCopier
は "深いコピー (Deep Clone)" を実行します。これは新たに生成されたクローンが元のオブジェクトから完全に独立していることを意味します。
JsonCopier<T>
を使用して T
型のオブジェクトを一つから別のものにコピーする方法の例です。
private sealed class Hoge
{
public int Property1 { get; set; }
public string Property2 { get; set; } = default!;
}
var source = new Hoge{ Property1 = 100, Property2 = "ほげ" };
var cloned = JsonCopier.DeepClone(source);
Assert.NotNull(cloned);
Assert.Equal(source.Property1, cloned.Property1);
Assert.Equal(source.Property2, cloned.Property2);
NullableParser
文字列からnull許容型への変換が可能になります。成功時には該当型の値が、解析に失敗した場合には null
が返されます。
NullableParser.Parse<T>(string)
を使用して、null 許容型へ変換する方法の例です。
var parsed = NullableParser.Parse<bool>("false");
Assert.True(parsed is false);
var parsed = NullableParser.Parse<bool>("true");
Assert.True(parsed);
var parsed = NullableParser.Parse<bool>("0");
Assert.False(parsed.HasValue);
var parsed = NullableParser.Parse<int>("123");
Assert.Equal(123, parsed ?? 0);
var parsed = NullableParser.Parse<double>("-1.643e6");
Assert.Equal(-1643000d, parsed ?? 0);
var parsed = NullableParser.Parse<double>(@"\1,643.57");
Assert.False(parsed.HasValue);
NullableParser.ParseToNumber<T>(string, NumberStyles, IFormatProvider?)
を使用して、null 許容型へ変換する方法の例です。
var parsed = NullableParser.ParseToNumber<double>(
@"\1,643.57",
NumberStyles.Currency,
CultureInfo.GetCultureInfo("ja-JP"));
Assert.Equal(1643.57d, parsed ?? 0);
NullableParser.ParseToDateTime(string, string)
を使用して、null 許容型へ変換する方法の例です。
var parsed = NullableParser.ParseToDateTime("2014/11/11 12:34:56", "yyyy/MM/dd HH:mm:ss");
Assert.Equal(DateTime.Parse("2014/11/11 12:34:56", CultureInfo.InvariantCulture), parsed ?? DateTime.Today);
ValueRange
// RangeA : inclusiveLowerBound: true, inclusiveUpperBound: true
// RangeB : inclusiveLowerBound: true, inclusiveUpperBound: true
// RangeA : [5,6,7,8,9]
// RangeB :
// B0: [3,4] ... OverlapsWith=false/IntersectsWith=false (After)
// B1: [3,4,5] ... OverlapsWith=false/IntersectsWith=true (Start Touching)
// B2: [3,4,5,6] ... OverlapsWith=true /IntersectsWith=true (Start Inside)
// B3: [5,6,7,8,9,10,11] ... OverlapsWith=true /IntersectsWith=true (Inside Start Touching)
// B4: [5,6,7,8] ... OverlapsWith=true /IntersectsWith=true (Enclosing Start Touching)
// B5: [6,7,8] ... OverlapsWith=true /IntersectsWith=true (Enclosing)
// B6: [6,7,8,9] ... OverlapsWith=true /IntersectsWith=true (Enclosing End Touching)
// B7: [5,6,7,8,9] ... OverlapsWith=true /IntersectsWith=true (Exact Match)
// B8: [4,5,6,7,8,9,10] ... OverlapsWith=true /IntersectsWith=true (Inside)
// B9: [4,5,6,7,8,9] ... OverlapsWith=true /IntersectsWith=true (Inside End Touching)
// B10: [8,9,10,11] ... OverlapsWith=true /IntersectsWith=true (End Inside)
// B11: [9,10,11] ... OverlapsWith=false/IntersectsWith=true (End Touching)
// B12: [10,11] ... OverlapsWith=false/IntersectsWith=false (Before)
var rangeA = Range.Create(5, 9, inclusiveUpperBound: true);
var rangeB1 = Range.Create(3, 5, inclusiveUpperBound: true);
Assert.False(rangeA.OverlapsWith(rangeB1));
Assert.True(rangeA.IntersectsWith(rangeB1));
ValueRangeExtensions.IntersectsWith
を使用して、特定の値範囲が他の値範囲と交差しているかどうかを判断する方法の例です。
// 値範囲を定義します
var rangeA = ValueRange.Create(5, 9, inclusiveUpperBound: true);
var rangeB = ValueRange.Create(3, 5, inclusiveUpperBound: true);
// IntersectsWith メソッドを使用して範囲が交差しているかを確認します
var intersects = rangeA.IntersectsWith(rangeB);
// Assert
Assert.True(intersects);
ValueRangeExtensions.OverlapsWith
を使用して、特定の値範囲が他の値範囲と重複しているかどうかを判断する方法の例です。
// 値範囲を定義します
var rangeA = ValueRange.Create(5, 9, inclusiveUpperBound: true);
var rangeB = ValueRange.Create(3, 5, inclusiveUpperBound: true);
// OverlapsWith メソッドを使用して範囲が重複しているかを確認します
var overlaps = rangeA.OverlapsWith(rangeB);
// Assert
Assert.False(overlaps);
🙏 Acknowledgments
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Newtonsoft.Json (>= 13.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated | |
---|---|---|---|
0.1.4 | 250 | 6/7/2024 | |
0.1.3 | 216 | 2/29/2024 | |
0.1.2 | 107 | 2/19/2024 | |
0.1.1 | 127 | 2/11/2024 | |
0.1.0 | 86 | 2/11/2024 | |
0.0.1-beta.5 | 128 | 1/21/2024 | |
0.0.1-beta.4 | 104 | 1/12/2024 | |
0.0.1-beta.3 | 77 | 1/12/2024 | |
0.0.1-beta.2 | 92 | 1/10/2024 |