现在的位置: 首页 > 综合 > 正文

SPRING.NET 1.3.2 学习12–为索引器属性赋值

2013年10月27日 ⁄ 综合 ⁄ 共 581字 ⁄ 字号 评论关闭

假设有如下类,有两个索引器,一个是整形,一个是字符串

public class Person
{
    private IList favoriteNames = new ArrayList();
    private IDictionary properties = new Hashtable();
    public Person()
    {
        favoriteNames.Add("p1");
        favoriteNames.Add("p2");
    }
    public string this[int index]
    {
        get { return (string) favoriteNames[index]; }
        set { favoriteNames[index] = value; }
    }
    public string this[string keyName]
    {
        get { return (string) properties[keyName]; }
        set { properties.Add(keyName, value); }
    }
}

下面的对象定义为索引器赋值

<object id="person" type="Test.Objects.Person, Test.Objects">
    <property name="[0]" value="Master Shake"/>
    <property name="['one']" value="uno"/>
</object>

老的1.02版本写法不同,这里不再研究,直接跳过

抱歉!评论已关闭.