(Translated by https://www.hiragana.jp/)
GitHub - DepthRel/Toolkit: .NET Toolkit include tools for comfortable dev
Skip to content

DepthRel/Toolkit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Toolkit

.NET Toolkit is a tool for simplify the development of classes, business logic, UI elements, etc.

  • Contracts - a way to verify the transferred parameters in a concise way. Contracts are intended to replace the cumbersome constructions of condition checks, such as:

    if (string.IsNullOrWhiteSpace(str?.Trim()))
    {
        throw new Exception("The value is incorrect");
    }

    Instead, just write:

    Contract.StringFilled<Exception>(str);

    The same goes for null checks:

    Contract.NotNull<object, ArgumentNullException>(obj);

    Logic checks:

    Contract.MoreOrEqualThan<int, InvalidOperationException>(first, second);
  • Check - a static class similar to the Contract class, but returns a Boolean value instead of throwing an exception.

    if (Check.NotNull<object>(obj)) // true if obj isn't null

    String checks:

    string str = "";
    if (Check.StringFilled(str)) // false because str is empty
  • Condition - allows you to build a chain of logical conditions.

    int a = 10;
    int b = 20;
    var result = Condition
                 .Check(a == 10)
                 .And(b == 20);
                 .Or(b == 5)
                 .Not() // now it's false
  • And others...
  • BaseViewModel contains an implementation of the INotifyPropertyChanged interface with the OnPropertyChanged() method to notify observers about a change in the value of the observed object.

    The generic SetProperty method is designed to assign values to observable objects and notify about their change.

  • IMessage is an interface for solving the problem of calling a dialog from a ViewModel without interacting with the View layer.

    // View layer
    public class Message : IMessage
    {
        public void Report() { MessageBox.Show("Message for user" );
    }
    
    public MainWindow()
    {
        DataContext = new ViewModel(new Message());
    }
    
    // ViewModel layer
    class ViewModel
    {
        public ViewModel(IMessage message)
        {
            message.Report();
        }
    }
  • And others...

See wiki for more details.

DepthRel, 2020