Skip to content

Commit

Permalink
Fixing the polyfills
Browse files Browse the repository at this point in the history
  • Loading branch information
dgmjr committed Jan 24, 2024
1 parent eebe033 commit 82e1308
Show file tree
Hide file tree
Showing 38 changed files with 417 additions and 7,055 deletions.
35 changes: 35 additions & 0 deletions All/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
date: 2023-07-13T05:44:46:00-05:00Z
description: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files, yadda, yadda, yadda...
keywords:
- IP
- copyright
- license
- mit
permissions:
- commercial-use
- modifications
- distribution
- private-use
conditions:
- include-copyright
limitations:
- liability
- warranty
lastmod: 2024-01-0T00:39:00.0000+05:00Z
license: MIT
slug: mit-license
title: MIT License
type: license
---

# MIT License

## Copyright © 2022-2024 [David G. Moore, Jr.](mailto:[email protected] "Send Dr. Moore") ([@dgmjr](https://github.com/dgmjr "Contact Dr. Moore on GitHub")), All Rights Reserved

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Key features:
```csharp
var email = EmailAddress.From("[email protected]");

if (email.IsEmpty) {
if (!email.IsEmpty) {
// use email
}
```
Expand Down Expand Up @@ -126,9 +126,9 @@ if (id.IsEmpty) {
- [`Int24`](https://github.com/dgmjr-io/Primitives/blob/main/src/Int24.cs) - a 24-bit signed integer (*alias: i24*)
- [`UInt24`](https://github.com/dgmjr-io/Primitives/blob/main/src/Int24.cs) - a 24-bit unsigned integer (*alias: ui24*)

## The <ins>`blank`</ins> Resource <ins>`blank`</ins>s
## The <ins>`X`</ins> Resource <ins>`Y`</ins>s

These are a collection of <ins>`blank`</ins> Resource <ins>`blank`</ins>s.
These are a collection of <ins>`X`</ins> Resource <ins>`Y`</ins>s.

- [`iri`](https://github.com/dgmjr-io/Primitives/blob/main/src/iri.cs) - An internationalized resource identifier
- [`uri`](https://github.com/dgmjr-io/Primitives/blob/main/src/uri.cs) - A uniform resource identifier
Expand Down
179 changes: 122 additions & 57 deletions src/Abstractions/IRegexValueObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,77 +8,142 @@ public interface IRegexValueObject<TSelf>
IComparable,
IEquatable<TSelf>,
IHaveAUri
#if NET7_0_OR_GREATER
,
IParsable<TSelf>,
IUriConvertible<TSelf>
#endif
where TSelf : IRegexValueObject<TSelf>
{
/// <summary>Gets The value of the value object as a string. Will be <see langword="null" /> or <see cref="string.Empty" /> iff <see cref="IsEmpty" /> == <see langword="true" /></summary>
string Value { get; }
// #if NET7_0_OR_GREATER
// ,
// IParsable<TSelf>,
// IUriConvertible<TSelf>
// #endif
// where TSelf : IRegexValueObject<TSelf>
// {
// /// <summary>Gets The value of the value object as a string. Will be <see langword="null" /> or <see cref="string.Empty" /> iff <see cref="IsEmpty" /> == <see langword="true" /></summary>
// string Value { get; }

// /// <summary><see langword="true" /> if the value object is empty, <see langword="false" /> otherwise</summary>
// /// <value><see langword="true" /> if the value object is empty, <see langword="false" /> otherwise</value>
// bool IsEmpty { get; }

// #if NET6_0_OR_GREATER
// // /// <summary>Gets <inheritdoc cref="Regex" path="/returns" /></summary>
// // /// <returns>a <see cref="Regex" /> containing the regular expression, which can be used to parse/validate string versions of the value object</returns>
// // public abstract static Regex Regex();

// /// <summary>Gets <inheritdoc cref="RegexString" path="/returns" /></summary>
// /// <returns>the regular expression (as a string), which can be used to parse/validate string versions of the value object</returns>
// public abstract static string RegexString { get; }

// /// <summary>Gets <inheritdoc cref="Name" path="/returns" /></summary>
// /// <returns>the name of the value object</returns>
// public virtual static string Name { get; } = typeof(TSelf).Name;

// /// <summary>Gets <inheritdoc cref="Description" path="/returns" /></summary>
// /// <returns>a description of the value object type</returns>
// public abstract static string Description { get; }

// /// <summary>Parses the <paramref name="value" /> into <inheritdoc cref="Parse" path="/returns" /></summary>
// /// <returns>an instance of <typeparamref name="TSelf" /> iff the <see langword="string" /> <paramref name="value" /> parses properly</returns>
// /// <exception cref="global::Vogen.ValueObjectValidationException">thrown if the value object fails validation</exception>
// /// <exception cref="global::System.Exception">thrown if parsing the <see langword="string" /> <paramref name="value" /> failed for some other reason</exception>
// public abstract static TSelf Parse(string value);

// /// <summary>Generates <inheritdoc cref="Parse" path="/returns" /></summary>
// /// <returns>an instance of <typeparamref name="TSelf" /> iff the <see langword="string" /> <paramref name="value" /> parses properly</returns>
// /// <exception cref="global::Vogen.ValueObjectValidationException">thrown if the value object fails validation</exception>
// /// <exception cref="global::System.Exception">thrown if parsing the <see langword="string" /> <paramref name="value" /> failed for some other reason</exception>
// public abstract static TSelf From(string value);

/// <summary><see langword="true" /> if the value object is empty, <see langword="false" /> otherwise</summary>
/// <value><see langword="true" /> if the value object is empty, <see langword="false" /> otherwise</value>
bool IsEmpty { get; }
// /// <summary>Gets <inheritdoc cref="ExampleValue" path="/returns" /></summary>
// /// <returns>an example (archetypal) value for the value object</returns>
// public abstract static TSelf ExampleValue { get; }

#if NET6_0_OR_GREATER
/// <summary>Gets <inheritdoc cref="Regex" path="/returns" /></summary>
/// <returns>a <see cref="Regex" /> containing the regular expression, which can be used to parse/validate string versions of the value object</returns>
public abstract static Regex Regex();
// /// <summary>Gets the empty representation of this value object</summary>
// public static abstract TSelf Empty { get; }

// // public abstract static Validation Validate(string value);
// /// <summary>Gets the "external documentation" for the value object</summary>
// public static virtual ExternalDocsTuple? ExternalDocumentation => null;
// #else
// // /// <summary>Gets <inheritdoc cref="RegexString" path="/returns" /></summary>
// // /// <returns>the regular expression (as a string), which can be used to parse/validate string versions of the value object</returns>
// // string RegexString { get; }

// // /// <summary>Gets <inheritdoc cref="Description" path="/returns" /></summary>
// // /// <returns>a description of the value object type</returns>
// // string Description { get; }

// // /// <summary>Gets <inheritdoc cref="ExampleValue" path="/returns" /></summary>
// // /// <returns>an example (archetypal) value for the value object</returns>
// // TSelf ExampleValue { get; }

// // /// <summary>Returns <inheritdoc cref="Regex" path="/returns" /></summary>
// // /// <returns>a <see cref="Regex" /> containing the regular expression, which can be used to parse/validate string versions of the value object</returns>
// // Regex Regex();
}

// /// <summary>Gets the original string that was parsed to create the value object</summary>
// string OriginalString { get; }
// }

internal record struct RegexValueObject : IRegexValueObject<RegexValueObject>
{
/// <summary>Gets <inheritdoc cref="RegexString" path="/returns" /></summary>
/// <returns>the regular expression (as a string), which can be used to parse/validate string versions of the value object</returns>
public abstract static string RegexString { get; }
public static string RegexString => throw new NotImplementedException();

/// <summary>Gets <inheritdoc cref="Name" path="/returns" /></summary>
/// <returns>the name of the value object</returns>
public virtual static string Name { get; } = typeof(TSelf).Name;
public static string Name => throw new NotImplementedException();

/// <summary>Gets <inheritdoc cref="Description" path="/returns" /></summary>
/// <returns>a description of the value object type</returns>
public abstract static string Description { get; }

/// <summary>Parses the <paramref name="value" /> into <inheritdoc cref="Parse" path="/returns" /></summary>
/// <returns>an instance of <typeparamref name="TSelf" /> iff the <see langword="string" /> <paramref name="value" /> parses properly</returns>
/// <exception cref="global::Vogen.ValueObjectValidationException">thrown if the value object fails validation</exception>
/// <exception cref="global::System.Exception">thrown if parsing the <see langword="string" /> <paramref name="value" /> failed for some other reason</exception>
public abstract static TSelf Parse(string value);

/// <summary>Generates <inheritdoc cref="Parse" path="/returns" /></summary>
/// <returns>an instance of <typeparamref name="TSelf" /> iff the <see langword="string" /> <paramref name="value" /> parses properly</returns>
/// <exception cref="global::Vogen.ValueObjectValidationException">thrown if the value object fails validation</exception>
/// <exception cref="global::System.Exception">thrown if parsing the <see langword="string" /> <paramref name="value" /> failed for some other reason</exception>
public abstract static TSelf From(string value);

/// <summary>Gets <inheritdoc cref="ExampleValue" path="/returns" /></summary>
/// <returns>an example (archetypal) value for the value object</returns>
public abstract static TSelf ExampleValue { get; }

/// <summary>Gets the empty representation of this value object</summary>
public static abstract TSelf Empty { get; }

// public abstract static Validation Validate(string value);
/// <summary>Gets the "external documentation" for the value object</summary>
public static virtual ExternalDocsTuple? ExternalDocumentation => null;
#else
/// <summary>Gets <inheritdoc cref="RegexString" path="/returns" /></summary>
/// <returns>the regular expression (as a string), which can be used to parse/validate string versions of the value object</returns>
string RegexString { get; }
public static string Description => throw new NotImplementedException();

/// <summary>Gets <inheritdoc cref="Description" path="/returns" /></summary>
/// <returns>a description of the value object type</returns>
string Description { get; }
public static ExternalDocsTuple? ExternalDocumentation => throw new NotImplementedException();

/// <summary>Gets <inheritdoc cref="ExampleValue" path="/returns" /></summary>
/// <returns>an example (archetypal) value for the value object</returns>
TSelf ExampleValue { get; }
public static RegexValueObject ExampleValue => throw new NotImplementedException();

/// <summary>Returns <inheritdoc cref="Regex" path="/returns" /></summary>
/// <returns>a <see cref="Regex" /> containing the regular expression, which can be used to parse/validate string versions of the value object</returns>
Regex Regex();
#endif
public static RegexValueObject Empty => throw new NotImplementedException();

public string Value => throw new NotImplementedException();

public bool IsEmpty => throw new NotImplementedException();

public string OriginalString => throw new NotImplementedException();

public Uri Uri => throw new NotImplementedException();

public static RegexValueObject Parse(string value)
{
throw new NotImplementedException();
}

public static RegexValueObject From(string value)
{
throw new NotImplementedException();
}

public static RegexValueObject From(Uri uri)
{
throw new NotImplementedException();
}

public static RegexValueObject Parse(string s, IFormatProvider? provider)
{
throw new NotImplementedException();
}

public static bool TryParse(string s, IFormatProvider? provider, out RegexValueObject result)
{
throw new NotImplementedException();
}

public int CompareTo(RegexValueObject other)
{
throw new NotImplementedException();
}

/// <summary>Gets the original string that was parsed to create the value object</summary>
string OriginalString { get; }
public int CompareTo(object obj)
{
throw new NotImplementedException();
}
}
5 changes: 2 additions & 3 deletions src/Abstractions/IStringWithRegexValueObject.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
namespace System;

public interface IStringWithRegexValueObject<TSelf> : IRegexValueObject<TSelf>
where TSelf : IStringWithRegexValueObject<TSelf>
{ }
public interface IStringWithRegexValueObject<TSelf> // : IRegexValueObject<TSelf>
where TSelf : IStringWithRegexValueObject<TSelf> { }
32 changes: 16 additions & 16 deletions src/Abstractions/IUriConvertible{T}.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
namespace System;

public interface IUriConvertible<T>
where T : IUriConvertible<T>, IHaveAUri
{
#if NET70_OR_GREATER
public static virtual T FromUri(Uri uri) =>
typeof(T).IsAssignableFrom(typeof(Uri))
? (T)uri
: new FromUri(uri?.ToString() ?? string.Empty);
public static virtual T FromUri(string uri) =>
typeof(T).IsAssignableFrom(typeof(Uri))
? (T)new Uri(uri)
: new FromUri(uri ?? string.Empty);
#endif
}
namespace System;

public interface IUriConvertible<T> : IHaveAUri
where T : IUriConvertible<T>, IHaveAUri
{
#if NET70_OR_GREATER
public static virtual T FromUri(Uri uri) =>
typeof(T).IsAssignableFrom(typeof(Uri))
? (T)uri
: new FromUri(uri?.ToString() ?? string.Empty);
public static virtual T FromUri(string uri) =>
typeof(T).IsAssignableFrom(typeof(Uri))
? (T)new Uri(uri)
: new FromUri(uri ?? string.Empty);
#endif
}
10 changes: 6 additions & 4 deletions src/Dgmjr.Primitives.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net6.0;net8.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net6.0;net8.0</TargetFrameworks>
<!-- <TargetFramework>net7.0</TargetFramework> -->
<LangVersion>preview</LangVersion>
<AssemblyName>Dgmjr.Primitives</AssemblyName>
Expand Down Expand Up @@ -50,15 +50,14 @@

<ItemGroup>
<Compile Remove="./PRE_NET6_0_POLYFILLS_NOT_USING/*.cs" />
<Compile Remove="./PRE_NET6_0_POLYFILLS/*.cs" Condition="$(DefineConstants.Contains('NET6_0_OR_GREATER'))" />
<!-- <Compile Remove="./PRE_NET6_0_POLYFILLS/*.cs" Condition="$(DefineConstants.Contains('NET6_0_OR_GREATER'))" /> -->
<Compile Remove="./PRE_NET6_0_POLYFILLS/*.cs" />
<NoWarn Include="CS8335" Description="Do not use '{0}'. This is reserved for compiler usage." Condition="$(DefineConstants.Contains('NET6_0_OR_GREATER'))" />
<PackageFile Include="./PrimitivesGlobalUsings.cs" Pack="true" PackagePath="Build/%(Filename)%(Extension)" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Dgmjr.System.Extensions"/>
<SourceCode Include="System.Private.CoreLib.Polyfills" />
<PackageReference Include="Dgmjr.RegexDtoGenerator" IncludeAssets="Analyzers;Build" ExcludeAssets="Native;BuildTransitive;BuildMultitargeting;ContentFiles;Compile;Runtime" PrivateAssets="All" />
<!-- <PackageReference Include="Dgmjr.RegexDtoGenerator" IncludeAssets="Analyzers;Build" ExcludeAssets="Native;BuildTransitive;BuildMultitargeting;ContentFiles;Compile;Runtime" PrivateAssets="All" /> -->
<PackageReference Include="System.Text.Json.Usings" IncludeAssets="Build;BuildTransitive;BuildMultitargeting;Runtime;Compile" ExcludeAssets="ContentFiles;Native;Analyzers" PrivateAssets="None" />
<Usings Include="System.Text.RegularExpressions.Usings"/>
<Usings Include="System.Usings"/>
Expand All @@ -77,4 +76,7 @@
<ItemGroup>
<EmbeddedResource Include="./Resources/*.*" LogicalName="%(Filename)%(Extension)" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Polyfills" />
</ItemGroup>
</Project>
Loading

0 comments on commit 82e1308

Please sign in to comment.