Unless I'm missing something, DataList & DataToken implementation does not support implicit casts. It does not support the use of
.Cast<T>
calls either.
Let's say you have a DataList full of string tokens:
DataList a = new DataList() { "First", "Second", "Third" };
What's normally the shortest way to concatenate it into "First, Second, Third"? Something like this:
String.Join(", ", a.Cast<string>().ToArray());
But we can't do that, since there is no exposed definition of .Cast<T> for DataList or DataToken (
DataList.ToArray().Cast<string>().ToArray()
).
Well,
Array.ConvertAll()
is exposed, but you don't support lambdas. This is better, but now an effective one-liner is split into multiple segments all over the code.
So the only valid way to do that
Join
is to manually iterate:
string[] items = new string[a.DataList.Count];
for (int i = 0; i < items.Length; i++)
{
items[i] = a.ToArray()[i].ToString();
}
string output = String.Join(", ", items);
Pretty much the only unsafe cast sources are of types
DataDictionary
,
DataList
,
Reference
, and
Error
(kind of). You already return type name in those cases, so just support cast operators and implicit casting.