|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Markup;
using System.Windows.Data;
using System.ComponentModel;
using Signum.Utilities;
using Signum.Utilities.DataStructures;
namespace Signum.Windows
{
[MarkupExtensionReturnType(typeof(object[]))]
[DefaultProperty("Type")]
public class EnumValuesExtension : MarkupExtension
{
Type type;
public Type Type
{
get { return type; }
set { type = value; }
}
bool sort;
public bool Sort
{
get { return sort; }
set { sort = value; }
}
bool nicePairs;
public bool NicePairs
{
get { return nicePairs; }
set { nicePairs = value; }
}
public override object ProvideValue(IServiceProvider serviceProvider)
{
var values = Enum.GetValues(Type).Cast<object>();
if (nicePairs)
{
var valuePairs = values.Select(a => new Tuple<object, string>(a, EnumExtensions.NiceToString(a)));
if (sort)
valuePairs = valuePairs.OrderBy(a => a.Second);
return valuePairs.ToArray();
}
else
{
if (sort)
values = values.OrderBy(a => a.ToString());
return values.ToArray();
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I'm Computer Scientist, one of the founders of Signum Software, and the lead developer behind Signum Framework.
www.signumframework.com
I love programming in C#, Linq, Compilers, Algorithms, Functional Programming, Computer Graphics, Maths...