使用反序列化 XML 文件中的多字段列表 <> 来填充第二个单字段列表 (Xamarin)
Use multi-field List<> from Deserialized XML file to populate second single field list (Xamarin)
这一定很简单...在 T-SQL 中需要我一秒钟。
在我得到重复的标志之前...我一直在尝试发布一些类似的问题并且我已经在这个问题上研究了几个小时,修改涉及 JTokens 的各种回复,更改为 IEnumerable,反序列化一个字段仅举几例。我不断收到以下错误:
xamarin cannot implicitly convert type
'System.Collections.Generic.List to 'System.Colletions.List
我已经将一个 xml 文件反序列化为一个列表,如下所示:
var assembly = IntrospectionExtensions.GetTypeInfo(typeof(LoadResourceText)).Assembly;
Stream stream = assembly.GetManifestResourceStream("papapp.WineCatInfo.xml");
List<WineCategoryInfo> winecategoryinfos;
using (var reader = new StreamReader(stream))
{
var serializer = new XmlSerializer(typeof(List<WineCategoryInfo>));
winecategoryinfos = (List<WineCategoryInfo>)serializer.Deserialize(reader);
}
#endregion
return winecategoryinfos;
它填充的列表定义如下:
public class WineCategoryInfo
{
public string WineTypeNo { get; set; }
public string WineFamily { get; set; }
public string MainStyle { get; set; }
public string StyleType { get; set; }
public string LengthCharacteristic { get; set; }
public string RegionCommonAppelation { get; set; }
}
我想查询反序列化日期,将上述列表中一个特定字段的所有值放入第二个列表,定义如下:
public class WineFamilies
{
public string WineFamily { get; set; }
}
有人可以向我解释如何实现吗?
非常感谢。
使用LINQ
using System.Linq;
var family = (from x in winecategoryinfos select x.WineFamily).ToList<string>();
或消除重复项
var family = (from x in winecategoryinfos select x.WineFamily).Distinct().ToList<string>();
如果您想使用 WineFamilies class 而不是字符串,请尝试
var family = (from x in winecategoryinfos select new WineFamilies() { WineFamily = x.WineFamily }).ToList();
这一定很简单...在 T-SQL 中需要我一秒钟。
在我得到重复的标志之前...我一直在尝试发布一些类似的问题并且我已经在这个问题上研究了几个小时,修改涉及 JTokens 的各种回复,更改为 IEnumerable,反序列化一个字段仅举几例。我不断收到以下错误:
xamarin cannot implicitly convert type 'System.Collections.Generic.List to 'System.Colletions.List
我已经将一个 xml 文件反序列化为一个列表,如下所示:
var assembly = IntrospectionExtensions.GetTypeInfo(typeof(LoadResourceText)).Assembly;
Stream stream = assembly.GetManifestResourceStream("papapp.WineCatInfo.xml");
List<WineCategoryInfo> winecategoryinfos;
using (var reader = new StreamReader(stream))
{
var serializer = new XmlSerializer(typeof(List<WineCategoryInfo>));
winecategoryinfos = (List<WineCategoryInfo>)serializer.Deserialize(reader);
}
#endregion
return winecategoryinfos;
它填充的列表定义如下:
public class WineCategoryInfo
{
public string WineTypeNo { get; set; }
public string WineFamily { get; set; }
public string MainStyle { get; set; }
public string StyleType { get; set; }
public string LengthCharacteristic { get; set; }
public string RegionCommonAppelation { get; set; }
}
我想查询反序列化日期,将上述列表中一个特定字段的所有值放入第二个列表,定义如下:
public class WineFamilies
{
public string WineFamily { get; set; }
}
有人可以向我解释如何实现吗?
非常感谢。
使用LINQ
using System.Linq;
var family = (from x in winecategoryinfos select x.WineFamily).ToList<string>();
或消除重复项
var family = (from x in winecategoryinfos select x.WineFamily).Distinct().ToList<string>();
如果您想使用 WineFamilies class 而不是字符串,请尝试
var family = (from x in winecategoryinfos select new WineFamilies() { WineFamily = x.WineFamily }).ToList();