Browsing 15485 questions and answers with Jon Skeet

Second iteration of XDocument.Save() throwing "Access to Path Denied"

I'm writing a small class to manage configuration XML for an in-house application. The following code is called each time a new list of t is loaded, and attempts to serialize...
Jon Skeet
people
quotationmark

I'm surprised it's working on the first iteration - because you're not checking a useful file. Instead of calling Path.Combine with multiple arguments, you're concatenating TaskData.xml with the current directory. You want: if... more 2/20/2017 6:09:47 PM

people

How do I deserialise different NodaTime LocalDate patterns within the same JSON object

I'm trying to use NodaTime to interpret dates retrieved from a third-party API. The dates come in an annoying array of formats in the same response, one that I'm particularly...
Jon Skeet
people
quotationmark

This does indeed seem to be a use case we hadn't considered. For "normal" usage, sealing NodaPatternConverter feels like the right approach - but when a JsonConverter has to be specified by type rather than instantiated, the sealing is... more 2/20/2017 6:02:50 PM

people

Why addLast() not working properly

I created a DeQueue as follws Deque<Integer> deque = new ArrayDeque<Integer>(8); // use add() method to add elements in the...
Jon Skeet
people
quotationmark

addLast doesn't somehow maintain a notion of "this should be last" forever - it just adds to the end of the current dequeue. It's equivalent to add, as documented. So if we look at the values at each step, we have: deque.add(20); //... more 2/19/2017 9:37:59 AM

people

JAVA right bit shift return wrond value

I try to use right binary shifting in JAVA. Please look in code below: int val = 180000; val >>>= 8; // val == 703, ok val >>>= 8; // val == 2 , lok val...
Jon Skeet
people
quotationmark

Why last operation in second example compute wrong value? The value is computed according to the specification. It's your expectations that are wrong. From JLS 15.19: If the promoted type of the left-hand operand is int, then only... more 2/19/2017 9:19:41 AM

people

Getting the actual this reference to the task state machine

I'm playing with the idea of tampering with the state of a tasks internal state machine, but i'm having trouble finding a way to actually access the state machine reference within...
Jon Skeet
people
quotationmark

It's nasty, and it's not guaranteed to work (it depends on implementation details) - but this works for me... it basically provokes the state machine to pass a continuation to an awaiter. We can then get the state machine out of the... more 2/17/2017 2:57:44 PM

people

What is the "Name=value" in [MyAttribute(Name=value)]

I don't know what phrasing to use to google this. Consider this attribute: [MyAttribute(MyOption=true,OtherOption=false)] What is the Name=value part? And how can I implement...
Jon Skeet
people
quotationmark

It's specifying a property when creating an instance of the attribute. Attributes can have constructor parameters and properties - this one is setting a property. Note that you can mix positional constructor arguments, named constructor... more 2/17/2017 12:06:30 PM

people

C# default parameter by name is this possible?

May be this is a stupid question but: I wonder if there is something like default parameter but not by value - but by name. Example: I must use a parameter "IWebDriver driver"...
Jon Skeet
people
quotationmark

No, there's no way of doing that. Default parameters have to have constant values - they can't depend on a value taken from a local variable. It sounds like you should probably construct an instance which stores a driver reference in a... more 2/17/2017 11:58:08 AM

people

How to copy image in java using bufferedreader/writer

File file = new File("download.png"); File newfile = new File("D:\\Java.png"); BufferedReader br=null; BufferedWriter bw=null; try { FileReader fr =...
Jon Skeet
people
quotationmark

Whats wrong with this code. You're using text-based classes for binary data. Is it possible with BufferedReader and Writer Class? Not while you're dealing with binary data, no. I know how to to make copy of image using... more 2/16/2017 3:57:55 PM

people

why does i.Parent.ReplaceWith(i) not throw an exception?

In these statements (running with MoreLinq): var xml = @" <div> <p> <h2>hey</h2> </p> <pre /> <h2 class=""cool"" /> <p> ...
Jon Skeet
people
quotationmark

You don't need MoreLINQ to demonstrate this at all - and you can simplify the sample code, too: using System; using System.Linq; using System.Xml.Linq; class Program { static void Main() { var element = new XElement( ... more 2/16/2017 9:15:54 AM

people

C# convert System.Func<Tderived, bool> to System/Func<Tbase, bool>

I've googled but couldn't find satisfactory answers. I'm basically trying to get this code to work: public List<WordEntry> WordDataBase = new...
Jon Skeet
people
quotationmark

Basically, you just need to cast - the language rules don't allow the compiler to take the if statement into account when it thinks about the types involved. Note that you also need to call ToList<Entry>(), specifying the type... more 2/15/2017 3:18:47 PM

people