Browsing 7239 questions and answers with Jon Skeet

Union two ImmutableEnumSets with Guava

I want to union two ImmutableEnumSets from Guava. Here's my try on it: public final class OurColors { public enum Colors { RED, GREEN, BLUE, ...
Jon Skeet
people
quotationmark

Well, Sets.union returns a Sets.SetView<E>, not an ImmutableSet<E>. So you can do this: public final static Sets.SetView<Colors> ourColorSet = Sets.union(myColorSet, yourColorSet); ... which in many cases would... more 11/20/2015 7:16:38 AM

people

How does NodaTime handle future dates if our Government changes the DLS start times?

If I use NodaTime to convert a future date and time to UTC, it uses the Offset of that future date (as known from the global offset database), what happens if suddenly that future...
Jon Skeet
people
quotationmark

Firstly, you would need to update the data in order to know about the change, and obtain an appropriate IDateTimeZoneProvider in your code. Instructions for that are in the user guide but we hope to make it simpler in the future. In... more 11/20/2015 6:54:47 AM

people

Alternative for String.join in Android?

I want to concatenate an ArrayList with commas as separators. I found this answer, stating it's possible to use String.join in Java. When I try to use this however, Android...
Jon Skeet
people
quotationmark

You can use TextUtils.join instead: String result = TextUtils.join(", ", list); (String.join was added in Java 8, which is why you can't use it in Android.) more 11/19/2015 11:46:04 AM

people

VB.NET Query Linq for get all elements node

I'm try to understandin Linq to XML and I've this file XML: <?xml version="1.0" encoding="utf-8"?> <Headers xmlns="http://tempuri.org/GridLayerSchema.xsd"> ...
Jon Skeet
people
quotationmark

You're being confused by the fact that the Value property on XElement will concatenate all the text nodes within an element, including within descendants. That happens to be getting the text value of the Name child element, because that's... more 11/19/2015 10:09:29 AM

people

Rebuild byte array with bigInteger and other method

when I doing the signature encoding I meet a stranger problem: When I want to rebuild a byte array, it always failed with : //digest is the original byte array String...
Jon Skeet
people
quotationmark

Don't use either of these approaches. Either convert into hex directly (not using BigInteger) or use base64. BigInteger will faithfully reproduce numbers, but it's not meant to be a general purpose binary-to-hex converter. In particular,... more 11/19/2015 7:24:30 AM

people

Referring to dynamic members of C# 'dynamic' object

I'm using JSON.NET to deserialize a JSON file to a dynamic object in C#. Inside a method, I would like to pass in a string and refer to that specified attribute in the dynamic...
Jon Skeet
people
quotationmark

I suspect you could use: public void Update(string key, string Value) { File[key] = Value; } That depends on how the dynamic object implements indexing, but if this is a Json.NET JObject or similar, I'd expect that to work. It's... more 11/19/2015 7:08:20 AM

people

C# 5.0 Visual Studio Code Intellisense System.IO

Visual Studio Code tells me the type or namespace 'DirectoryInfo' could not be found. Oddly enough though using System.IO; is indeed included. I have gone as far as adding it to...
Jon Skeet
people
quotationmark

Although DirectoryInfo and FileInfo are in the System.IO namespace, in the DNX world they're in the System.IO.FileSystem assembly. So you need to add a dependency of: "System.IO.FileSystem": "4.0.1-beta-23302" more 11/19/2015 7:06:11 AM

people

How should I take an input, check against a dictionary, and if it matches replace with the definition?

What would be the best way to take an input, check against a dictionary, and if it matches replace with the definition? I'm trying to make a morse code converter, and I've...
Jon Skeet
people
quotationmark

It sounds like you actually want a static variable for the dictionary, as that's not going to change over time. I'd then use a StringBuilder to build up the result, rather than trying to replace text within the string. (Strings are... more 11/19/2015 6:59:58 AM

people

Passing Command Line Argument to Button Text

I have created a simple Application to notify a user of something that is happening. It consists of a single button that when a command line is passed to it, it will display that...
Jon Skeet
people
quotationmark

What I want to accomplish is that if no command line arguments are specified, it will display a default message. That suggests you should check for the length of the arguments with the Length property. So something like: private void... more 11/18/2015 5:58:35 PM

people

Monitoring Task completion

I run several tasks and keep them in a list to check if they are already completed. I discovered that tasks that come from an async method are always shown as RanToCompletion...
Jon Skeet
people
quotationmark

I discovered that tasks that come from an async method are always shown as RanToCompletion although the task itself was still running. Yes, because your void method has completed, and that's all that Task.Run is calling. If instead... more 11/18/2015 4:18:25 PM

people