FxCop – 讓原始碼循規蹈矩的程式警察 文/沈炳宏 ==========程式========= 程式1 using Microsoft.Cci; using Microsoft.FxCop.Sdk; using Microsoft.FxCop.Sdk.Introspection; namespace FxCopRuleDemo { public class LengthRule : BaseIntrospectionRule { public LengthRule() : base("LengthRule", "FxCopRuleDemo.Rules", typeof(LengthRule).Assembly) { } public override ProblemCollection Check(Member m) { Method method = m as Method; if (method == null) return null; if (method.Instructions == null) return null; string name = method.Name.Name; if (name.Length > 10) { Resolution resolution = base.GetResolution(m.Name.Name); Problem problem = new Problem(resolution, m.Name.Name); base.Problems.Add(problem); } return base.Problems; } } } ==========程式========= ==========程式========= 程式2 MyCoolApp true $(AppName).exe ==========程式=========