📅  最后修改于: 2022-03-11 14:49:07.792000             🧑  作者: Mango
public static class StringEnumerableExtensions {
public static IEnumerable StringsToEnums( this IEnumerable strs) where T : struct, IConvertible {
Type t = typeof( T );
var ret = new List();
if( t.IsEnum ) {
T outStr;
foreach( var str in strs ) {
if( Enum.TryParse( str, out outStr ) ) {
ret.Add( outStr );
}
}
}
return ret;
}
}