So, I wrote a quick code to quickly convert between business objects and view models. Not to pimp my own blog, but you can find the details here if you are interested or need to know.
One problem that I am facing is that I have my own collection type, ProductCollection, and I need to include this in the [] line in my model. Obviously, since there is no implicit cast by default, I get an exception in the contract converter.
So, I thought I would write the following small code, and this should solve the problem:
public static implicit operator string[](ProductCollection collection) {
var list = new List<string>();
foreach (var product in collection)
{
if (product.Id == null)
{
list.Add(null);
}
else
{
list.Add(product.Id.ToString());
}
}
return list.ToArray();
}
- . , - ? , -, ? !