YamatoDaiwaCS_Extensions 0.3.0

Suggested Alternatives

YamatoDaiwa.CSharpExtensions

Additional Details

This package has been renamed to "YamatoDaiwa.CSharpExtensions"

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package YamatoDaiwaCS_Extensions --version 0.3.0
                    
NuGet\Install-Package YamatoDaiwaCS_Extensions -Version 0.3.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="YamatoDaiwaCS_Extensions" Version="0.3.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="YamatoDaiwaCS_Extensions" Version="0.3.0" />
                    
Directory.Packages.props
<PackageReference Include="YamatoDaiwaCS_Extensions" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add YamatoDaiwaCS_Extensions --version 0.3.0
                    
#r "nuget: YamatoDaiwaCS_Extensions, 0.3.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package YamatoDaiwaCS_Extensions@0.3.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=YamatoDaiwaCS_Extensions&version=0.3.0
                    
Install as a Cake Addin
#tool nuget:?package=YamatoDaiwaCS_Extensions&version=0.3.0
                    
Install as a Cake Tool

Yamato Daiwa CS(harp) extensions

Hero image of "Yamato Daiwa CS(sharp) Extensions" library

The extensions of the standard classes

DateOnly

  • DateOnly CreateDateOnlyFromISO8601_String(string ISO8601_String)
  • string ToISO8601_String()

DateTime

  • DateOnly CreateDateOnlyFromISO8601_String(string ISO8601_String)
  • string ToISO8601_String()

EmailAddress

Public static fields
Name VALID_PATTERN
Type Regex
Is readonly Yes

Contains the regular expression of the valid email address according w3resource.com.

Public static methods
  • bool IsValid(string potentialEmail)

Array

  • TElement[] LogEachElement<TElement>(Action<TElement>? logger = null)

Dictionary

  • Dictionary<TKey, TValue> SetPairIfValueNotIsNull<TKey, TValue>
  • SetPairIf
    • Dictionary<TKey, TValue> SetPairIf<TKey, TValue>(TKey key, TValue value, bool condition) where TKey : notnull
    • Dictionary<TKey, TValue> SetPairIf<TKey, TValue>(TKey key, TValue value, Func<TKey, TValue, bool> condition) where TKey : notnull

List

  • List<TElement> AddElementsToStart<TElement> (params TElement[] newElements)
  • List<TElement> AddElementsToEnd<TElement> (params TElement[] newElements)
  • List<TElement?> AddElementToEndIfNotNull<TElement>(TElement? newElement)
  • AddElementToEndIf
    • List<TElement> AddElementToEndIf<TElement>(TElement newElement, bool condition)
    • List<TElement> AddElementToEndIf<TElement>(TElement newElement, Func<TElement?, bool> condition)
  • StringifyEachElementAndJoin<TElement>(string separator)
  • ReplaceArrayElementsByPredicate
    • List<TElement> ReplaceArrayElementsByPredicate<TElement>(Func<TElement, bool> predicate, TElement newElement, bool mustReplaceOnlyFirstOne)
    • List<TElement> ReplaceArrayElementsByPredicate<TElement>(Func<TElement, bool> predicate, Func<TElement, TElement> replacer, bool mustReplaceOnlyFirstOne)
  • List<TElement> LogEachElement<TElement>(Action<TElement>? logger = null)

Number

  • bool IsValueOfAnyNumericType(object value)

String

  • bool IsNonEmpty()
  • string ToUpperCamelCase()
  • string ToLowerCamelCase()
  • string RemoveAllSpecifiedCharacters(char[] charactersToRemove)

System.Text.Json.Nodes.JsonObject

  • void SetProperty(this JsonObject targetObject, string dotSeparatedPath, object value)

Random values generators (RandomValuesGenerator class)

  • bool GetRandomBoolean()
  • byte GetRandomByte(byte minimalValue = Byte.MinValue, byte maximalValue = Byte.MaxValue)
  • ushort GetRandomUShort(ushort minimalValue = ushort.MinValue, ushort maximalValue = ushort.MaxValue)
  • TArrayElement GetRandomArrayElement<TArrayElement>(TArrayElement[] targetArray)
  • DateOnly GetRandomDate(DateOnly earliestDate, DateOnly latestDate)
  • DateTime GetRandomDateTime(DateOnly earliestDate, DateOnly latestDate)

Data mocking

DataMocking class

