ValueContainer 1.0.0

Generic container for packing values with built-in value initialization check.

There is a newer version of this package available.
See the version list below for details.
Install-Package ValueContainer -Version 1.0.0
dotnet add package ValueContainer --version 1.0.0
<PackageReference Include="ValueContainer" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ValueContainer --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Value assignment and validation container

Generic container for packing values with built-in value initialization check:

  Value<Sample> sampleValue = new ValueContainer<Sample>();

  // Throws ArgumentNullException here
  sampleValue.set(null);

  // Throws InvalidOperationException here
  sampleValue.validate();
  sampleValue.set(new Sample());

  // Will not throws any exceptions now
  sampleValue.validate();

  Sample sample = sampleValue.get();

Do not write value initialization check any more. Instead of:


  public class Sample
  {
    private Sample value;

    void set(Sample value)
    {
      if(value == null)
        throw new ArgumentNullException(nameof(value));
      this.value = value;
    }
  }

Write like this:


  public class Sample
  {
    private Value<Sample> value;
    public Sample()
    {
      this.value = new ValueContainer<Sample>();
    }

    void set(Sample value)
    {
      this.value.set(value);
    }
  }

Or like this. If you use any dependency injection container:


  public class Sample
  {
    private Value<Sample> value;
    public Sample(Value<Sample> value)
    {
      this.value = value;
    }

    void set(Sample value)
    {
      this.value.set(value);
    }
  }

Value assignment and validation container

Generic container for packing values with built-in value initialization check:

  Value<Sample> sampleValue = new ValueContainer<Sample>();

  // Throws ArgumentNullException here
  sampleValue.set(null);

  // Throws InvalidOperationException here
  sampleValue.validate();
  sampleValue.set(new Sample());

  // Will not throws any exceptions now
  sampleValue.validate();

  Sample sample = sampleValue.get();

Do not write value initialization check any more. Instead of:


  public class Sample
  {
    private Sample value;

    void set(Sample value)
    {
      if(value == null)
        throw new ArgumentNullException(nameof(value));
      this.value = value;
    }
  }

Write like this:


  public class Sample
  {
    private Value<Sample> value;
    public Sample()
    {
      this.value = new ValueContainer<Sample>();
    }

    void set(Sample value)
    {
      this.value.set(value);
    }
  }

Or like this. If you use any dependency injection container:


  public class Sample
  {
    private Value<Sample> value;
    public Sample(Value<Sample> value)
    {
      this.value = value;
    }

    void set(Sample value)
    {
      this.value.set(value);
    }
  }

Release Notes

Generic ValueContainer has been added.

Dependencies

This package has no dependencies.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.2 154 8/6/2019
1.0.1 101 7/29/2019
1.0.0 99 7/5/2019