still fixing git stuff

This commit is contained in:
mgroves 2011-02-05 20:52:15 -05:00
parent e4b07dd8d9
commit d53d393bd6
3 changed files with 41 additions and 2 deletions

View file

@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using MonoStockPortfolio.Entities;
namespace MonoStockPortfolio.Core
{
public static class EnumExtensions
{
/// Will get the string value attribute for a given enums value, this will
/// only work if you assign the StringValue attribute to
/// the items in your enum.
public static string GetStringValue(this Enum value)
{
var type = value.GetType();
var fieldInfo = type.GetField(value.ToString());
var attributes = fieldInfo.GetCustomAttributes(typeof(StringValueAttribute), false) as StringValueAttribute[];
if (attributes != null)
{
return attributes.Length > 0 ? attributes[0].StringValue : string.Empty;
}
return string.Empty;
}
public static IEnumerable<T> GetValues<T>(this Enum value)
{
var enumerations = new List<Enum>();
var fields = value.GetType().GetFields(BindingFlags.Static | BindingFlags.Public);
foreach (var fieldInfo in fields)
{
enumerations.Add((Enum)fieldInfo.GetValue(value));
}
return enumerations.Cast<T>();
}
}
}

View file

@ -41,8 +41,8 @@
<Compile Include="Config\AndroidSqliteConfigRepository.cs" />
<Compile Include="Config\IConfigRepository.cs" />
<Compile Include="DictionaryExtensions.cs" />
<Compile Include="EnumExtensions.cs" />
<Compile Include="AndroidSqliteBase.cs" />
<Compile Include="EnumExtensions.cs" />
<Compile Include="PortfolioRepositories\AndroidSqlitePortfolioRepository.cs" />
<Compile Include="PortfolioRepositories\IPortfolioRepository.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />

View file

@ -4,10 +4,10 @@ using Android.App;
using Android.Content;
using Android.OS;
using Android.Preferences;
using MonoStockPortfolio.Core;
using MonoStockPortfolio.Core.Config;
using MonoStockPortfolio.Entities;
using MonoStockPortfolio.Framework;
using MonoStockPortfolio.Core;
namespace MonoStockPortfolio.Activites
{