© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
8 replies
Sven ☕

❔ Can I generalise this method?

public static IEnumerable<Enum> TransformIdToEnums(string value, params Type[] enums)
{
    string[] values = value.Split(',');
    for (int i = 0; i < enums.Length; i++)
    {
        var type = enums[i];
        yield return (Enum)Converter.GetEnumFromValue<type>(values[i]);
    }
}
public static IEnumerable<Enum> TransformIdToEnums(string value, params Type[] enums)
{
    string[] values = value.Split(',');
    for (int i = 0; i < enums.Length; i++)
    {
        var type = enums[i];
        yield return (Enum)Converter.GetEnumFromValue<type>(values[i]);
    }
}

Lets say I pass in "0,3,2" - I also want to pass in the Types of the Enusm I want to get them converted as. For example I split them into three different Enums, 0 being the category, 3 the subcategory and 2 a list item.
Any way to generalise this?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Generalise Attributes?
C#CC# / help
3y ago
✅ How to optimize this method?
C#CC# / help
2y ago
Big problem with this method
C#CC# / help
3y ago