2012-10-04 07:20:13 -02:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Globalization;
|
2012-10-04 07:06:01 -02:00
|
|
|
|
using System.Reflection;
|
2012-10-04 07:20:13 -02:00
|
|
|
|
using System.Runtime.Serialization;
|
2012-10-04 07:06:01 -02:00
|
|
|
|
using Umbraco.Core.Models.EntityBase;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Core.Models
|
|
|
|
|
|
{
|
2012-10-04 07:20:13 -02:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Represents a Language
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[Serializable]
|
|
|
|
|
|
[DataContract(IsReference = true)]
|
2012-10-24 12:22:52 -02:00
|
|
|
|
public class Language : Entity, ILanguage
|
2012-10-04 07:06:01 -02:00
|
|
|
|
{
|
|
|
|
|
|
private string _isoCode;
|
|
|
|
|
|
private string _cultureName;
|
|
|
|
|
|
|
|
|
|
|
|
public Language(string isoCode)
|
|
|
|
|
|
{
|
|
|
|
|
|
IsoCode = isoCode;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-06-21 18:11:03 +02:00
|
|
|
|
private static readonly Lazy<PropertySelectors> Ps = new Lazy<PropertySelectors>();
|
|
|
|
|
|
|
|
|
|
|
|
private class PropertySelectors
|
|
|
|
|
|
{
|
|
|
|
|
|
public readonly PropertyInfo IsoCodeSelector = ExpressionHelper.GetPropertyInfo<Language, string>(x => x.IsoCode);
|
|
|
|
|
|
public readonly PropertyInfo CultureNameSelector = ExpressionHelper.GetPropertyInfo<Language, string>(x => x.CultureName);
|
|
|
|
|
|
}
|
2012-10-04 07:06:01 -02:00
|
|
|
|
|
2012-10-04 07:20:13 -02:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets or sets the Iso Code for the Language
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[DataMember]
|
2012-10-04 07:06:01 -02:00
|
|
|
|
public string IsoCode
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return _isoCode; }
|
2016-06-21 20:43:02 +02:00
|
|
|
|
set { SetPropertyValueAndDetectChanges(value, ref _isoCode, Ps.Value.IsoCodeSelector); }
|
2012-10-04 07:06:01 -02:00
|
|
|
|
}
|
|
|
|
|
|
|
2012-10-04 07:20:13 -02:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets or sets the Culture Name for the Language
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[DataMember]
|
2012-10-04 07:06:01 -02:00
|
|
|
|
public string CultureName
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return _cultureName; }
|
2016-06-21 20:43:02 +02:00
|
|
|
|
set { SetPropertyValueAndDetectChanges(value, ref _cultureName, Ps.Value.CultureNameSelector); }
|
2012-10-04 07:06:01 -02:00
|
|
|
|
}
|
|
|
|
|
|
|
2012-10-04 07:20:13 -02:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Returns a <see cref="CultureInfo"/> object for the current Language
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[IgnoreDataMember]
|
2012-10-04 07:06:01 -02:00
|
|
|
|
public CultureInfo CultureInfo
|
|
|
|
|
|
{
|
2015-11-18 14:13:32 +01:00
|
|
|
|
get { return CultureInfo.GetCultureInfo(IsoCode); }
|
2012-10-04 07:06:01 -02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|