Interface IMethod
Represents a method declared in an application assembly, or declared in a third-party assembly and used by the application code.
public interface IMethod : ICodeContainer, IUser, IMember, IAttributeTarget, ICodeElement, IUsed
- Inherited Members
- Extension Methods
Properties (58)
AccessThis
Gets a value indicating whether this method is explicitly accessign the this reference.
bool AccessThis { get; }
Property Value
Remarks
Returns false for any static method.
ChangesObjectState
Gets a value indicating whether this method assigns an instance field of its parent type
bool ChangesObjectState { get; }
Property Value
Remarks
true can be returned also for a constructor or a class constructor method.
true is returned for a static method or a class constructor that modifies the state of an object passed by reference.
true is returned for an instance method of a type T that modifies an instance of T that is not the one referenced by the this reference.
Methods that ChangesObjectState complexify the program because they break type immutability (see IType.IsImmutable).
ChangesTypeState
Gets a value indicating whether this method assigns a static field of its parent type.
bool ChangesTypeState { get; }
Property Value
Remarks
true can be returned also for a constructor or a class constructor method.
CyclomaticComplexity
Gets a numeric nullable value measuring this method body complexity computed from source code.
ushort? CyclomaticComplexity { get; }
Property Value
- ushort?
null if this method is declared in a third-party assembly.
null if this method is abstract or is a default constructor.
null if the PDB file of this method parent's assembly, hasen't been found.
null if the source code file path referenced from the PDB file cannot be found.
null if the source code of this method is written with a programming language different than C#.
Otherwise returns this method body complexity computed from source code.
More information on this can be found at: Understanding NDepend Analysis Inputs
If source code CC is not available for a non-abstract method, the code metric IMethod.ILCyclomaticComplexity can be used instead.
Remarks
The Cyclomatic Complexity (CC) is a popular procedural software metric equal to the number of decisions that can be taken in a procedure.
Concretely, in C# the CC of a method is 1 + {the number of following expressions found in the body of the method}:
if | while | for | foreach | case | default | continue | goto | && | || | catch | ternary operator ?: | ??
Following expressions are not counted for CC computation:
else | do | switch | try | using | throw | finally | return | object creation | method call | field access
Notice that the CC of a lambda method or an anonymous method is not counted when computing the CC of its outer method.
Recommendations:
Methods where CC is higher than 15 are hard to understand and maintain. Methods where CC is higher than 30 are extremely complex and should be split in smaller methods (except if they are automatically generated by a tool).
FieldsAssigned
Gets a sequence of fields that this method is assigning. If this method is declared in a third-party assembly, gets an empty sequence.
IEnumerable<IField> FieldsAssigned { get; }
Property Value
Remarks
This property getter has a O(this.FieldsUsed.Count) time complexity.
- See Also
FieldsReadButNotAssigned
Gets a sequence of fields that this method is reading but not assigning. If this method is declared in a third-party assembly, gets an empty sequence.
IEnumerable<IField> FieldsReadButNotAssigned { get; }
Property Value
Remarks
This property getter has a O(this.FieldsUsed.Count) time complexity.
- See Also
FieldsUsed
Gets a sequence of fields that this method is using. If this method is declared in a third-party assembly, gets an empty sequence.
IEnumerable<IField> FieldsUsed { get; }
Property Value
Remarks
This property getter has a O(this.FieldsUsed.Count) time complexity.
- See Also
ILCyclomaticComplexity
Gets a numeric nullable value measuring this method body complexity computed from IL code.
ushort? ILCyclomaticComplexity { get; }
Property Value
- ushort?
null if this method is declared in a third-party assembly.
null if this method is abstract or is a default constructor.
Otherwise returns this method body complexity computed from IL code.
Remarks
The IMethod.CyclomaticComplexity (CC) metric is language dependent. Thus, NDepend provides the metric ILCyclomaticComplexity (ILCC) which is language independent because it is computed from IL as:
1 + {the number of different offsets targeted by a jump/branch IL instruction}.
Experience shows that ILCC is a bit more larger than the source code CC. Indeed, a C# if expression yields one IL jump. A C# for loop yields two different offsets targeted by a branch IL instruction while a foreach C# loop yields three.
ILNestingDepth
Gets a numeric nullable value measuring this method body maximum nesting scopes depth.
ushort? ILNestingDepth { get; }
Property Value
- ushort?
null if this method is declared in a third-party assembly.
null if this method is abstract.
Otherwise returns this method body maximum nesting scopes depth.
Remarks
The metric Nesting Depth for a method is the maximum number of encapsulated scopes inside the body of the method. The metric IL Nesting Depth is computed from the IL code. Values computed are similar to what we would expect by computing them from the C# or VB.NET source code.
A testing condition with N conditions, such as if( i > 9 && i < 12), is considered as N scopes because it is possible to decompose such conditions into N atomic conditions.
When a method has a large number of case statements corresponding to a switch, the C# and VB.NET compiler generally produce optimizations while generating the IL. In such case, the IL Nesting Depth corresponding value might be slightly higher to what you would expect.
Recommendations:
Methods with a IL Nesting Depth value higher than 4 are hard to understand and maintain. Methods with a IL Nesting Depth value higher than 8 are extremely complex and should be split in smaller methods (except if they are automatically generated by a tool).
IsAbstract
Gets a value indicating whether this method is an abstract method, or a method declared on an interface.
bool IsAbstract { get; }
Property Value
IsAsync
Gets a value indicating whether this method is asynchronous, declared with the keyword async.
bool IsAsync { get; }
Property Value
Remarks
Both compilation shapes are detected: the classic compiler-generated state machine (a nested type implementing System.Runtime.CompilerServices.IAsyncStateMachine, merged into the method) and, since .NET 11, the runtime async shape where no state machine is emitted and the method carries the MethodImplOptions.Async flag.
IsClassConstructor
Gets a value indicating whether this method is a class constructor.
bool IsClassConstructor { get; }
Property Value
IsConstructor
Gets a value indicating whether this method is an instance constructor.
bool IsConstructor { get; }
Property Value
IsDefaultConstructor
Gets a value indicating whether this method is a default constructor. A default constructor is generated by the compiler on classes that don't have a constructor defined in source code.
bool IsDefaultConstructor { get; }
Property Value
IsEntryPoint
Gets a value indicating whether this method is defined as the entry point.
bool IsEntryPoint { get; }
Property Value
IsEventAdder
Gets a value indicating whether this method is an event adder.
bool IsEventAdder { get; }
Property Value
IsEventRemover
Gets a value indicating whether this method is an event remover.
bool IsEventRemover { get; }
Property Value
IsExplicitInterfaceImpl
Gets a value indicating whether this method is an explicit interface method implementation.
bool IsExplicitInterfaceImpl { get; }
Property Value
IsExtensionMethod
Gets a value indicating whether this method is an extension method.
bool IsExtensionMethod { get; }
Property Value
IsFinal
Gets a value indicating whether this method is declared with the sealed keyword in C#, NotOverridable keyword in VB.NET.
bool IsFinal { get; }
Property Value
IsFinalizer
Gets a value indicating whether this method is a finalizer.
bool IsFinalizer { get; }
Property Value
IsGeneric
Gets a value indicating whether this method is a generic method.
bool IsGeneric { get; }
Property Value
IsIndexerGetter
Gets a value indicating whether this method is an indexer getter.
bool IsIndexerGetter { get; }
Property Value
IsIndexerSetter
Gets a value indicating whether this method is an indexer setter.
bool IsIndexerSetter { get; }
Property Value
IsNewSlot
Gets a value indicating whether this method has a new slot in the type's method table.
bool IsNewSlot { get; }
Property Value
Remarks
Certainly the best resource on the web about this new slot advanced topic is this stackoverflow Q&A
Internally, NDepend relies on this new slot value to compute the override/overriden methods sets in IMethod property getter OverriddensBase, OverridesDerived and OverridesDirectDerived.
IsOperator
Gets a value indicating whether this method is an operator implementation method.
bool IsOperator { get; }
Property Value
IsOverloaded
Gets a value indicating whether this method one of several methods the same SimpleName
bool IsOverloaded { get; }
Property Value
IsPInvokeImpl
Gets a value indicating whether this method is tagged with the System.Runtime.InteropServices.DllImportAttribute attribute.
bool IsPInvokeImpl { get; }
Property Value
IsPropertyGetter
Gets a value indicating whether this method is a property setter.
bool IsPropertyGetter { get; }
Property Value
IsPropertyInit
Gets a value indicating whether this method is a property initializer defined with the C# keyword init.
bool IsPropertyInit { get; }
Property Value
Remarks
Notice that if this value is trueIMethod.IsPropertySetter is also true.
IsPropertySetter
Gets a value indicating whether this method is a property getter.
bool IsPropertySetter { get; }
Property Value
IsTestMethod
Gets a value indicating whether this method is a test method, tagged with a test attribute of a supported test framework, like [Fact], [Theory], [Test], [TestCase] or [TestMethod].
bool IsTestMethod { get; }
Property Value
Remarks
Set-up and tear-down methods are not test methods. This value is not persisted in the analysis result, it is inferred both at analysis time and when loading an analysis result.
- See Also
IsUsingBoxing
Gets a value indicating whether this method IL body is using the box IL instruction.
bool IsUsingBoxing { get; }
Property Value
IsUsingPinning
Gets a value indicating whether this method contains unsafe code that is using pinning.
bool IsUsingPinning { get; }
Property Value
Remarks
VB.NET does not support unsafe code but C# does.
In C#, pinning is generated through the fixed keyword.
IsUsingPointers
Gets a value indicating whether this method contains unsafe code that is using some pointers.
bool IsUsingPointers { get; }
Property Value
Remarks
VB.NET does not support unsafe code but C# does.
IsUsingUnboxing
Gets a value indicating whether this method IL body is using the unbox IL instruction.
bool IsUsingUnboxing { get; }
Property Value
IsVirtual
Gets a value indicating whether this method is declared as virtual.
bool IsVirtual { get; }
Property Value
MembersUsed
Gets a sequence of fields, methods properties and events that this method is using and calling. If this method is declared in a third-party assembly, gets an empty sequence.
IEnumerable<IMember> MembersUsed { get; }
Property Value
Remarks
This property getter has a O(this.MembersUsed.Count) time complexity.
MethodsCalled
Gets a sequence of methods that this method is calling. If this method is declared in a third-party assembly, gets an empty sequence.
IEnumerable<IMethod> MethodsCalled { get; }
Property Value
Remarks
This property getter has a O(this.MethodsCalled.Count) time complexity.
MethodsCallingMe
Gets a sequence of methods that are calling this method.
IEnumerable<IMethod> MethodsCallingMe { get; }
Property Value
Remarks
This property getter has a O(this.MethodsCallingMe.Count) time complexity.
NbMethodsCalled
Gets the number of methods this method is calling. Gets null if this method is declared in a third-party assembly.
uint? NbMethodsCalled { get; }
Property Value
- uint?
NbMethodsCallingMe
Gets the number of methods that call this method.
uint NbMethodsCallingMe { get; }
Property Value
NbOverloads
Gets the number of overloads of this method or this constructor. Gets 1 if this method is not overloaded. Gets null if this method is declared in a third-party assembly.
ushort? NbOverloads { get; }
Property Value
Remarks
Methods where NbOverloads is higher than 6 might be a problem to maintain and provoke higher coupling than necessary.
This might also reveal a potential misused of the C# and VB.NET language that supports object initialization since versions C#v3 and VB9. This language feature helps reducing the number of constructors of a class.
NbParameters
Gets the number of parameters of a method. ref and out parameters are also counted. The this reference passed to instance methods in IL is not counted as a parameter.
ushort NbParameters { get; }
Property Value
Remarks
Methods where NbParameters is higher than 5 might be painful to call and might degrade performance. You should prefer using additional properties/fields to the declaring type to handle numerous states.
Another alternative is to provide a class or structure dedicated to handle arguments passing. For example see the class System.Diagnostics.ProcessStartInfo and the method System.Diagnostics.Process.Start(ProcessStartInfo).
NbVariables
Gets the number of variables declared in the body of this method. Gets null if this methods is abstract or if it is declared in a third-party assembly.
ushort? NbVariables { get; }
Property Value
Remarks
Methods where NbVariables is higher than 8 are hard to understand and maintain.
Methods where NbVariables is higher than 15 are extremely complex and should be split in smaller methods (except if they are automatically generated by a tool).
Overloads
Gets a sequence of methods declared in this method ParentType.MethodsAndConstructors, sharing the same SimpleName with this method. The sequence returned doesn't contain this method.
IEnumerable<IMethod> Overloads { get; }
Property Value
Remarks
If this method doesn't have any overload, gets an empty sequence.
If this method is declared in a third party assembly, gets an empty sequence no matter this method is overloaded or not.
Properties getters IsOverloaded and NbOverloads are faster to invoke than this property getter and might be better suited in some situations.
This property getter has a O(this.ParentType.MethodsAndConstructors.Count) time complexity.
- See Also
OverriddensBase
Gets a sequence of methods declared in this method ParentType.BaseClasses and InterfacesImplemented, overridden by this method. If this method doesn't override any method, gets an empty sequence.
IEnumerable<IMethod> OverriddensBase { get; }
Property Value
Remarks
A sequence of methods overridden by this method is also returned even if this method is declared in a third-party assembly.
This property getter has a O(this.ParentType.DepthOfInheritance.Count) time complexity.
- See Also
OverridesDerived
Gets a sequence of methods declared in this method ParentType.DerivedTypes, overriding this method. If this method is not overridden, gets an empty sequence.
IEnumerable<IMethod> OverridesDerived { get; }
Property Value
Remarks
A sequence of methods overriding this method is also returned even if this method is declared in a third-party assembly.
Methods for which IsNewSlot is true, are not in the returned sequence.
This property getter has a O(this.ParentType.NbChildren.Count) time complexity.
- See Also
OverridesDirectDerived
Gets a sequence of methods declared in this method ParentType.DirectDerivedTypes, overriding this method. If this method is not overridden, gets an empty sequence.
IEnumerable<IMethod> OverridesDirectDerived { get; }
Property Value
Remarks
A sequence of methods overriding this method is also returned even if this method is declared in a third-party assembly.
Methods for which IsNewSlot is true, are not in the returned sequence.
This property getter has a O(this.ParentType.NbChildren.Count) time complexity.
- See Also
ParentEvent
If this method is an event add or remove accessor, returns the parent IEvent object, else returns null.
IEvent ParentEvent { get; }
Property Value
ParentProperty
If this method is a property getter or setter, or an indexer getter or setter, returns the parent IProperty object, else returns null.
IProperty ParentProperty { get; }
Property Value
PercentageBranchCoverage
Gets a numeric nullable value measuring the percentage of branch coverage by tests for this method.
byte? PercentageBranchCoverage { get; }
Property Value
- byte?
Remarks
Branch coverage is a more accurate measure of code coverage than PercentageCoverage because it compensates for method complexity.
Since branch coverage is generated from the underlying opcodes, it often does not map cleanly to source code.
This means that it might be difficult to take branch coverage values and determine how to write tests that will improve coverage.
Availability:
Branch coverage is only available if your coverage data are imported from NCover coverage files and if the metric NbLinesOfCode is available for this method.
Rank
Gets a numeric nullable value assessing this method rank, computed by the original Google Parge Rank algorithm.
float? Rank { get; }
Property Value
- float?
null if this method is declared in a third-party assembly.
Otherwise returns this method Rank numeric value.
Remarks
A homothety of center 0.15 is applied to make it so that the average of all application methods.Rank is 1.
Recommendations:
Methods with high rank should be more carefully tested because bugs in such methods will likely be more catastrophic.
ReadsImmutableObjectState
Gets a value indicating whether this method reads an instance field with a true value for IField.IsImmutable
bool ReadsImmutableObjectState { get; }
Property Value
ReadsImmutableTypeState
Gets a value indicating whether this method reads a static field with a true value for IField.IsImmutable
bool ReadsImmutableTypeState { get; }
Property Value
ReadsMutableObjectState
Gets a value indicating whether this method reads an instance field with a false value for IField.IsImmutable
bool ReadsMutableObjectState { get; }
Property Value
ReadsMutableTypeState
Gets a value indicating whether this method reads a static field with a false value for IField.IsImmutable
bool ReadsMutableTypeState { get; }
Property Value
ReturnType
Gets the return type of this method. Gets null if the return type of this method is not in the scope of assemblies analyzed defined by IProject.CodeToAnalyze.
IType ReturnType { get; }
Property Value
Remarks
This property getter has a constant time complexity.
- See Also
Methods (2)
AssignField(IField)
Gets a value indicating whether this method is assigning the field fieldAssigned.
bool AssignField(IField fieldAssigned)
Parameters
fieldAssignedIFieldThe field object.
Returns
Remarks
This method has a O(fieldAssigned.MethodsAssigningMe.Count) time complexity.
- See Also
CreateA(IType)
Gets a value indicating whether this method is calling a constructor of the type typeCreated.
bool CreateA(IType typeCreated)
Parameters
typeCreatedITypeThe type object.
Returns
Remarks
This method has a O(this.NbMethodsCalled.Count) time complexity.
- See Also