NullablePropertiesDecisionStrategies enumeration
Enumeration element Description
mustGenerateAll All nullable (optional) properties must be generated except the cases of incompatible properties.
mustGenerateWith50PercentageProbabilityIfHasNotBeenPreDefined Nullable (optional) properties must be generated with 50% probability.
mustSkipIfHasNotBeenPreDefined Nullable (optional) properties must not be randomly generated.
DecideOptionalValue static method and NullablePropertiesDecisionSourceDataAndOptions structure
TValueType? DecideOptionalValue<TValueType>(NullablePropertiesDecisionSourceDataAndOptions<TValueType> sourceDataAndOptions)
struct NullablePropertiesDecisionSourceDataAndOptions<TPropertyType>
{
  public required NullablePropertiesDecisionStrategies Strategy { get; init; }
  public required Func<TPropertyType> RandomValueGenerator? { get; init; }
  public TPropertyType? PreDefinedValue { get; init; }
}

Decides, will nullable (optional) value be available or no, and if yes, returns this value. Intended to be used when generating the properties for the class / structure.

The decision will depend mainly on specified nullable property decision strategy:

Enumeration element Description
mustGenerateAll If target nullable property has not been predefined via NullablePropertiesDecisionStrategies.PreDefinedValue, it will be generated by specified RandomValueGenerator. It means the RandomValueGenerator must be specified for this strategy, otherwise ArgumentException will be thrown.
mustGenerateWith50PercentageProbabilityIfHasNotBeenPreDefined If target nullable property has been predefined via NullablePropertiesDecisionStrategies.PreDefinedValue, this value will be returned otherwise will be generated by specified RandomValueGenerator with probability 50%. It means the RandomValueGenerator must be specified for this strategy, otherwise ArgumentException will be thrown.
mustSkipIfHasNotBeenPreDefined If target nullable property has not been predefined via NullablePropertiesDecisionStrategies.PreDefinedValue, no random value will be generated. Only for the strategy RandomValueGenerator should be omitted.

Errors classes

Error class Usage
DataRetrievingFailedException Intended to be used when the data retrieving from some external resource (server, database, file, etc.) failed.
DataSubmittingFailedException Intended to be used when the data submitting to any external resource (server, database, etc.) failed.

MockGatewayHelper class

When mock the asynchronous data transactions, takes care about such routines as

  1. Randomizing of the pending interval
  2. Simulation of the error
  3. Logging

Public static methods

SetLogger
void SetLogger(Log log)
    
delegate void Log(string message) 

Adds the logging method which will be invoked if the logging will be demanded in other methods.

SimulateDataRetrieving
Task<TResponseData> SimulateDataRetrieving<TRequestParameters, TResponseData>(
  TRequestParameters requestParameters,
  Func<TResponseData> getResponseData,
  SimulationOptions options
)

where the SimulationOptions is the associated structure will be described below.

SimulateDataSubmitting
Task<TResponseData> SimulateDataSubmitting<TRequestData, TResponseData>(
  TRequestData requestData,
  Func<TResponseData> getResponseData,
  SimulationOptions options
)

It's behaviour is almost even with SimulateDataRetrieving, but there are some differences:

  • The logging
  • DataSubmittingFailedException will be thrown instead of DataRetrievingFailedException when error simulation mode is enabled.

Associated structure SimulationOptions

public struct SimulationOptions
{
  public ushort? MinimalPendingPeriod__Seconds { get; init; }
  public ushort? MaximalPendingPeriod__Seconds { get; init; }
  public bool MustSimulateError { get; init; }
  public bool MustLogResponseData { get; init; }
  public required string GatewayName { get; init; }
  public required string TransactionName { get; init; }
}
MinimalPendingPeriod__Seconds
Type ushort
Default value 1
Use case If you want to see the loading placeholder for a while, increase this value.
MaximalPendingPeriod__Seconds
Type ushort
Default value 2
Use case If you want to see the loading placeholder for a while, increase this value.
MustSimulateError
Type bool
Default value false
Use case If you want to check is the error message displays correctly in your GUI, set this flag to true.
MustSimulateError
Type bool
Is required Yes
MustLogResponseData
Type bool
Is required Yes
Note System.Text.Json.JsonSerializer will be used for serializing.
GatewayName
Type bool
Is required Yes
Note Used for logging only. "Gateway" could be called "service" or somehow else in your code.
TransactionName
Type bool
Is required Yes
Note Used for logging only.
Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • net9.0

    • No dependencies.

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