Browsing 7239 questions and answers with Jon Skeet

How to add a namespace to specific attributes using linq?

We're creating JSON from XML using NewtonSoft's standard .NET functionality. We know that we need to use namespace to define values to be an array as @Json:Array="true" but we...
Jon Skeet
people
quotationmark

You have to do a tree-walk, I believe. If you want to keep all the attributes in place, you'd need to use XElement.ReplaceAttributes. Otherwise, you can just remove the old ones and add new ones. (You can't modify the name of an... more 9/23/2016 11:17:53 AM

people

Using generics from non generic class

I have a problem with generics. I have written a generic class. I derive other classes from this class. Finally I would like to use this derived class in another class but I...
Jon Skeet
people
quotationmark

The problem is that you're trying to use T for two purposes: The source of the status code (you're calling StatusCode on it) The type of the status code (it's the type argument for Information<T>) Now you could just make... more 9/23/2016 10:28:38 AM

people

What is the need of finally block when we can close files and all in catch block

What is the need of finally block when we can close files and all in catch block. Whatever thing we are closing or clearing in finally block can it be done in catch block. Please...
Jon Skeet
people
quotationmark

You normally want to perform the same clean-up action whether an exception is thrown or not. Doing that just with catch blocks is painful - especially if you want to make sure that you only call close() once, even if that throws. You'd end... more 9/23/2016 8:17:02 AM

people

What is the Java equivalent for C# `Interlocked.Exchange(Object, Object) : Object`?

What is the Java equivalent for C# Interlocked.Exchange(Object, Object) : Object? Is there a way in Java to perform the following actions in a single atomic step without lock: 1)...
Jon Skeet
people
quotationmark

There's no operation to do this for an arbitrary variable, as far as I'm aware... but this is what the AtomicReference type is for: private AtomicReference<String> stringReference; ... String oldValue =... more 9/23/2016 6:59:23 AM

people

Why does when sending a file in multipart/form data in java we have to use both a Writer and a OutputStream?

Hi I have seen many sample codes working for sending a file in multipart/form-data in java. But they have used both Writer and an OutputStream. Why can't they use just use one of...
Jon Skeet
people
quotationmark

Basically, the response contains both text and binary data, so using both a Writer and an OutputStream makes perfect sense. The writer just wraps the output stream, and is used to write text. The output stream itself is used to write the... more 9/23/2016 6:38:59 AM

people

Bit Shifting using primitive byte in Java

I want to decode a document encoded using variable byte. The continuation bit is 1 (not 0 as usual). For each byte that I read i check if it is bigger than 128: YES (=128) I...
Jon Skeet
people
quotationmark

It sounds like really you're just wanting to mask the bottom seven bits - which is most simply done using &: if ((b & 0xff) >= 0x80) { n = (n << 7) + (b & 0x7f); } I've changed everything to either use hex or... more 9/23/2016 5:41:50 AM

people

No console output on Winforms project, works on Console project

Just an FYI this question has been re-edited to be more concise. I am working with .NET (whether help is in C# or VB, it doesn't matter). I have a console application, something...
Jon Skeet
people
quotationmark

It turns out that the reason I had a hard time reproducing this was that it wasn't a code problem at all - it was how the code was being run. If you run the program in a debugger, for some reason setting RedirectStandardError to true... more 9/23/2016 5:39:05 AM

people

How to downcast in Unity C# when you need to access specific subclass information on hover?

EDIT 2 This is what is being shown in the unity debugger when I look at the list of Items. It is seeing the baseball bat as an Item type, not WeaponItem type. EDIT 1 This is...
Jon Skeet
people
quotationmark

The problem isn't the cast - it's the XML deserialization. The serializer is only creating Item instances, which is why the cast is failing. You need to change your attributes to tell the serializer which types you want to... more 9/23/2016 5:34:54 AM

people

Override property conflict

I have two complex class: public class BaseRepository<EntityType> where EntityType : class { protected northwindDataContext context = new northwindDataContext(); ...
Jon Skeet
people
quotationmark

It sounds like what you really want is for the BaseService<T>.repo field (it's a field, not a property - and I'd discourage you from using public fields, but that's a different matter) to be the appropriate kind of repository for the... more 9/22/2016 10:11:00 PM

people

mystery on timstamp getTime diff

here is my code: System.out.println(" serverStartTime:" + serverStartTime + " serverRunningTime:" + serverRunningTime); Timestamp sTime = convertTimeFormat(serverStartTime, "MMM...
Jon Skeet
people
quotationmark

You used H in your time format - that's a 24-hour time, so your "start" time is just after midday, more than 10 hours later than your end time. Yes, you've got the "AM" in the format string as well, but I believe that's being ignored due... more 9/22/2016 8:19:31 PM

people