XSharpPublic icon indicating copy to clipboard operation
XSharpPublic copied to clipboard

Feature request: List support in Macro expression

Open ArneOrtlinghaus opened this issue 4 years ago • 4 comments

We would like to reference list elements of generic lists like var olist := List{} in macro expression in the form |olist|olist[1]

Describe the solution you'd like Currently this finishes with an exception "Conversion error from usual (object) to array

Describe alternatives you've considered An example is in the attached program in the function testmacrolist()

Additional context Add any other context or screenshots about the feature request here. Program.zip macrolisterror

ArneOrtlinghaus avatar Sep 21 '21 13:09 ArneOrtlinghaus

Arne, This will be difficult, since there is no real context from which the macro compiler can read the type of the usual. Even if we would not cast the usual to array and if we would use the index properties of the usual type at runtime, what would you expect then to happen with the index. Would you expect that the index would be 0 based (like for the List<> class) or would the index be 1 based (like for arrays).

Have you tried explicitly casting like this: o:testmacrop1("((System.Collections.IList)olist)[1]", "olist", olist)

I know that casting to a generic type does not work yet. This is on our todo list. So this will not work: o:testmacrop1("((System.Collections.Generic.IList<int>)olist)[1]", "olist", olist)

Robert

RobertvanderHulst avatar Sep 21 '21 14:09 RobertvanderHulst

Robert,

thank you. This works: o:testmacrop1("((System.Collections.IList)olist)[1]", "olist", olist)

We were only thinking about this possibility. We understand that it is difficult because the context is missing indeed.

ArneOrtlinghaus avatar Sep 21 '21 14:09 ArneOrtlinghaus

Would you expect that the index would be 0 based (like for the List<> class) or would the index be 1 based (like for arrays). I would expect 0 based as is also in the hard coded variant.

ArneOrtlinghaus avatar Sep 21 '21 14:09 ArneOrtlinghaus

Nikos is going to add support for parsing generic types in one of the next builds of the macro compiler. In that case you should also be able to cast it to (System.Collections.Generic.IList)olist)[1]

RobertvanderHulst avatar Sep 21 '21 14:09 RobertvanderHulst