Skip to content

Commit 6d5987e

Browse files
author
Jason Becker
committed
Add Flags enum entry and update GetUnitTypeByAttributes method
- Added the Flags entry to the EntryUnitType enum to represent unit types with the Flags attribute. - Updated the GetUnitTypeByAttributes method to check if the property is an enum and has the Flags attribute.
1 parent 6df66e8 commit 6d5987e

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/Moryx/Serialization/DefaultSerialization.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public virtual object ConvertValue(Type memberType, ICustomAttributeProvider att
221221
return CollectionBuilder(memberType, currentValue, mappedEntry);
222222
default:
223223
var value = mappedEntry.Value.Current;
224-
if (value is null)
224+
if (value is null)
225225
return null;
226226

227227
try
@@ -251,6 +251,15 @@ public EntryUnitType GetUnitTypeByAttributes(ICustomAttributeProvider property)
251251
{
252252
var unitType = EntryUnitType.None;
253253

254+
// Check if the property is an enum and has the <see cref="System.FlagsAttribute"/>
255+
if (property is PropertyInfo propertyInfo && propertyInfo.PropertyType.IsEnum)
256+
{
257+
if (propertyInfo.PropertyType.GetCustomAttributes(typeof(System.FlagsAttribute), false).Any())
258+
{
259+
unitType = EntryUnitType.Flags;
260+
}
261+
}
262+
254263
var passwordAttr = property.GetCustomAttribute<PasswordAttribute>();
255264
if (passwordAttr != null)
256265
unitType = EntryUnitType.Password;

src/Moryx/Serialization/EntryConvert/EntryUnitType.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ public enum EntryUnitType
2323
/// <summary>
2424
/// Unit directory
2525
/// </summary>
26-
Directory
26+
Directory,
27+
/// <summary>
28+
/// Unit with <see cref="System.FlagsAttribute"/>
29+
/// </summary>
30+
Flags,
2731
}
2832
}

0 commit comments

Comments
 (0)