-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from andyvans/multiscreen-enhancements
Multiscreen enhancements
- Loading branch information
Showing
9 changed files
with
136 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System.ComponentModel; | ||
|
||
namespace Mamesaver.Models.Configuration | ||
{ | ||
public enum MamePrimaryScreen | ||
{ | ||
[Description("Highest resolution display")] | ||
HighestResolution, | ||
|
||
[Description("Primary display")] | ||
WindowsPrimary | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using System; | ||
using System.ComponentModel; | ||
using System.Linq; | ||
using System.Windows.Markup; | ||
|
||
namespace Mamesaver.Models.Extensions | ||
{ | ||
/// <summary> | ||
/// Provide metadata about enumerations | ||
/// </summary> | ||
public class EnumerationExtension : MarkupExtension | ||
{ | ||
private Type _enumType; | ||
|
||
public EnumerationExtension(Type enumType) | ||
{ | ||
EnumType = enumType ?? throw new ArgumentNullException(nameof(enumType)); | ||
} | ||
|
||
public Type EnumType | ||
{ | ||
get => _enumType; | ||
private set | ||
{ | ||
if (_enumType == value) return; | ||
|
||
var enumType = Nullable.GetUnderlyingType(value) ?? value; | ||
if (enumType.IsEnum == false) throw new ArgumentException("Type must be an Enum"); | ||
|
||
_enumType = value; | ||
} | ||
} | ||
|
||
public override object ProvideValue(IServiceProvider serviceProvider) | ||
{ | ||
var enumValues = Enum.GetValues(EnumType); | ||
|
||
return ( | ||
from object enumValue in enumValues | ||
select new EnumerationMember | ||
{ | ||
Value = enumValue, | ||
Description = GetDescription(enumValue) | ||
}).ToArray(); | ||
} | ||
|
||
private string GetDescription(object enumValue) | ||
{ | ||
var descriptionAttribute = EnumType | ||
.GetField(enumValue.ToString()) | ||
.GetCustomAttributes(typeof(DescriptionAttribute), false) | ||
.FirstOrDefault() as DescriptionAttribute; | ||
|
||
return descriptionAttribute != null | ||
? descriptionAttribute.Description | ||
: enumValue.ToString(); | ||
} | ||
|
||
public class EnumerationMember | ||
{ | ||
public string Description { get; set; } | ||
public object Value { get; set; } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.