Browsing 7239 questions and answers with Jon Skeet

Disable Support for Reading (Invalid JSON) Single Quote Strings

Newtonsoft.Json for C# supports reading stuff like {'key':'value'} but thats improper JSON. Is it possible to disable that so it parses and reads more like PHP (Where'as PHP...
Jon Skeet
people
quotationmark

You could write your own JsonReader subclass to perform this, but the JsonTextReader class (which is the most commonly used one, as far as I'm aware) doesn't support this. From the ParseValue method, for example: case '"': case '\'': ... more 1/13/2018 2:23:59 AM

people

Is java.io.FileWriter designed only for a single use?

I'm building a program that constantly writes to the same file, using java.io.FileWriter. During run-time, whenever I need to update the file, I call a method that writes...
Jon Skeet
people
quotationmark

The problem starts on the second .write call, when the FileWriter starts appending to the file, instead of overwriting it. Yes, you've got an open writer. Writing to that writer will just write additional text to the file - just like... more 1/11/2018 3:19:08 PM

people

How to convert Mac to string?

How do I convert the MAC data type to String? I am able to use base64 to encode the SecretKey data type into a String but this doesn't work for MAC. // Generate a secret MAC...
Jon Skeet
people
quotationmark

The Mac class itself isn't the data - it holds the data and updates it on calls to update and doFinal. Currently you're only calling init with the key - you then need to call update (optionally) and then doFinal. When you call doFinal,... more 1/6/2018 10:36:10 AM

people

When would == be overridden in a different way to .equals?

I understand the difference between == and .equals. There are plenty of other questions on here that explain the difference in detail e.g. this one: What is the difference...
Jon Skeet
people
quotationmark

== is bound statically, at compile-time, because operators are always static. You overload operators - you can't override them. Equals(object) is executed polymorphically, because it's overridden. In terms of when you'd want them to be... more 1/5/2018 8:40:42 PM

people

Calculate the number of hours between two dates using NodaTime

I'm trying to use NodaTime to calculate the number of hours between two dates and I get this exception: "Units contains time units: Hours. Parameter name: units" This code works...
Jon Skeet
people
quotationmark

If you've just got dates, the simplest option is to multiply the number of days by 24. Alternatively, create LocalDateTime values instead: Hours = Period.Between(birthday.AtMidnight(), today.AtMidnight(), PeriodUnits.Hours).Hours; Or... more 1/5/2018 8:20:30 PM

people

Access object value from parameter attribute in C#

This is my method public Component SaveComponent([ValidateMetaFields] Component componentToSave) { ... } This is my custom...
Jon Skeet
people
quotationmark

No, attribute instances don't have any notion of the target they're applied to. Note that normally you fetch attributes from a target, so whatever's doing that fetching could potentially supply the information to whatever comes next.... more 1/5/2018 4:44:02 PM

people

Different text detection result from Google Vision API

Get different result for text detection from .Net code and demo app for the same image google vision api result and .net result this is my code: var response =...
Jon Skeet
people
quotationmark

As noted in Emil's answer, you want the DOCUMENT_TEXT_DETECTION feature rather than TEXT_DETECTION. However, you can do it all rather more simply than with the current code. Rather than using Google.Apis.Vision.V1 (which it looks like... more 1/5/2018 4:19:53 PM

people

Find closest end of month for a given date in C#

I want to find the "closest" end-of-month-date to a particular date. For instance, if the date is 4.3.2017, 28.2.2017 is the closest date. For 20.3.2017, 31.3.2017 is the closest...
Jon Skeet
people
quotationmark

Given that there can only be two options, it seems odd to loop here. Assuming you only have dates, rather than needing to worry about the time of day as well, it seems to me that the decision only rests on how many days are in the... more 1/5/2018 12:13:17 PM

people

Paged search returning incorrect amount of results

Tried implementing the page results control to my code to get past the 1000 users limit but it only returns as many users as I've set the page size to (e.g. page size is set to...
Jon Skeet
people
quotationmark

You've used Control.NONCRITICAL. From the documentation: criticality - If true then the server must honor the control and return search results as indicated by pageSize or refuse to perform the search. If false, then the server need... more 1/5/2018 10:27:23 AM

people

Why can't I use 'as' with generic type parameter that is constrained to be an interface?

In the example below (only for demo purpose), if T is not constrained with class, then this conversion: var ret = objectA as T; ..will cause the following compile error: ...
Jon Skeet
people
quotationmark

since I have constrained T to be interface IObject, compiler should know that T must be an interface type and the 'as' operation should be valid. No, T doesn't have to be an interface type. It has to be a type that implements the... more 1/5/2018 7:34:11 AM

people