How can I check if a node is an hashtable or Directory  
Author Message
CaoxiCao





PostPosted: Visual Studio Code Analysis and Code Metrics, How can I check if a node is an hashtable or Directory Top

Hi,

I have a new problem now.
I can get array type by
local.Type.NodeType == NodeType.ArrayType

and ,how can i get Hashtable /Directory's type

then,ArrayList/List

thank you!



Visual Studio Team System34  
 
 
Todd King - MSFT





PostPosted: Visual Studio Code Analysis and Code Metrics, How can I check if a node is an hashtable or Directory Top

To check for these types (or any type for that matter) you are going to need to check the name of the type. So to check if a type is a Dictionary you would do the following:

if (type.GetFullUnmangledNameWithoutTypeParameters().Equals("System.Collections.Generic.Dictionary", StringComparison.Ordinal))
{ ...
}

For Hashtable you do the same thing specifying the fully qualified path to the Hashtable type.

if (type.GetFullUnmangledNameWithoutTypeParameters().Equals("System.Collections.Hashtable", StringComparison.Ordinal))
{ ...
}

etc...

-Todd King



 
 
CaoxiCao





PostPosted: Visual Studio Code Analysis and Code Metrics, How can I check if a node is an hashtable or Directory Top

thank you first.

i just do it as follow:

if (objField.Type.NodeType == NodeType.ArrayType
|| objField.Type == SystemTypes.ArrayList
|| objField.Type == SystemTypes.Hashtable
|| RuleUtilities.IsAssignableToInstanceOf(objField.Type, SystemTypes.GenericList)
|| RuleUtilities.IsAssignableToInstanceOf(objField.Type, SystemTypes.GenericDictionary)
)