财产安全集

时间:2012-05-19 13:45:14

标签: c# .net properties private-members

我只是在这里画一个空白。有一个我想要的类只读取类的属性,但有一个可以更新属性的管理类型函数。

public class Group : Object, INotifyPropertyChanged
{   // this is read only admin is via UserGroupAdmin
    public event PropertyChangedEventHandler PropertyChanged;
    private void NotifyPropertyChanged(String info)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(info));
        }
    } 

    public Int16 ID { get; private set; }
    public string Name { get; private set; }
    public override bool Equals(Object obj)
        {
            //Check for null and compare run-time types.
            if (obj == null || !(obj is Group)) return false;
            Group item = (Group)obj;
            return (ID == item.ID);
        }

    public override int GetHashCode() { return (int)ID; }
    public Group(Int16 id, string name)
    { ID = id; Name = name;  }
 }

我想要的是管理类型功能

public group ReviseGroupName (Group group, string revisedName)
{
   // write revised name to SQL
   // revise group.name
   // return revised group
}

我知道的SQL部分。我考虑的只是创建一个具有相同ID和哈希码的新组并返回它。

1 个答案:

答案 0 :(得分:0)

如果AdminGroup中的嵌套类,您可以在函数中设置私有属性:

public class Group
{
    public string Name { get; private set; }

    public class Admin
    {
        public Group ReviseGroupName (Group group, string revisedName)
        {
            group.Name = revisedName;
            return group;
        }
    }
}