// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
namespace Microsoft.Extensions.Localization
{
///
/// A locale specific string.
///
public class LocalizedString
{
///
/// Creates a new .
///
/// The name of the string in the resource it was loaded from.
/// The actual string.
public LocalizedString(string name, string value)
: this(name, value, resourceNotFound: false)
{
}
///
/// Creates a new .
///
/// The name of the string in the resource it was loaded from.
/// The actual string.
/// Whether the string was not found in a resource. Set this to true to indicate an alternate string value was used.
public LocalizedString(string name, string value, bool resourceNotFound)
: this(name, value, resourceNotFound, searchedLocation: null)
{
}
///
/// Creates a new .
///
/// The name of the string in the resource it was loaded from.
/// The actual string.
/// Whether the string was not found in a resource. Set this to true to indicate an alternate string value was used.
/// The location which was searched for a localization value.
public LocalizedString(string name, string value, bool resourceNotFound, string searchedLocation)
{
if (name == null)
{
throw new ArgumentNullException(nameof(name));
}
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
Name = name;
Value = value;
ResourceNotFound = resourceNotFound;
SearchedLocation = searchedLocation;
}
public static implicit operator string(LocalizedString localizedString)
{
return localizedString?.Value;
}
///
/// The name of the string in the resource it was loaded from.
///
public string Name { get; }
///
/// The actual string.
///
public string Value { get; }
///
/// Whether the string was not found in a resource. If true, an alternate string value was used.
///
public bool ResourceNotFound { get; }
///
/// The location which was searched for a localization value.
///
public string SearchedLocation { get; }
///
/// Returns the actual string.
///
/// The actual string.
public override string ToString() => Value;
}
}