Browsing 7239 questions and answers with Jon Skeet

Linq Func delegate can it be added to?

I have a method below. If possible I would like to add some standard filtering in addition that passed through the func variable: .Where(p => p.IsLive) I can of...
Jon Skeet
people
quotationmark

The simplest approach would just to be to chain another call to Where: Product GetProduct(Func<Product, bool> func) { return CompareView.Select() .Where(p => p.IsLive) .Where(func) ... more 3/20/2015 10:26:18 AM

people

Java method object name from argument

I would like to create a method, which will, besides other things, create an object named like the method argument. (I apologize if it is solved somewhere else, didn't find it)...
Jon Skeet
people
quotationmark

That's naming a variable - not an object. Objects don't have names, as such. (You can have a field called name of course, but it's not a general thing.) Variable names are usually only relevant at compile time - so it doesn't really make... more 3/20/2015 8:23:31 AM

people

Integer.parseInt large number and retain sign?

I'm working with hex values and I need to retain the sign of the values. I'm wondering if someone has a creative way to retain the sign of the int without using BigInteger? I...
Jon Skeet
people
quotationmark

If you want to store 32 bits at a time, the obvious solution in my view would be to parse with Long.parseLong instead: isumI = (float)(Long.parseLong(ssumI, 16) / Math.pow(2, bits)); (Do you definitely want to hold these values as float... more 3/20/2015 8:18:59 AM

people

Conversion of byte array hex to decimal

I have a byte array with hexadecimal values, for example: var b = new byte[] {0x27, 0x01, 0x00, 0x00}; I need to convert this to decimal value, but when I used code below, get...
Jon Skeet
people
quotationmark

Basically your understanding of endianness is wrong - your example is in little-endian format already, so you should only reverse it if BitConverter expects a big-endian format. You just need to invert your condition: if... more 3/20/2015 8:16:41 AM

people

Is omnisharp Server similar to IIS expres

Is omnisharp server similar to IIS express? Let's say I have a project folder which has only html files, I start the ominisharp server through atom text editor. It gets started...
Jon Skeet
people
quotationmark

No, the point of the Omnisharp server is not to be a general purpose web server - it's to act as a service. Think of it as an "IDE service" that just happens to exposed itself over HTTP, as that's the easiest way for many clients to talk... more 3/19/2015 10:21:57 PM

people

SimpleDateFormat hour string off by one on certain *dates*. How? Why?

I'm using SimpleDateFormat to turn my GregorianCalendar instances into nice strings. I'm having a weird issue where in certain dates the time string is off by one, but not...
Jon Skeet
people
quotationmark

You're setting the time zone of the calendar you're using, but that's not what you pass into the SimpleDateFormat - you're just using the default system time zone when you format... more 3/19/2015 10:11:48 PM

people

Execution of Any() clause against IQueryable object

I have an object IQueryable that represent some query over my db-model. Now i need to do some validation to that IQeryable and return back the object in that way private...
Jon Skeet
people
quotationmark

It's part of the query - it's within a Where clause. So no, it won't be executed immediately. Having said that, you appear to be closing the context that the query uses, so I suspect that by the time it is used, it'll be broken... more 3/19/2015 4:47:50 PM

people

How to parse dates from other timezones that occur during daylight savings switchover using java.util.Date

I ran into an issue while parsing the following date. 08 März 2015 02:15:20 Code SimpleDateFormat fmt = new SimpleDateFormat("dd MMM yyyy HH:mm:ss",...
Jon Skeet
people
quotationmark

Ideally, you'd use a parser that allowed you to parse date/time values without trying to apply a time zone at all - both java.time.* and Joda Time allow for this, IIRC, and both are much cleaner than java.util.*. However, if you have to... more 3/19/2015 4:46:23 PM

people

Get the Date in yyyy MM dd format c#

I am getting the date in DateTime format. e.g. 3/26/2015 12:00:00 AM I want to to convert it into Date Time (YYYY-MM-DD). My output should be in DateTime : DateTime obj =...
Jon Skeet
people
quotationmark

You appear to be under the impression that a DateTime has a format. It doesn't - no more than an int is neither decimal, nor hex, nor binary - but could be converted to any of those textual representations. It sounds like you should just... more 3/19/2015 2:23:28 PM

people

Detect the length of a lambda expression using Roslyn

I'm wondering how could one possibly detect the length (number of lines) when analyzing code using the Roslyn compiler. At the moment, I'm developing a law which prohibited the...
Jon Skeet
people
quotationmark

It sounds like you know how to get to the relevant syntax nodes (SimpleLambdaExpressionSyntax and ParenthesizedLambdaExpressionSyntax) and just need to know how long they are. I think you just want something like this: var lineSpan =... more 3/19/2015 2:15:17 PM

people