2016-11-25 72 views
1

我已经创建了一本字典。但是生成过程中它给我的错误:如何解决字典设置问题

Change 'INotificationMessage.AlertMessageList ' to be read-only by removing the property setter

public interface INotificationMessage 
    { 
     /// <summary> 
     /// Gets or sets the notification message list. 
     /// </summary> 
     /// <value> 
     /// The notification message list. 
     /// </value> 
     Dictionary<string, string> AlertMessageList { get; set; } 
    } 

可以请ayone帮助我解决这个问题。

回答

2

通常,您不应该为集合设置公共集合,因为这允许替换列表。只需使用:

Dictionary<string, string> AlertMessageList { get; } 

要解决它,你可以为组收集或使用添加方法:

Dictionary<string, string> AlertMessageList { get; private set; } 

Collection properties should be read only

+0

如果您需要设置强制implemation用于获取列表,只需在接口中添加一个方法void SetAlertMessageList(Dictionary dict) Dictionary SetAlertMessageList() – user1519979

+0

@Raj Hello。如果有帮助请接受答案。如果不是,那么描述是什么问题。在此先感谢您 – Marusyk

+0

@MegaTron能否请您建议如何在界面中添加一个方法来设置属性。 – Raj