namespace TestOptionalNullParameters
public string BrandProp { get; set; }
static void Main(string[] args)
Product product = new Product();
Brand brand = new Brand() { BrandProp = "Set in Main" };
Console.WriteLine("Result when calling with GenerateArticle(product, brand):");
Console.WriteLine("-------------------------------------------------------------------");
GenerateArticle(product, brand);
Console.WriteLine("Result when calling with GenerateArticle(product, null, null):");
Console.WriteLine("-------------------------------------------------------------------");
GenerateArticle(product, null);
Console.WriteLine("Result when calling with GenerateArticle(product):");
Console.WriteLine("-------------------------------------------------------------------");
GenerateArticle(product);
public static void GenerateArticle(Product product, Maybe<Brand> maybeBrand = new Maybe<Brand>())
Brand brand = maybeBrand.IsSet
: new Brand() { BrandProp = "Fallback brand" };
Console.WriteLine($"product={product} ");
Console.WriteLine($"brand={brand?.BrandProp} ");
public bool IsSet { get; }
public static implicit operator Maybe<T>(T obj)
return new Maybe<T>(obj);