Browsing 7239 questions and answers with Jon Skeet
userList.forEach is expecting a Consumer<? extends User> - in other words, a method which accept a User reference and do something with it. That could be: A static method accepting a User parameter, in which case the parameter... more 8/20/2014 4:18:15 PM
It's easy to prove that it reads past the end element - you just need to create an XML file which contains data after the end element, making it invalid: <root> <child /> </root> More stuff If you load that, you'll... more 8/20/2014 1:10:48 PM
Use the overload of the GZipStream constructor which accepts a bool parameter to say whether to leave the underlying stream open afterwards: using (var zip = new GZipStream(networkStream, CompressionMode.Compress, true)) { zip.Write... more 8/20/2014 11:35:40 AM
It sounds like you're really just looking for the element name, possibly its LocalName: var root = XElement.Load("project_data.xml"); foreach (var element in root.Elements()) { Console.WriteLine("{0}: {1}", ... more 8/20/2014 10:38:28 AM
Perhaps use composition instead of inheritance - have an extra property of what's currently your base class for "extended properties"... then just populate that property lazily: public class FileInfo // Or whatever { public string... more 8/20/2014 8:52:04 AM
You can get it to work with casting, but it's ugly: if (typeof(T) == typeof(string)) { copyAction((T)(object) GetStringValue(field)); } (etc) This sort of thing always ends up being fairly ugly, to be honest. One option would be to... more 8/20/2014 8:31:22 AM
Your GenericComparer isn't generic - and you're implementing the non-generic IComparer interface. So there isn't any type T... you haven't declared a type parameter T and there's no named type called T. You probably want: public class... more 8/20/2014 7:44:22 AM
I suspect all you're looking for it: PropertyInfo[] queryInfo = typeof(T).GetProperties(); In other words, get the properties from the generic type argument rather than for a particular instance of that type. more 8/20/2014 7:33:42 AM
I'd just create a new class or struct to encapsulate the two values. You could use Tuple<,> instead, but personally I'd create a new type so that you can use friendlier property names. You might want to include all the data from the... more 8/20/2014 6:54:06 AM
The argument you use for an out parameter has to exactly match the declared parameter type. As HandleException has a third parameter out Exception exceptionToThrow, that won't work at the moment. Given that you don't need the exception to... more 8/19/2014 8:00:13 PM