Skip to content

Commit 099d925

Browse files
committed
+ Added support map IEnumerable<int>/IEnumerable<long>and List<int>
1 parent 137c77b commit 099d925

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

src/FlowCommandLine/FlowPropertyMapper.cs

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public static class FlowPropertyMapper {
77

88
public static PropertyInfo? GetPropertyFromParameter ( FlowCommandParameter parameter, IEnumerable<PropertyInfo> properties ) {
99
if ( !string.IsNullOrEmpty ( parameter.PropertyName ) ) return properties.FirstOrDefault ( a => a.Name.ToLowerInvariant () == parameter.PropertyName.ToLowerInvariant () );
10-
if ( !string.IsNullOrEmpty ( parameter.FullName ) ) return properties.FirstOrDefault ( a => a.Name.ToLowerInvariant () == parameter.FullName.ToLowerInvariant() );
10+
if ( !string.IsNullOrEmpty ( parameter.FullName ) ) return properties.FirstOrDefault ( a => a.Name.ToLowerInvariant () == parameter.FullName.ToLowerInvariant () );
1111
if ( !string.IsNullOrEmpty ( parameter.ShortName ) ) return properties.FirstOrDefault ( a => a.Name.ToLowerInvariant () == parameter.ShortName.ToLowerInvariant () );
1212

1313
return null;
@@ -34,12 +34,44 @@ public static bool SetPropertyValue<T> ( Type type, Dictionary<string, string> v
3434
isChanged = true;
3535
}
3636
break;
37+
case Type _ when type == typeof ( IEnumerable<int> ):
38+
if ( values.ContainsKey ( parameterKey ) ) {
39+
property.SetValue ( model, MapIntegerCollections ( values, parameterKey ) );
40+
isChanged = true;
41+
}
42+
break;
43+
case Type _ when type == typeof ( List<int> ):
44+
if ( values.ContainsKey ( parameterKey ) ) {
45+
property.SetValue ( model, MapIntegerCollections ( values, parameterKey ) );
46+
isChanged = true;
47+
}
48+
break;
3749
case Type _ when type == typeof ( long ):
3850
if ( values.ContainsKey ( parameterKey ) && long.TryParse ( values[parameterKey], out var int64value ) ) {
3951
property.SetValue ( model, int64value );
4052
isChanged = true;
4153
}
4254
break;
55+
case Type _ when type == typeof ( IEnumerable<long> ):
56+
if ( values.ContainsKey ( parameterKey ) ) {
57+
var longValues = values[parameterKey]
58+
.Split ( "," )
59+
.Select (
60+
a => {
61+
if ( long.TryParse ( values[parameterKey], out var int64value ) ) {
62+
return (long?) int64value;
63+
} else {
64+
return null;
65+
}
66+
}
67+
)
68+
.Where ( a => a != null )
69+
.ToList ();
70+
71+
property.SetValue ( model, longValues );
72+
isChanged = true;
73+
}
74+
break;
4375
case Type _ when type == typeof ( double ):
4476
if ( values.ContainsKey ( parameterKey ) && double.TryParse ( values[parameterKey], CultureInfo.InvariantCulture, out var doublevalue ) ) {
4577
property.SetValue ( model, doublevalue );
@@ -84,6 +116,22 @@ public static bool SetPropertyValue<T> ( Type type, Dictionary<string, string> v
84116
return isChanged;
85117
}
86118

119+
private static List<int> MapIntegerCollections ( Dictionary<string, string> values, string parameterKey ) {
120+
return values[parameterKey]
121+
.Split ( "," )
122+
.Select (
123+
a => {
124+
if ( int.TryParse ( a, out var int32value ) ) {
125+
return (int?) int32value;
126+
} else {
127+
return null;
128+
}
129+
}
130+
)
131+
.Where ( a => a != null )
132+
.Select ( a => a.Value )
133+
.ToList ();
134+
}
87135
}
88136

89137
}

0 commit comments

Comments
 (0)