Reputation: 35
I have extended a class like so:
public class CormantRadDock : Telerik.Web.UI.RadDock
{
public enum Charts { LineChart, PieChart, BarChart };
public Charts ChartType { get; set; }
public bool LegendEnabled { get; set; }
public string ChartName { get; set; }
public CormantRadDock() : base()
{
}
}
I am now trying to adjust some code elsewhere to accommodate this update.
The old code was this:
List<RadDock> docks = new List<RadDock>(dockLayout.RegisteredDocks);
where RegisteredDocks is of type "System.Collections.ObjectModel.ReadOnlyCollection<RadDock>"
I do not understand why this is not possible:
List<CormantRadDock> docks = new List<CormantRadDock>(dockLayout.RegisteredDocks);
I receive the errors:
The best overloaded method match for 'System.Collections.Generic.List.List(System.Collections.Generic.IEnumerable)' has some invalid arguments.
Argument 1: cannot convert from 'System.Collections.ObjectModel.ReadOnlyCollection' to 'System.Collections.Generic.IEnumerable'
Could someone please explain why this is occurring and a best possible solution?
Upvotes: 0
Views: 137
Reputation: 292695
Some of the RegisteredDocks
might not be CormantRadDock
, so they can't be added to a List<CormantRadDock>
.
If you're only interested in the CormantRadDocks, you can filter by type:
List<CormantRadDock> docks = dockLayout.RegisteredDocks.OfType<CormantRadDock>().ToList();
If you know for sure that RegisteredDocks
will only contain CormantRadDocks, you can cast each item:
List<CormantRadDock> docks = dockLayout.RegisteredDocks.Cast<CormantRadDock>().ToList();
Upvotes: 3