我一直在用 StyleCop 清理我的项目文件,但我有以下无法解决的问题
PasswordPolicyCollection.cs (13): CA2214 : Microsoft.Usage : 'PasswordPolicyCollection.PasswordPolicyCollection()' 包含一个调用链,该调用链导致对类定义的虚拟方法的调用。查看以下调用堆栈以了解意外后果: PasswordPolicyCollection..ctor() ConfigurationElementCollection.CreateNewElement():ConfigurationElement PasswordPolicyCollection.Add(PasswordPolicy):Void ConfigurationElementCollection.BaseAdd(ConfigurationElement):Void
这是代码:
using System.Configuration;
public class PasswordPolicyCollection : ConfigurationElementCollection
{
public PasswordPolicyCollection()
{
var passwordPolicy = (PasswordPolicy)this.CreateNewElement();
this.Add(passwordPolicy);
}
public override ConfigurationElementCollectionType CollectionType
{
get
{
return ConfigurationElementCollectionType.AddRemoveClearMap;
}
}
public new PasswordPolicy this[string name]
{
get
{
return (PasswordPolicy)BaseGet(name);
}
}
public PasswordPolicy this[int index]
{
get
{
return (PasswordPolicy)BaseGet(index);
}
set
{
if (BaseGet(index) != null)
{
BaseRemoveAt(index);
}
BaseAdd(index, value);
}
}
public void Add(PasswordPolicy passwordPolicy)
{
this.BaseAdd(passwordPolicy);
}
public int Indexof(PasswordPolicy policy)
{
return BaseIndexOf(policy);
}
public void Remove(PasswordPolicy url)
{
if (BaseIndexOf(url) >= 0)
BaseRemove(url.Name);
}
public void RemoveAt(int index)
{
BaseRemoveAt(index);
}
public void Remove(string name)
{
BaseRemove(name);
}
public void Clear()
{
BaseClear();
}
protected override void BaseAdd(ConfigurationElement policy)
{
BaseAdd(policy, false);
}
protected override sealed ConfigurationElement CreateNewElement()
{
return new PasswordPolicy();
}
protected override object GetElementKey(ConfigurationElement policy)
{
return ((PasswordPolicy)policy).Name;
}
}
有任何想法吗?