... Home Contact

Krzysztof Koźmic's blog

You're doing it wrong.


Show appreciation: My Amazon.com Wish List

Me@Twitter

    Currently reading

    Article Categories

    Archives

    Post Categories

    MyPersonal

    Syndication:

    Generics

    There are 4 entries for the tag Generics

    On generics limitations

    I wish generics in C# were more powerful. Why this is not legal?public class ServiceHost<TService> : ServiceHost where TService : class { public ServiceEndpoint AddServiceEndpoint<TServiceInterface>(Binding binding, string address) where TService : TServiceInterface { return AddServiceEndpoint(typeof(TServiceInterface), binding, address); } } Technorati Tags: Generics

    So is it a class or what?

    C# doesn't stop to surprise me. While looking at Moq source code I noticed something strange: Generic constraint says class but yet somehow interfaces account for class? Technorati Tags: Moq, Generics

    Implicit casting of generic classes

    Can anyone tell me what am I missing here? Here's a simple class public class Mock<TType>{ private readonly TType _actual;  public Mock(TType actual) { _actual = actual; } public TType Actual { get { return _actual; } } public static implicit operator TType(Mock<TType> item) { return item.Actual; }} That's a...

    Hello World: the 'new' keyword

    Everyone knows what the new keyword is for in C# - you use it to call constructor of an object, right? What can be simpler? Actually, that's true, but not the whole truth. That's the most common way to use it. However, new is one of contextual keywords, which means, it can have different meaning, depending on the context where it's being used. The new keyword can be used in three scenarios: the one presented above, everyone immediately thinks of - creating objects. as modifier, to hide members of a base class. as generic constraint. Creating objects is pretty...