MethodNode ReadMethod(IMethod method) { MethodNode m; TypeNode t = ReadType(method.DeclaringTypeDefinition); if (!methodMappings.ContainsKey(method)) { m = new MethodNode(method, t, ReadType(method.ReturnType.GetDefinition())); t.methods.Add(m); methodMappings.Add(method, m); cecilMappings.Add(loader.GetCecilObject((IUnresolvedMethod)method.UnresolvedMember), method); } else { m = methodMappings[method]; } return m; }
public Relationship GetRelationship(INode node) { Relationship relationship = new Relationship(); if (node == this) { relationship.Relationships.Add(RelationshipType.Same); return(relationship); } if (node is NamespaceNode) { NamespaceNode ns = (NamespaceNode)node; foreach (var type in GetAllTypes()) { if (type != null && type.Namespace == ns) { relationship.AddRelationship(RelationshipType.UseThis); } } } if (node is TypeNode) { TypeNode type = (TypeNode)node; foreach (var usedType in GetAllTypes()) { if (type == usedType) { relationship.AddRelationship(RelationshipType.UseThis); } } } if (node is MethodNode) { MethodNode method = (MethodNode)node; foreach (var usedMethod in GetAllMethods()) { if (method == usedMethod) { relationship.AddRelationship(RelationshipType.UseThis); } } } if (node is FieldNode) { FieldNode field = (FieldNode)node; foreach (var usedField in GetAllFields()) { if (field == usedField) { relationship.AddRelationship(RelationshipType.UseThis); } } } return(relationship); }
void ReadInstructions(MethodNode m, IMethod method, MethodDefinition cecilObject) { if (!cecilObject.HasBody) return; foreach (var instruction in cecilObject.Body.Instructions) { m.instructions.Add(new Instruction { DeclaringMethod = m, Operand = (instruction.Operand ?? "").ToString() }); // IL cyclomatic complexity if (instruction.OpCode.FlowControl == FlowControl.Cond_Branch) m.CyclomaticComplexity++; var operand = ReadOperand(instruction); if (operand is MethodDefinition && ((MethodDefinition)operand).DeclaringType.Module.Assembly == assemblyDefinition) { var md = (MethodDefinition)operand; if (md.DeclaringType.Name == "" || md.DeclaringType.Name.StartsWith("<")) { // TODO : Handle generated members } else { var opMethod = (IMethod)cecilMappings[md]; var methodNode = methodMappings[opMethod]; m.typeUses.Add(methodNode.DeclaringType); m.methodUses.Add(methodNode); } } if (operand is FieldDefinition && ((FieldDefinition)operand).DeclaringType.Module.Assembly == assemblyDefinition) { var fd = (FieldDefinition)operand; if (fd.DeclaringType.Name == "" || fd.DeclaringType.Name.StartsWith("<")) { // TODO : Handle generated members } else { var field = (IField)cecilMappings[fd]; var fieldNode = fieldMappings[field]; m.fieldUses.Add(fieldNode); } } } }
public static BitmapSource GetIcon(MethodNode method) { if (method.Method.IsPrivate) return PrivateMethod; if (method.Method.IsProtected) return ProtectedMethod; // if (method.IsGetter || method.IsSetter) // { // if (method.IsPublic) // return PropertyMethod; // if (method.IsPrivate) // return PrivatePropertyMethod; // if (method.IsProtected) // return ProtectedPropertyMethod; // } return MethodNode; }