C#: specialized template method - Error: Type '…' already defines a member called '…' with the same parameter types

前端 未结 2 1456
-上瘾入骨i
-上瘾入骨i 2021-01-23 13:02

I\'m quite new to C# and currently developing an application using the EntityFramework. I would like to extend the functionality of the database context class, so that I can cal

2条回答
  •  忘了有多久
    2021-01-23 13:39

    I'd recommend (besides of reading about generics and C# in general) to configure the pool with desired types on run time, store them in dictionaries and use the Type as key, i.e. something along the following lines...:

    //...
    
    // configuration, maybe factor out to a dedicated class...
    private readonly IDictionary m_SupportedPools =
        new Dictionary();
    
    // add this queryable, note that type inference works here
    public void AddToPool(IQueryable p_Queryable)
    {
        m_SupportedPools.Add(typeof(T), p_Queryable);
    }
    
    public IQueryable GetPool()
    {
        IQueryable t_Set = null;  
        if (m_SupportedQueries.TryGetValue(typeof(T), out t_Set)) {
            return t_Set as IQueryable;
        } else {
            return null;
        }
    }
    

提交回复
热议问题