changement de candidat à l'investissement

This commit is contained in:
Paul Schneider 2017-01-26 11:04:03 +01:00
commit be3087fff6
351 changed files with 359 additions and 497 deletions

View file

@ -0,0 +1,43 @@
using BookAStar.Attributes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace BookAStar.Extensions
{
public static class EnumExtensions
{
public static string GetDescription(this Enum value)
{
var type = value.GetType();
var typeInfo = type.GetTypeInfo();
var declaredMember = typeInfo.DeclaredMembers.FirstOrDefault(i => i.Name == value.ToString());
var attribute = declaredMember?.GetCustomAttribute<DisplayAttribute>();
return attribute == null ? value.ToString() : attribute.Description;
}
public static IEnumerable<string> GetDescriptions(Type type)
{
var values = Enum.GetValues(type).Cast<Enum>();
var descriptions = new List<string>();
foreach (var value in values)
{
descriptions.Add(value.GetDescription());
}
return descriptions;
}
public static Enum GetEnumFromDescription(string description, Type enumType)
{
var enumValues = Enum.GetValues(enumType).Cast<Enum>();
var descriptionToEnum = enumValues.ToDictionary(k => k.GetDescription(), v => v);
return descriptionToEnum[description];
}
}
}

View file

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace BookAStar.Extensions
{
[ContentProperty("Source")]
public class ImageResourceExtension : IMarkupExtension
{
public string Source { get; set; }
public object ProvideValue(IServiceProvider serviceProvider)
{
if (Source == null)
return null;
var imageSource = ImageSource.FromResource(Source);
return imageSource;
}
}
}