Replacements for SystemTypes, GetTypeNode(), GetStaticInitializer(), BaseControlFlowRule
-
Mittwoch, 28. Mai 2008 19:47
Hi all,
I'm trying to convert my FxCop 1.35 custom rules to the 1.36 SDK. I have a couple of questions:
1. What is the effective replacement for "SystemTypes"? I use it in 2 different contexts: with IsAssignableTo() and checking if a Type (now TypeNode) is of a certain type (e.g. Object, Exception, etc.)
2. What is the equivalent to GetTypeNode(), for example:
Code Snippetwhile ( false == currentBaseException.Equals( TypeNode.GetTypeNode( typeof( System.Exception ) ) ) )
{
exceptionInheritanceDepth++;
currentBaseException = currentBaseException.BaseClass;
}
if ( exceptionInheritanceDepth > 0 )
{
Resolution resolution = GetResolution( classToAnalyze.Name.Name,
exceptionInheritanceDepth.ToString( CultureInfo.CurrentCulture ) );
Problems.Add( new Problem( resolution ) );
}
3. How do you get a StaticInitializer from a TypeNode? I used to use:
Code SnippetStaticInitializer staticInitializer = RuleUtilities.GetStaticInitializer( type );
4. What is the replacement for RuleUtilities.GetMethod()? I used to use:
Code SnippetMethod method = RuleUtilities.GetMethod( member );
if ( method != null )
{
if ( RuleUtilities.IsDisposeMethod( member ) || RuleUtilities.IsDisposeBool( method ) )
{
VisitStatements( method.Body.Statements );
if ( ContainsThrowStatement )
{
Problems.Add( new Problem( GetResolution( member.DeclaringType.FullName ) ) );
}
}
}
5. What is the replacement for 'BaseControlFlowRule"? I am trying to inherit from it to develop a rule to warn about Nested 'ForEach' loops.
TIA
Alle Antworten
-
Donnerstag, 29. Mai 2008 00:33Moderator
1. SystemTypes became FrameworkTypes.
2. GetTypeNode was part of the reflection API bridge that we removed in FxCop 1.36, instead of using that call you should now first check to see if the type you want is on FrameworkTypes, and if not then just use the FullName to identify types.
3. We don't have a replacement for it but it was a very simple method that simply looped over all the members in the type and looked for a StaticInitializer, like the following:
Code Snippetforeach
(Member member in type.Members){
StaticInitializer staticInitializer = member as StaticInitializer; if (staticInitializer != null) return cctor;}
return
null;4. Replacement is (member as Method)
5. We also removed our controlflow and dataflow engine in FxCop 1.36 due to the number of bug reports we were recieving about it. I know this was an unpopular move but we will be reintroducing a new and much improved dataflow engine in our next release. This means that there is no more BaseControlFlowRule.
-Todd
-
Donnerstag, 29. Mai 2008 21:23
Hi Todd,
Thank you for your response
The only other question is how can I go about writing a rule to warn about nested 'foreach' loops?
TIA
-
Mittwoch, 4. April 2012 12:38
Hi Todd,
Im also working on few rules of FxCop 1.35
while coding, i couldnt find the equivalent for public static Microsoft.Cci.Method GetMethod(string name, MemberList members, TypeNodeList theParameters) in FxCop 10.0
Any clue as to how to acheive it?
Thanks is advance
-
Mittwoch, 4. April 2012 12:39
Hi ,
Im also working on few rules of FxCop 1.35
while coding, i couldnt find the equivalent for public static Microsoft.Cci.Method GetMethod(string name, MemberList members, TypeNodeList theParameters) in FxCop 10.0
Any clue as to how to acheive it?
Thanks is advance
-
Mittwoch, 4. April 2012 14:20
private static Method GetMethod(string name, IEnumerable<Method> methods, params TypeNode[] parameterTypes) { return methods.FirstOrDefault(m => (m.Name.Name == name) && m.ParameterTypesMatch(parameterTypes)); }- Als Antwort vorgeschlagen voodem Donnerstag, 5. April 2012 05:10
-
Donnerstag, 6. September 2012 09:57
Todd King
Thanks so much it working..!

