changement de candidat à l'investissement
This commit is contained in:
parent
8114c2409c
commit
be3087fff6
351 changed files with 359 additions and 497 deletions
43
ZicMoove/ZicMoove/Extensions/EnumExtensions.cs
Normal file
43
ZicMoove/ZicMoove/Extensions/EnumExtensions.cs
Normal 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];
|
||||
}
|
||||
}
|
||||
}
|
||||
24
ZicMoove/ZicMoove/Extensions/ImageResourceExtension.cs
Normal file
24
ZicMoove/ZicMoove/Extensions/ImageResourceExtension.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue