You searched for new guid. We found 22 results in 0.011 seconds.

Convert generic parameter of type T to List<TP> when T is IEnumerable<TP>

My application has a method that caches a value. I need a second method that check if the generic parameter of type T implements IEnumerable and not implements IList. If the...
Jon Skeet
people
quotationmark

Dynamic typing and overloading could help here, if you don't mind using dynamic: object ConvertToListIfNecessary(dynamic input) { return MaybeToList(input); } private IList<T> MaybeToList<T>(IEnumerable<T> input) { ... more

people

Increment value from expression

I want to write a closure and increment it's value but i'm not able to do it. Here is my code int i = 0; Expression<Func<bool>> closurExpression = ()...
Jon Skeet
people
quotationmark

Well, you can do sidestep the rules using Interlocked.Increment: int i = 0; Expression<Func<bool>> expression = () => Interlocked.Increment(ref i) != 0; ... but I would be very cautious about doing so. I wouldn't expect... more

people