The following code produces the issue
Cannot implicitly convert type
'System.Collections.Generic.IEnumberable<DataField<string>>'
to 'DataFields'. An explicit conversion exists (are you missing a cast?).
How do I get around this? What am I doing wrong?
public class DataFields : List<DataField>
{
}
public abstract class DataField
{
public string Name { get; set; }
}
public class DataField<T> : DataField
{
public T Value { get; set; }
}
public static DataFields ConvertXML(XMLDocument data) {
DataFields result = (from d in XDocument.Parse(data.OuterXML).Elements()
select new DataField<string>
{
Name = d.Name.ToString(),
Value = d.Value
}).ToList();
return result;
}
Edited: Moving the information below to another question.
Using LINQ to create a List<T> where T : someClass<U>
In addition I would like to be able to do something like the following in this statement, in order to set the type of the value for each. How can I accomplish this.
select new DataField<[Attribute of element called type]>
{
Name = d.Name.ToString(),
Value = d.Value
}