-
Notifications
You must be signed in to change notification settings - Fork 9
ElementCollection implementing IEnumerable<Element> #15
Comments
Unfortunately, that is not possible because they do not comply with the contract for |
What about to provide something like external interfaces. When an extenal interface is obtained from the class: // C#
IEnumerable<Element> Foo(ElementCollection elements)
{
return elements;
} The compiler will create a wrapper: // JavaScript
function foo(elements) {
return new ElementCollectionEnumerable(elements);
} |
It is a good idea, I have been thinking something similar myself. However, I don't think the ElementCollectionEnumerable idea will work (I do not want users to be required to add additional JS to use the web reference assembly), but I think the generated code could be something like
or something like that. This could also be used for things like (illegal today)
by causing an identity conversion from C to IA and/or IB to generate such proxy interface type. Notes for implementation:
fails for |
In the meantime, putting an extension method on ElementCollection and/or other classes with methods returning them might be a simple fix for you n9. I use something like this
Being able to define some sort of implicit cast for ElementCollection could also be helpful, but I don't really know if that's possible through extensions in C#. |
Unfortunately it is not possible to define conversion operators to and from interfaces in C#, otherwise that would have probably been the best solution |
My idea is to specify the behavior using attributes. One attribute could be: [ExplicitExternalInterface(typeof(IEnumerable<Element>), typeof(ElementCollectionEnumerable))] where The other attribute could be: [ImplicitExternalInterface(typeof(IEnumerable<Element>))] in this case the external interface implementation is composed from the methods (e.g. with inline code) which are present on the class. |
Where is your ElementCollectionEnumerable class defined? And I do not really see any point for the ImplicitExternalInterface attribute; the metadata importer can find this out by itself |
Somewhere in C#: public class ElementCollectionEnumerable : IEnumerable<Element>
{
public ElementCollectionEnumerable(ElementCollection elements)
{
// ...
}
//...
} |
What about to add interface
IEnumerable<Element>
toElementCollection
(and maybe other similar collections)?The text was updated successfully, but these errors were encountered: