Skip to content

Commit

Permalink
#144 Inherit CultureAttribute from MulticastAttribute
Browse files Browse the repository at this point in the history
  • Loading branch information
YevgeniyShunevych committed Feb 26, 2018
1 parent 23223b0 commit 51995d0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 18 deletions.
20 changes: 3 additions & 17 deletions src/Atata/Attributes/CultureAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
using System;
using System.Globalization;

namespace Atata
namespace Atata
{
/// <summary>
/// Specifies the culture of a component.
/// </summary>
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Class | AttributeTargets.Assembly)]
public class CultureAttribute : Attribute
public class CultureAttribute : MulticastAttribute
{
public CultureAttribute(string value = null)
public CultureAttribute(string value)
{
Value = value;
}
Expand All @@ -18,15 +14,5 @@ public CultureAttribute(string value = null)
/// Gets the culture value.
/// </summary>
public string Value { get; private set; }

public bool HasValue
{
get { return !string.IsNullOrWhiteSpace(Value); }
}

public CultureInfo GetCultureInfo()
{
return HasValue ? new CultureInfo(Value) : CultureInfo.CurrentCulture;
}
}
}
4 changes: 3 additions & 1 deletion src/Atata/UIComponentMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ private IEnumerable<TAttribute> FilterAndOrderByTarget<TAttribute>(IEnumerable<T
/// <returns>The <see cref="CultureInfo"/> instance.</returns>
public CultureInfo GetCulture()
{
return (Get<CultureAttribute>(AttributeLevels.All, x => x.HasValue) ?? new CultureAttribute()).GetCultureInfo();
string cultureName = Get<CultureAttribute>(AttributeLevels.All)?.Value;

return cultureName != null ? CultureInfo.GetCultureInfo(cultureName) : CultureInfo.CurrentCulture;
}

/// <summary>
Expand Down

0 comments on commit 51995d0

Please sign in to comment.