| File: Optional`1.cs | Web Access |
| Project: src\roslyn\src\Razor\src\Shared\Microsoft.AspNetCore.Razor.Utilities.Shared\Microsoft.AspNetCore.Razor.Utilities.Shared.csproj (Microsoft.AspNetCore.Razor.Utilities.Shared) |
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. namespace Microsoft.AspNetCore.Razor; public readonly struct Optional<T>(T value) { public bool HasValue { get; } = true; public T Value { get; } = value; public T GetValueOrDefault(T defaultValue) => HasValue ? Value : defaultValue; public static implicit operator Optional<T>(T value) => new(value); public override string ToString() => HasValue ? Value?.ToString() ?? "null" : "unspecified"; }