Skip to content
Discussion options

You must be logged in to vote

The short answer is yes, any type can support custom deconstruction via extension methods.

However, if you're referring to the non-generic System.Collections.IDictionary this is complicated by the fact that it implements System.Collections.IEnumerable which effectively enumerates all values as System.Object. An extension method to deconstruct System.Object is possible but wouldn't apply in most situations, so what I might suggest is an extension method on IDictionary that returns IEnumerable<DictionaryEntry> which would be safe to deconstruct:

public static class IDictionaryExtensions {
    // returns a type-safe enumerable of each entry
    public static IEnumerable<DictionaryEntry> Entries

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by WeihanLi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants