I have class CheckBoxObject and DeployCheckBoxObject that derived from CheckBoxObject.
i have observable collection of CheckBoxObject and for each element of the collection want to use child properties and functions.
how can i convert the parent collection to child ?
public class CheckboxObject : ViewModelBase
{
public CheckboxObject(object o)
{
Object = o;
}
public object Object;
public string Name => Object.ToString();
}
public class DeployCheckBoxObject : CheckboxObject
{
public DeployCheckBoxObject(object o) : base(o)
{
}
public string status { get; set; }
}
public class Test
{
ObservableCollection<DeployCheckBoxObject> items = new ObservableCollection<DeployCheckBoxObject>();
public void populate(someObject) {
items = someObject.ToObservableCheckboxCollection(); //error
}
}
I also try to call child functions with parent object and get invalid cast error
public class Test
{
ObservableCollection<CheckBoxObject> items = new ObservableCollection<CheckBoxObject>();
public void populate(someObject) {
items = someObject.ToObservableCheckboxCollection();
foreach (CheckboxObject cb in CbVendorItems) {
((DeployCheckBoxObject)cb).Count = 100; //error
}
}
}
public static ObservableCollection<CheckboxObject> ToObservableCheckboxCollection<T>(this IEnumerable<T> enumerableList)
{
var a = new ObservableCollection<CheckboxObject>();
if (enumerableList == null) return a;
foreach (var item in enumerableList)
{
a.Add(new CheckboxObject(item));
}
return a;
}
how can i access to child methods ?