Archived
This forum has been archived. Please start a new discussion on GitHub.
Nice to have: BinarySearch and Sort method on generated collections
DeepDiver
in Comments
hi,
in case sequence<> is generated with the meta tag ["cs:collection"]
it would be nice to have the BinarySearch and Sort methods available.
the generated code will look like:
this is actually pretty straight foreward.
thx & cu tom
PS: adding the contructor with parameter ICollection c would help as well.
in case sequence<> is generated with the meta tag ["cs:collection"]
it would be nice to have the BinarySearch and Sort methods available.
the generated code will look like:
public int BinarySearch(C value)
{
return InnerList.BinarySearch(value);
}
public void Sort()
{
return InnerList.Sort();
}
this is actually pretty straight foreward.
thx & cu tom
PS: adding the contructor with parameter ICollection c would help as well.
0
Comments
-
DeepDiver wrote:in case sequence<> is generated with the meta tag ["cs:collection"]
it would be nice to have the BinarySearch and Sort methods available.
I don't see any problem with this, so I'll add this for the next release.adding the contructor with parameter ICollection c would help as well.
I'm reluctant to add this because it would open up a hole in the type system: if I pass a collection with elements of the wrong type to this constructor, I won't be told at compile time. Instead, the constructor would have to throw an exception at run time if the elements cannot be cast to the expected element type.
Overall, I think it's preferable to write a foreach loop explicitly to populate the collection. At least, that way, the cast is explicit and I can see what is going on in the code.
Cheers,
Michi.0
