c# - Manipulating existing XDocument (fails) -


I found the following code snippet from my Silverlight application:

  var message = message from XcurrentMsg .Descendants ("Messages") where DateTime.Parse (message.Attribute ("Timestamp"). Value) .ComparateTo (DateTime.Parse (MessageCache.Last_Cached ())) Select new {ip = message. Attribution ("IP"). Value, timestamp = message. Attribution ("Timestamp") Value, text = message. value,}; If (message == empty) new system exemption ("no new message was recorded. The application tried to access non-existing resources!"); (Excelement temporary element = new excelement ("message", message.text.tostring (), new extitid ("IP", message.ip.Testring), new XAttribute ("timestamp", message .imestamp.ToString () ); XcurrentMsg.Element ("Root") element ("Message"). AddMessage (BuildMessage (message.ip, message.timestamp, message.text)); msgCount ++;} MessageCache.CacheXML ( XcurrentMsg; MessageCache.Refresh ();  

XcurrentMsg is XDocument with my server: structure

  & lt; root & gt; & lt; message & Gt; & lt; message ip = "" timestamp = "" & gt; text  & lt; / message For the last time I cache excurrentmoug, I want to get all the "messages" new until I "XElement temporaryElement" "And" XcurrentMsg.Element .... "and use the currentMsg string as the output, it works fine. But I have to save" new message "in my excitement / cache. Now if I do not take this part out, then my application becomes very terrible nuts. I think it writes XcurrentMsg without hindering infinite elements.  

I do not know what the problem is.

Value,

This classic LINQ has been found.

Variable Message a IEnumerable & lt; SomeAnonymousType & gt; . The mistake you are making is assuming that all the countrymakers has been calculated after the assignment of message and created a set of someAnonymousType has gone.

In reality nothing has happened at this point. Only when you begin to compute the set with the fret, then Descendents creates animated and anonymous forms. Even at this point, the entire countrymakers have not been estimated, in fact, only to the first item which is where is the clause condition, then only one projection (result Select) is made in a time as it is through the foreach loops.

Therefore, the messages you added are also included in the calculations and because you end up with other messages in infinite loop or at least one error

if you make sure If the item is being calculated, before connecting the loop, the ToList () has been set before the bench. For the query, this is a list & lt; T & gt; creates.

  var message = (Message from "Message") in XcurrentMsg.Descendants, where DateTime.Parse (message.Attribute ("Timestamp". Value) .compareTo (DateTime.Parse (MessageCache) Select Last_Cached ()) gt 1 Select the new {ip = message.Attribute ("ip") value, timestamp = message attribute ("timestamp". Value, text = message, value,}). ToList ();  

Note In any case, there is no need to test the message for the tap, it will not be empty, it can be an empty count or a list.


Comments