jjzjj

ienumerator

全部标签

c# - 在 JavaScript/TypeScript 中实现 IEnumerable

我正在尝试在JavaScript/TypeScript中实现C#关键字yield(无论哪个):例如,我想实现thecode://usingSystem.Collections;//usingSystem.Diagnostics;publicstaticvoidProcess(){//Displaypowersof2uptotheexponentof8:foreach(intnumberinPower(2,8)){Debug.Write(number.ToString()+"");}//Output:248163264128256}publicstaticIEnumerablePower

c# - 访问 IEnumerable 中的特定属性

我正在尝试查询XML文档并返回存储在METEDATA标记内的COUNT标记中的计数。问题是我在访问程序中使用的属性strCount时遇到了困难。我考虑过遍历IEnumerable,但希望能够以更简洁的方式访问他的值。比如返回countQ.strCount我们的countQ["strCount"]。我知道这些在这种情况下不起作用,但想说明使用我想要值的属性名称的愿望,而不是索引或循环。代码PrivateXDocumentdoc=XDocument.Load(path);publicclassentityCount{publicstringstrCount{get;set;}}public

c# - 将 IEnumerable<int> 作为参数传递给 WCF 服务

我得到的xml看起来像:123和一个wcf服务契约(Contract):[ServiceContract(Namespace="",Name="MyService",SessionMode=SessionMode.NotAllowed)]publicinterfaceIMyService{[OperationContract][WebInvoke(Method="POST",ResponseFormat=WebMessageFormat.Xml,RequestFormat=WebMessageFormat.Xml,BodyStyle=WebMessageBodyStyle.Bare)]

c# - XML 反序列化 IEnumerable 类时出错

我正在尝试将HistoryRoot类序列化和反序列化为这种XML格式:这是HistoryRoot、HistoryList和HistoryItem类:[Serializable]publicclassHistoryRoot{publicHistoryListFiles=newHistoryList{sl=newSortedList(),list=newList(),max=500,c=program.M.qFile},Folders=newHistoryList{sl=newSortedList(),list=newList(),max=100,c=program.M.qFolder},

c# - 序列化在 c# 中实现 IEnumerable 的自定义泛型类型

我有一个通用类型Foo1,它基本上是一个包含一些元数据和通用列表的容器。当我序列化该类型时,它获得名称“Foo1Of”+TypeParameterName。publicclassFoo1{publicstringName{get;set;}=string.Empty;publicListList{get;set;}=newList();}[TestMethod]publicvoidSerializeFoo1(){Foo1foo=newFoo1{Name="Foo1",List={"Bar","Baz"}};XmlSerializers=newXmlSerializer(foo.GetT

c# - 如果 IEnumerable<string> 只返回一个字符串怎么办

我正在对XML文件执行简单的Linq查询IEnumerablevalue=fromiteminmyFile.Descendants("ProductName")select(string)item;通常(如果我有不止一行)我可以使用foreach循环进行迭代:foreach(stringstrinvalue){Console.WriteLine(str);}但是如果我确定我只有一项,并且我的方法签名是:publicstringgetValue(){return?;}我应该返回什么(如果我想删除foreach循环)? 最佳答案 如果你

c# - XmlReader 异常处理 - IEnumerable

我正在读取一个非常大的XML文件,我必须将其作为流读取,如下所示:publicIEnumerableGetStuff(){foreach(vargzipStreaminGetGZips()){using(varreader=XmlReader.Create(gzipStream,newXmlReaderSettings{CheckCharacters=false})){reader.MoveToContent();while(reader.Read())//我在处理过程中遇到无效字符异常:'',hexadecimalvalue0x19,isaninvalidcharacter.Line

xml - 防止 IEnumerable 和 ICollection<T> & 继承类型的 XML 序列化

注意:XMLIgnore不是答案!好的,下面是我关于XMLSerializationandInheritedTypes的问题,我开始将该代码集成到我正在处理的应用程序中,愚蠢地认为一切都会顺利..我遇到了一些实现IEnumerable和ICollection类的问题问题在于,当XMLSerializer开始序列化它们时,它将它们视为外部属性,而不是使用我们希望它使用的属性(即带有我们的AbstractXmlSerializer的属性))它来到这里并倒下(由于类型不匹配),几乎让我们回到原点。您也不能使用XmlIgnore属性修饰这些方法,因此我们不能那样阻止它。我目前的解决方案是删除接

c# - 有没有办法将 IEnumerable 转换为 XElements 的集合?

我正在尝试使用LINQ将XML文件保存到磁盘。我有一类业务对象,包括要转换为XML的字符串集合(List)。是否有一种简单的方式将此列表转换为XML元素列表?例如,我的列表可能是:Listcollection=newList(){"1","2","3"}输出应该是:123目前,我正在使用这种语法:XElementConfiguration=newXElement("Configuration",newXElement("Collection",collection.ToArray()),);但是,这会将集合连接成一个字符串元素。 最佳答案

c# - 使用条件将一次性大型 IEnumerable<T> 分成两半

假设我们有一个Foo类:publicclassFoo{publicDateTimeTimestamp{get;set;}publicdoubleValue{get;set;}//someotherpropertiespublicstaticFooCreateFromXml(Streamstr){Foof=newFoo();//dotheparsingreturnf;}publicstaticIEnumerableGetAllTheFoos(DirectoryInfodir){foreach(FileInfofiindir.EnumerateFiles("foo*.xml",Search