Skip to content
Daniel edited this page Aug 16, 2020 · 5 revisions

CodeMonkeys.Core

Nuget

The CodeMonkeys.Core package contains interfaces and helper classes which are used by the other framework packages.

Activator

Instead of the System.Activator class we are using an lambda expression based Activator class for instantiating objects on runtime. The Activator is used by the CodeMonkeys.Navigation.* and the CodeMonkeys.DependencyInjection package.

Sample:

// strongly typed return value
Activator.CreateInstance<MyType>(
    "arg1", 
    "arg2");

// object (untyped) return value
Activator.CreateInstance(
    typeof(MyType), 
    "arg1", 
    "arg2");

Important:

  • Always pass the correct constructor parameters - count, order, type!
  • The activator is able to create a instance with a public or an internal constructor only!

Guards

Instead of repeatedly writing throw new ArgumentNullException(...) and so on, we have static guard classes which are used internally by the framework.

Argument

The Argument class contains mechanisms for validating passed method parameters. Here you can find classic stuff like Argument.NotNull, Argument.NotEmptyOrWhiteSpace or Argument.GreaterThan.

Sample:

public void Method(string param1)
{
    Argument.NotEmptyOrWhiteSpace(
        param1,
        nameof(param1),
        "Custom message");
}

// throws ArgumentException
Method(string.Empty);

Property

The same like the Argument class but specially for properties.

Sample:

public string Property
{
    get => GetValue<string>();
    set
    {
        Property.NotEmptyOrWhiteSpace(value);
        SetValue(value);
    }   
}

// throws ArgumentException
Property = string.Empty;

TaskHelper

The TaskHelper is internally used to call the async InitializeAsync method of types which implement the IViewModel interface. It offers different overloads to work with it.

Clone this wiki locally