修复 FxCop 规则:枚举应该是强类型的
Posted
技术标签:
【中文标题】修复 FxCop 规则:枚举应该是强类型的【英文标题】:Fix FxCop Rule: Enumerations should be strongly typed 【发布时间】:2012-02-07 07:50:05 【问题描述】:我定义了一个名为 StringResourceCollection 的类。 我的班级声明如下:
namespace EPGObjectModel.IDE
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
public class StringResourceCollection : CollectionBase, IEnumerator
#region Fields
private int index = -1;
#endregion Fields
#region Properties
public object Current
get return this.List[index];
#endregion Properties
#region Indexers
public EPGString this[string index]
get
Reset();
while (this.MoveNext())
if (((EPGString)Current).StringId == index || ((EPGString)Current).StringName.Equals(index))
return (EPGString)Current;
return null;
#endregion Indexers
#region Methods
public int Add(EPGString item)
try
return List.Add(item);
catch(Exception)
throw;
public void Modify(string id, EPGString resourceToModify)
EPGString stringRes = this[id];
stringRes.DeletePermission = resourceToModify.DeletePermission;
stringRes.ModifyPermission = resourceToModify.ModifyPermission;
stringRes.StringInputLanguage = resourceToModify.StringInputLanguage;
stringRes.StringLanguage = resourceToModify.StringLanguage;
stringRes.StringName = resourceToModify.StringName;
stringRes.StringText = resourceToModify.StringText;
public void Modify(EPGString resourceToModify)
EPGString stringRes = this[resourceToModify.StringName];
if (stringRes == null)
return;
stringRes.DeletePermission = resourceToModify.DeletePermission;
stringRes.ModifyPermission = resourceToModify.ModifyPermission;
stringRes.StringInputLanguage = resourceToModify.StringInputLanguage;
stringRes.StringLanguage = resourceToModify.StringLanguage;
stringRes.StringName = resourceToModify.StringName;
stringRes.StringText = resourceToModify.StringText;
public bool MoveNext()
this.index++;
return (this.index < this.List.Count);
public void Remove(EPGString item)
try
List.Remove(item);
catch (ArgumentException)
throw;
public void Reset()
index = -1;
#endregion Methods
当我在我的代码上运行 fxcop 工具时,它显示“枚举应该是强类型”的错误 如何修复 FxCop 规则:枚举应该在我的类中进行强类型化? 这里需要进行哪些更改?
【问题讨论】:
【参考方案1】:既然你正在实现一个字符串集合,你应该实现
IEnumerator<string>
除了 IEnumerator
【讨论】:
以上是关于修复 FxCop 规则:枚举应该是强类型的的主要内容,如果未能解决你的问题,请参考以下文章