我是OOP的新手。请帮我。我将一些属性标记为“废弃”,并创建了2个集合。为了向后兼容,我需要在这些(过时的)属性中编写哪种设置器(我在测试和产品的旧版本中使用此属性)?

[Obsolete("This is for backward compatibility with existing database records. Use Ids instead")]
[DataMember(Name = "Id")]
public Guid Id
{
    get { return Ids.FirstOrDefault(); }
}

[Obsolete("This is for backward compatibility with existing database records. Use Names instead")]
[DataMember(Name = "name")]
public string Name
{
    get { return Names.FirstOrDefault(); }
}

DataMember(Name = "Ids")]
public GuidCollection Ids { get; set; }

DataMember(Name = "names")]
public StringCollection Names { get; set; }

最佳答案

这个怎么样,

[Obsolete("This is for backward compatibility with existing database records. Use Names instead")]
[DataMember(Name = "name")]
public string Name
{
    get
    {
        return Names.FirstOrDefault();
    }
    set
    {
        Names = new StringCollection();
        Names.Add(value);
    }
}


希望这可以帮助...

关于c# - 为了向后兼容,我需要写哪种 setter ?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31266957/

10-13 09:51