2012-07-13 85 views
0

我尝试写看起来像这样为什么这个通用接口定义是错误的?

public interface IPropertyGroupCollection 
{ 
    IEnumerable<IPropertyGroup> _Propertygroups { get;} 
} 

public interface IPropertyGroup 
{ 
    IEnumerable<IProperty<T, U, V>> _conditions { get; } 
} 

public interface IProperty<T, U, V> 
{ 
    T _p1 { get; } 
    U _p2 { get; } 
    V _p3 { get; } 
} 

public class Property<T, U, V> : IProperty<T, U, V> 
{ 
    //Some Implementation 
} 

我不断获取编译错误的_Conditions的IEnumerable的定义一个接口。

我在做什么错了? 理念是实现类将成为一个通用的属性包集

+0

用'object'替换所有泛型和你设置。 – ja72 2012-07-13 06:16:30

回答

7

那是因为你还没有宣布T,U和V:

public interface IPropertyGroup<T, U, V> 
{ 
    IEnumerable<IProperty<T, U, V>> _conditions { get; } 
} 

你将不得不泛型类型添加到IPropertyGroupCollection为好。

请记住,IProperty<bool,bool,bool>是与IProperty<int,int,int>不同的类型,尽管它们来自同一个通用“模板”。您不能创建IProperty<T, U, V>的集合,您只能创建一个集合IProperty<bool, bool, bool>IProperty<int int, int>

UPDATE:

public interface IPropertyGroupCollection 
{ 
    IEnumerable<IPropertyGroup> _Propertygroups { get;} 
} 

public interface IPropertyGroup 
{ 
    IEnumerable<IProperty> _conditions { get; } 
} 

public interface IProperty 
{ 
} 

public interface IProperty<T, U, V> : IProperty 
{ 
    T _p1 { get; } 
    U _p2 { get; } 
    V _p3 { get; } 
} 

public class Property<T, U, V> : IProperty<T, U, V> 
{ 
    //Some Implementation 
} 
+0

那我该如何使用这个集合作为PropertyBag?如果我将通用类型添加到集合接口? – SudheerKovalam 2012-07-13 06:12:26

+0

那么,你不能像你想要的那样使用泛型。 – 2012-07-13 06:15:25

+0

那么我有没有一种方法可以定义一个类似物业包的界面? – SudheerKovalam 2012-07-13 06:16:23

相关问题