spring.net泛型的配置以及使用方法

下面是泛型的类定义:
代码
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>();
        }
    }

 

在配置中是这样配置的:

 

  <object id="springGenericTest" type="piggyWinFormTemplet.SpringGenericTest&lt;int>, piggyWinForm">
    
<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);

 

 参考资料:4.2.4.泛型类的对象创建

 

posted @ 2010-09-26 14:45  努力偷懒  阅读(1318)  评论(0编辑  收藏  举报