I have two class of A & B, I want to pass var type variable by a method Separation() that is in another class. I do some casting but I receive InvalidCastException error. Any idea how to fix this, please?
Class A{
var products =from u in XDoc.Descendants("product")
select new
{
Urunkod = u.Element("productId"),
UrunAdi = u.Element("title"),
};
XmlUrun.Separate(products);
}
Class B{
internal static void Separate(object products)
{
var o2 = CaseByExample(products, new
{
Urunkod = "",
UrunAdi = "",
});
}
public static T CaseByExample<T>(this object o, T type)
{
return (T)o;
}
}
dynamictypes???