How do you provide a default type for generics?

后端 未结 6 1521
醉梦人生
醉梦人生 2020-12-30 18:58

I have a class that currently has several methods that take integer parameters. These integers map to operations that the application can perform. I\'d like to make the clas

6条回答
  •  天涯浪人
    2020-12-30 19:45

    I'm sure you've moved on from this, however I was working through a similar issue and found this solution that uses a context of "using" I was not familiar with. They need to put it in their namespace, so its not completely perfect.

    namespace mygeneric
    {
        public class SecurityContext
        {
    
        }
    }
    
    namespace mytest
    {
        using SecurityContext = mygeneric.SecurityContext;
        using mygeneric;
    
        enum MyContexts
        {
            User,
            Admin
        }
        class MyTest
        {
            SecurityContext myDefaultContext;
            SecurityContext mySpecialContext;
        }
    }
    

提交回复
热议问题