Xpandable.Practices.QrCode

QrCode classes for .Net.


Keywords
QrCode...
License
Apache-2.0
Install
Install-Package Xpandable.Practices.QrCode -Version 2.5.0

Documentation

Xpandable-Practices

Provides with useful interfaces contracts in .Net Standard and some implementations in .Net Core, mostly following the spirit of SOLID principles, such as DDD, ICommandHandler, IMediator and so on.

Use of Contracts

public User(string name, int age, ...)
{
    Name = name.WhenNull()
               .ThrowArgumentNullException(nameof(name));
    Age = age.WhenNotInRange(18, 50)
             .ThrowArgumentOutOfRangeException(); //  Will contain a default message.
    
    ...
    Name = name.WhenConditionFailed(value => value.Length < 30)
               .ThrowException<ArgumentException>("custom message");
    
    // You can chain conditions :
    Name = name.WhenNull()
                  .ThrowArgumentNullException(nameof(name))
                .WhenConditionFailed(value => value.Length < 30)
                  .ThrowException<ArgumentException>("custom message");
    
    // You can replace a value :
    Name = name.WhenConditionFailed(....)
               .Return("another value"); // or use a delegate.
}

Use of Optional{T}

There is a specific implementation of F# Options you can find in Optional with asynchronous behavior.

Use of specific implementation of F# Option to avoid null checks.

Without option :

public User FindUser(string userName, string password)
{
        var foundUser = userRepo.FindUserByName(userName);
        if(foundUser != null)
         {
             var isValidPWD = foundUser.PasswordIsValid(password, passwordService);
             if(isValidPWD)
                  return foundUser;
             else ....
         }
         ...
}

With option :

public User FindUser(string userName, string password)
{
    return userRepo.TryFindUserByName(userName)
         .Map(user => user.PasswordIsValid(password, passwordService)) 
         .Reduce(()=> throw ...);
}

// This code 'Map(user => user.PasswordIsValid(password, passwordService))' will be executed only if userRepo contains a value.
// PasswordIsValid returns the current user instance or throws an exception.
// Reduce(()=> throw ...) will be executed only if userRepo is empty.

Or

public Optional<User> TryFindUser(string userName, string password)
   => userRepo.TryFindUserByName(userName)
         .MapOptional(user => user.PasswordIsValid(password, passwordService));
         
// PasswordIsValid returns an Optional<User> with the current user instance if Ok or empty.

Use of Enumeration, a helper class to implement custom enumeration.

public abstract class Enumeration : IEqualityComparer<Enumeration>, IEquatable<Enumeration>, IComparable<Enumeration>
{
    protected Enumeration(string displayName, int value)
    {
        Value = value;
        DisplayName = displayName ?? throw new ArgumentNullException(nameof(displayName));
    }
    ....
    
    with useful methods :
    
    public static IEnumerable<TEnumeration> GetAll<TEnumeration>()...
    
    public static TEnumeration FromDisplayName<TEnumeration>(string displayName)
        where TEnumeration : Enumeration ...        
}

// You can use the EnumerationTypeConverter to convert "Enumeration" objects to and from string representations.

Xpandable-Practices-GraphQL

A starting point to generate GraphQL schema without ObjectGraphType implementation. Use of GraphQL.Net.

A working example can be found here.

Feel free to fork this project, make your own changes and create a pull request.