收集时的代码分析警告

时间:2014-06-17 14:52:39

标签: asp.net

我目前正在使用以下内容来存储会话中的对象集合。但是,我得到一个代码分析警告," Collection属性应该只读#34;

public class BankDetails
{
    //private constructor
    public string BankKey { get; set; }
    public string BankAccountHolder { get; set; }
    public string TypeOfAccount { get; set; }
    public string BankAccountNumber { get; set; }
    public string BankName { get; set; }
    public string Balance { get; set; }
    public string Branch { get; set; }
    public string Flag{ get; set; }
    public string NewContactType { get; set; }
    public string OwnerPlatFormID { get; set; }


    public static List<BankDetails> ExistingBankDetails
    {
        get
        {
            return HttpContext.Current.Session["ExistingBankDetails"] as List<BankDetails> ?? new

                List<BankDetails>();

        }
        set 
        { 
            HttpContext.Current.Session["ExistingBankDetails"] = value; 
        }
    }

    public static List<BankDetails> NewBankDetails
    {
        get
        {
            return HttpContext.Current.Session["NewBankDetails"] as List<BankDetails> ?? new

                List<BankDetails>();
        }
        set 
        { 
            HttpContext.Current.Session["NewBankDetails"] = value; 
        }
    }

    public void SetNewBankDetails(List<BankDetails> details)
    {
        details = NewBankDetails;
    }

    public void GetExistingBankDetails(List<BankDetails> existingDetails)
    {
        existingDetails = ExistingBankDetails;
    }
}

}

有关重写此内容的任何提示都要传递代码分析警告吗?

1 个答案:

答案 0 :(得分:0)

改变这个:

public static List<BankDetails> ExistingBankDetails

改为:

public static IEnumerable<BankDetails> ExistingBankDetails

以及所有其他声明。