Using Anonymous types (from LINQ)

Seems like there are some limitations in UiPath where either Option Strict, or Option Infer, is interfering with the ability to parse the results of a LINQ query.

Wondering if there are actually any ways for us to iterate through the properties of an anonymous type without getting late binding errors in UiPath?

A few people seem to have had some issues similar to this in the past but have gotten around it using some clever use of casting, specific to their use case.

In my specific case, my LINQ returns the following type:

IEnumerable<string,string,IEnumerable<string,integer>>

Which I would like to be able to iterate through and create data rows using (pseudocode):

For Each id In LINQ_Result
    NewRow("ID") = id.string1 <-- Late Binding error
    NewRow("State") = id.string2

    For Each property In id
        NewRow(property.Name) = property.Volume
    Next
Next

@cshan
to avoid intense castings the control can be done within the LINQ and the returns. Instead of returning an anonymous type alternate datatypes can be used e.g. keyvaluepairs / dictionaries / typed Lists / Arrays.

Another technique for dealing with different datatypes is to wotk with tuples:

1 Like

Thanks @ppr

I got it to work with tuples!

Only problem is I can’t figure out how to name my elements. I don’t know if you can in UiPath. Using LINQpad I was able to name the elements of my tuples, so the code was ultimately more readable.

In UiPath I have to refer to .item1, .item2 etc so it looks really messy. Also too much effort to define my own object class.

Think I can do better to make this more readable/friendly?

Also that data type is a new one for me for sure…

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.