Class NotNull
Provides static utilities for NotNull.
Inheritance
System.Object
NotNull
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: Maki
Assembly: Maki.dll
Syntax
public static class NotNull
Examples
The following example shows how to use NotNull.MakeOptional to convert a potentially null value into an Optional that either contains Nothing or a NotNull value.using System;
using Maki;
namespace Samples
{
class Program
{
// No need to check argument before using it, it can never be null
static void UseValue(NotNull<string> value)
{
Console.WriteLine(value.Item);
}
static void Main(string[] args)
{
// An instance that could be null
string valueOrNull = null;
if (DateTime.Today.DayOfWeek == DayOfWeek.Friday)
valueOrNull = "It's Friday!";
// Converts a potentially null value into an Optional
Optional<NotNull<string>> optionalValue = NotNull.MakeOptional(valueOrNull);
// Check that the Optional contains a value
if (optionalValue.HasValue)
{
// Get NonNull from Optional
UseValue(optionalValue.Get());
}
}
}
}
Methods
| Improve this Doc View SourceMake<T>(T)
Creates a new NotNull from the given object.
Declaration
public static NotNull<T> Make<T>(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | Object to store. |
Returns
Type | Description |
---|---|
NotNull<T> |
Type Parameters
Name | Description |
---|---|
T | Item type. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | Thrown if the argument is null. |
MakeOptional<T>(T)
Creates an Optional from the given object which is either Nothing if the
object is null or NotNull if the object is not null.
Declaration
public static Optional<NotNull<T>> MakeOptional<T>(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | Object to store. |
Returns
Type | Description |
---|---|
Optional<NotNull<T>> | NotNull if object is not null, Nothing otherwise. |
Type Parameters
Name | Description |
---|---|
T | Item type. |