CA1062:ValidateArgumentsOfPublicMethods for params
如下方法在进行Code analysisi会引发warning: CA1062:ValidateArgumentsOfPublicMethods
public static string Format(IFormatProvider provider, string format, params object[] args)
{
if(args.Length==0){....}
else{.....}
......................................
}
一般情况下调用如:Format(provider, format)或者Format(provider, format,arg1[,arg2....]) , args.Length为0, args不是null.
但在Format(provider, format, null)如此调用时,args为null. args.Length 此时会引发异常. 所以在调用args前需要检查以避免warning: CA1062 和潜在的bug.
public static string Format(IFormatProvider provider, string format, params object[] args)
{
if(args == null) {......}
if(args.Length==0){....}
else{.....}
......................................
}
reference:
http://msdn.microsoft.com/en-us/library/ms182182.aspx