diff options
| author | Lucas Faria Mendes <lucas.fariamo08@gmail.com> | 2026-03-30 13:38:18 +0000 |
|---|---|---|
| committer | Lucas Faria Mendes <lucas.fariamo08@gmail.com> | 2026-03-30 13:38:18 +0000 |
| commit | 1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1 (patch) | |
| tree | e1c3b20ea08f0cf71122a1e73f0d395f8fd83874 /Codemerx/Gestor.Common/Gestor.Common.Helpers/EnumBindingSourceExtension.cs | |
| parent | 674ca83ba9243a9e95a7568c797668dab6aee26a (diff) | |
| download | gestor-1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1.tar.gz gestor-1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1.zip | |
chore: location
Diffstat (limited to 'Codemerx/Gestor.Common/Gestor.Common.Helpers/EnumBindingSourceExtension.cs')
| -rw-r--r-- | Codemerx/Gestor.Common/Gestor.Common.Helpers/EnumBindingSourceExtension.cs | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/Codemerx/Gestor.Common/Gestor.Common.Helpers/EnumBindingSourceExtension.cs b/Codemerx/Gestor.Common/Gestor.Common.Helpers/EnumBindingSourceExtension.cs new file mode 100644 index 0000000..7ce699e --- /dev/null +++ b/Codemerx/Gestor.Common/Gestor.Common.Helpers/EnumBindingSourceExtension.cs @@ -0,0 +1,59 @@ +using System;
+using System.Windows.Markup;
+
+namespace Gestor.Common.Helpers
+{
+ public class EnumBindingSourceExtension : MarkupExtension
+ {
+ private Type _enumType;
+
+ public Type EnumType
+ {
+ get
+ {
+ return this._enumType;
+ }
+ set
+ {
+ if (value == this._enumType)
+ {
+ return;
+ }
+ if (null != value)
+ {
+ if (!(Nullable.GetUnderlyingType(value) ?? value).IsEnum)
+ {
+ throw new ArgumentException("Type must be for an Enum.");
+ }
+ }
+ this._enumType = value;
+ }
+ }
+
+ public EnumBindingSourceExtension()
+ {
+ }
+
+ public EnumBindingSourceExtension(Type enumType)
+ {
+ this.EnumType = enumType;
+ }
+
+ public override object ProvideValue(IServiceProvider serviceProvider)
+ {
+ if (null == this._enumType)
+ {
+ throw new InvalidOperationException("The EnumType must be specified.");
+ }
+ Type underlyingType = Nullable.GetUnderlyingType(this._enumType) ?? this._enumType;
+ Array values = Enum.GetValues(underlyingType);
+ if (underlyingType == this._enumType)
+ {
+ return values;
+ }
+ Array arrays = Array.CreateInstance(underlyingType, values.Length + 1);
+ values.CopyTo(arrays, 1);
+ return arrays;
+ }
+ }
+}
\ No newline at end of file |