代码
using System.Collections.Generic;
using System;
namespace piggyWinFormTemplet
public class SpringGenericTest <T>
{
private List<T> list;
private String name;
public List<T> Contents
{
get { return list; }
set { list = value; }
}
public String TypeName
{
get
{
Type type = typeof(T);
return type.Name;
}
}
public String Name
{
get { return name; }
set { name = value; }
}
public List<T> ApplyFilter(String filterExpression)
{
/// should really apply filter to list ;)
return new List<T>();
}
}
using System;
namespace piggyWinFormTemplet
public class SpringGenericTest <T>
{
private List<T> list;
private String name;
public List<T> Contents
{
get { return list; }
set { list = value; }
}
public String TypeName
{
get
{
Type type = typeof(T);
return type.Name;
}
}
public String Name
{
get { return name; }
set { name = value; }
}
public List<T> ApplyFilter(String filterExpression)
{
/// should really apply filter to list ;)
return new List<T>();
}
}
在配置中是这样配置的:
<object id="springGenericTest" type="piggyWinFormTemplet.SpringGenericTest<int>, piggyWinForm">
<property name="Name" value="My Integer List"/>
</object>
<property name="Name" value="My Integer List"/>
</object>
调用的方法:
代码
//spring.net泛型测试
SpringGenericTest<int> myGenericTest=(SpringGenericTest<int>)SpringTool.Context.GetObject("springGenericTest");
LogTool.Log.Error("spring.net泛型测试结果:" + myGenericTest.TypeName);
SpringGenericTest<int> myGenericTest=(SpringGenericTest<int>)SpringTool.Context.GetObject("springGenericTest");
LogTool.Log.Error("spring.net泛型测试结果:" + myGenericTest.TypeName);
参考资料:4.2.4.泛型类的对象创建