Browsing 7239 questions and answers with Jon Skeet

Multiple quotes cause PipedOutputStream/OutputStreamWriter to fail

I stumbled over a very strange behavior with the PipedOutputStream when I was trying to copy an OutputStream to an InputStream. See also How to write an nt:file...
Jon Skeet
people
quotationmark

This has nothing to do with the quotes - and everything to do with how much data you're writing. To demonstrate this, you can get rid of the writer and the loop entirely, and just use: pout.write(new byte[1024]); Or keep your existing... more 11/27/2014 1:23:33 PM

people

removing switch calling function based on object type using polymorphism

I have a piece of code (shown below) where i want to be able to call a function depending on the object type that is passed in, i currently have a switch statement which manages...
Jon Skeet
people
quotationmark

To use polymorphism, you'd introduce an abstract method in whatever the base class is for all your entities: public abstract class EntityBase { public abstract void GiveMeABetterName(); } (We don't know what you're trying to do,... more 11/27/2014 11:59:43 AM

people

Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type

I am working with .NET4.5 and VS2013, I have this query that gets dynamic result from db. dynamic topAgents = this._dataContext.Sql( "select t.create_user_id as \"User\",...
Jon Skeet
people
quotationmark

The problem is that topAgents is dynamic - so your ToList() call is dynamic, and so is Select. That has issues that: you can't use lambda expressions for dynamic calls like this; dynamic calls don't find extension methods... more 11/27/2014 11:30:33 AM

people

What is the Groovy truth of an empty closure?

I am trying to predict the behavior of this code in Groovy userList.find { } .find documentation When the find method is invoked and passed a closure it returns the first...
Jon Skeet
people
quotationmark

From the Groovy Closures Formal Definition (Alternative Source): Closures always have a return value. The value may be specified via one or more explicit return statement in the closure body, or as the value of the last executed... more 11/27/2014 10:41:25 AM

people

Read multiple lines with StreamReader with StreamReader.Peek

Let's say I have the following file format (Key value pairs): Objec1tKey: Object1Value Object2Key: Object2Value Object3Key: Object3Value Object4Key:...
Jon Skeet
people
quotationmark

I would strongly recommend that you separate the IO from the line handling entirely. Instead of making your processing code use a StreamReader, pass it either an IList<string> or an IEnumerable<string>... if you use... more 11/27/2014 10:25:27 AM

people

Check HMAC SHA1 without key in C#

I am generating HMAC-SHA1 without key in C# and it returns every time different hash for same value, how can I match hashes, My code is https://dotnetfiddle.net/3a3tiP is it...
Jon Skeet
people
quotationmark

From the documentation of HMACSHA1: A Hash-based Message Authentication Code (HMAC) can be used to determine whether a message sent over an insecure channel has been tampered with, provided that the sender and receiver share a secret... more 11/27/2014 7:30:21 AM

people

Is there any automatic way to sync values of objects

IDE: VS 2010, c# .net winforms Hi, I am having 3 objects obj1 obj2 and obj3, and obj1 some values are initiated and obj2 some values are initiated and I want in obj3 as final...
Jon Skeet
people
quotationmark

No, there's no built in support for merging... and unless the types of value1 and value2 are int?, you may not be able to tell the difference between "not initialized" and "initialized to 0". (If they're properties, you could give them... more 11/27/2014 6:59:32 AM

people

Get correct string position C#

I have a string: string str = "Wishing you {all a great} day {ahead}. \n Thanks a lot \n } \n for {your} help!}" I read the string line by line. So at present I have 4 lines...
Jon Skeet
people
quotationmark

Within a single string, it sounds like you should iterate over the characters in the string and keep a count of how many opening and how many closing braces you've seen. Something like this: int open = 0; for (int i = 0; i <... more 11/27/2014 6:56:28 AM

people

How to fix inherited member hiding warning when dealing with virtual properties

I have the following base class: public class OAuthRefreshToken { //Other properties.. public int UserId { get; set; } public virtual OAuthUser User { get; set;...
Jon Skeet
people
quotationmark

The warning should tell you what you can do - something like this (emphasis mine): 'OAuthRefreshToken.User' hides inherited member 'OAuthRefreshToken.User'. To make the current member override that implementation, add the override... more 11/26/2014 5:47:09 PM

people

How to shift all the whole numbers in a double to the right of the point

How to shift all the whole numbers in a double to the right of the point ? Example i have 5342, i want the function to return 0.5342. I do not know the number of digits in the...
Jon Skeet
people
quotationmark

This sounds like a pretty bizarre task, to be honest, but you could use: while (Math.Abs(value) >= 1) { value = value / 10; } That will go into an infinite loop if the input is infinity though - and you may well lose information... more 11/26/2014 5:34:09 PM

people