Table of Contents

Interface ICodeElement

Namespace
NDepend.CodeModel
Assembly
NDepend.API.dll

Represents a code element. This interface is implemented by IMethod, IField, IType, INamespace and IAssembly.

public interface ICodeElement : IUsed
Inherited Members
Extension Methods

Properties (45)

AsAssembly

Gets this code element casted to IAssembly if it is an assembly, else gets null.

IAssembly AsAssembly { get; }

Property Value

IAssembly

AsAttributeTarget

Gets this code element casted to IAttributeTarget if it is a an assembly, a type, a method or a field, else gets null.

IAttributeTarget AsAttributeTarget { get; }

Property Value

IAttributeTarget

AsCodeBase

Gets this code element casted to ICodeBase if it is a code base, else gets null.

ICodeBase AsCodeBase { get; }

Property Value

ICodeBase

AsCodeContainer

Gets this code element casted to ICodeContainer if it is a an assembly, a namespace, a type or a method, else gets null.

ICodeContainer AsCodeContainer { get; }

Property Value

ICodeContainer

AsCodeElementParent

Gets this code element casted to ICodeElementParent if it is an assembly, a namespace or a type, else gets null.

ICodeElementParent AsCodeElementParent { get; }

Property Value

ICodeElementParent

AsEvent

Gets this code element casted to IEvent if it is a field, else gets null.

IEvent AsEvent { get; }

Property Value

IEvent

AsField

Gets this code element casted to IField if it is a field, else gets null.

IField AsField { get; }

Property Value

IField

AsMember

Gets this code element casted to IMember if it is a method or field, else gets null.

IMember AsMember { get; }

Property Value

IMember

AsMethod

Gets this code element casted to IMethod if it is a method, else gets null.

IMethod AsMethod { get; }

Property Value

IMethod

AsNamespace

Gets this code element casted to INamespace if it is a namespace, else gets null.

INamespace AsNamespace { get; }

Property Value

INamespace

AsProperty

Gets this code element casted to IProperty if it is a field, else gets null.

IProperty AsProperty { get; }

Property Value

IProperty

AsType

Gets this code element casted to IType if it is a type, else gets null.

IType AsType { get; }

Property Value

IType

AsTypeOrMember

Gets this code element casted to IMember if it is a type, method or field, else gets null.

IMember AsTypeOrMember { get; }

Property Value

IMember

FullName

Gets a string representing the full name of this code element.

string FullName { get; }

Property Value

string

Remarks

  • If this code element is a IType, the full name is NamespaceName.TypeName<T>.
  • If this code element is a nested IType, the full name is NamespaceName.OutterTypeName+TypeName<T>.
  • If this code element is a IMethod, the full name is NamespaceName.TypeName.Method<T>(parameters types).
  • If this code element is a IField, the full name is NamespaceName.TypeName.FieldName.
  • If the parent namespace is the anonymous namespace, the full name begins directly with TypeName....
  • If this code element is a INamespace or an IAssembly returns this.Name.
This property getter has a constant time complexity.
See Also
WithFullName<TCodeElement>(IEnumerable<TCodeElement>, string)
WithFullNameIn<TCodeElement>(IEnumerable<TCodeElement>, string, params string[])
WithFullNameNotIn<TCodeElement>(IEnumerable<TCodeElement>, string, params string[])
WithFullNameLike<TCodeElement>(IEnumerable<TCodeElement>, string)
WithFullNameWildcardMatch<TCodeElement>(IEnumerable<TCodeElement>, string)

HasParentAssembly

Gets a value indicating whether this code element has a parent assembly.

bool HasParentAssembly { get; }

Property Value

bool

Remarks

This property getter has a constant time complexity.
Returns false if this code element is an assembly or a code base.

See Also

HasParentNamespace

Gets a value indicating whether this code element has a parent namespace.

bool HasParentNamespace { get; }

Property Value

bool

Remarks

This property getter has a constant time complexity.
Returns false if this code element is a namespace, an assembly or a code base.

See Also

HasParentType

Gets a value indicating whether this code element has a parent type.

bool HasParentType { get; }

Property Value

bool

Remarks

This property getter has a constant time complexity.
Returns true only if this code element is a method, a field, a property or an event. Returns false if this code element is a type, even for a type nested in another type, in which case IMember.ParentType can be used.

See Also

IsAssembly

Gets a value indicating whether this code element is an assembly, and can then be safely downcasted to IAssembly.

bool IsAssembly { get; }

Property Value

bool

IsAttributeTarget

Gets a value indicating whether this code element is an assembly, a type, a method or a field, and can then be safely downcasted to IAttributeTarget.

bool IsAttributeTarget { get; }

Property Value

bool

IsCodeBase

Gets a value indicating whether this code element is a code base, and can then be safely downcasted to ICodeBase.

bool IsCodeBase { get; }

Property Value

bool

IsCodeContainer

Gets a value indicating whether this code element is an assembly, a namespace a type or a method, and can then be safely downcasted to ICodeContainer.

bool IsCodeContainer { get; }

Property Value

bool

IsCodeElementParent

Gets a value indicating whether this code element is an assembly, a namespace or a type, and can then be safely downcasted to ICodeElementParent.

bool IsCodeElementParent { get; }

Property Value

bool

IsEvent

Gets a value indicating whether this code element is an event, and can then be safely downcasted to IProperty.

bool IsEvent { get; }

Property Value

bool

IsField

Gets a value indicating whether this code element is a field, and can then be safely downcasted to IField.

bool IsField { get; }

Property Value

bool

IsMember

Gets a value indicating whether this code element is a method, field, property or event, and can then be safely downcasted to IMember.

bool IsMember { get; }

Property Value

bool

IsMethod

Gets a value indicating whether this code element is a method, and can then be safely downcasted to IMethod.

bool IsMethod { get; }

Property Value

bool

IsNamespace

Gets a value indicating whether this code element is a namespace, and can then be safely downcasted to INamespace.

bool IsNamespace { get; }

Property Value

bool

IsProperty

Gets a value indicating whether this code element is a property, and can then be safely downcasted to IProperty.

bool IsProperty { get; }

Property Value

bool

IsTestCode

Gets a value indicating whether this code element is test code.

bool IsTestCode { get; }

Property Value

bool

Remarks

An application assembly is test code when it references a test framework assembly (xUnit, NUnit, MSTest, TUnit...). Its child namespaces, types and members are then test code as well. Third-party code elements are never test code. This value is not persisted in the analysis result, it is inferred both at analysis time and when loading an analysis result. This property getter has a constant time complexity.

See Also

IsTestFramework

Gets a value indicating whether this code element is a test framework code element.

bool IsTestFramework { get; }

Property Value

bool

Remarks

A third-party assembly is a test framework when it is used by at least one assembly and all assemblies using it are test code (see IsTestCode). Test frameworks (xUnit, NUnit, MSTest, TUnit...) and test libraries (mocking, assertions...) are typically referenced only by test assemblies. Its child namespaces, types and members are then test framework code elements as well. Application and test code elements are never test framework. When the code base contains only test assemblies and no application assembly, no code element is test framework. This value is not persisted in the analysis result, it is inferred both at analysis time and when loading an analysis result. This property getter has a constant time complexity.

See Also

IsThirdParty

Gets a value indicating whether this code element is an application or a third-party code element.

bool IsThirdParty { get; }

Property Value

bool

true if this code element is declared in a third-party assembly, or is itself a third-party assembly.

Remarks

This property getter has a constant time complexity.

See Also
ExceptThirdParty<TCodeElement>(IEnumerable<TCodeElement>)

IsThirdPartyInferredFromRef

Gets a value indicating whether this code element is a third-party code element resolved from reference.

bool IsThirdPartyInferredFromRef { get; }

Property Value

bool

Remarks

Since NDepend v2021.2 when a third-party assembly is not found at analysis time, such assembly and its child namespaces, types, methods and fields are resolved from their references in application assemblies.

IsType

Gets a value indicating whether this code element is a type, and can then be safely downcasted to IType.

bool IsType { get; }

Property Value

bool

IsTypeOrMember

Gets a value indicating whether this code element is a type, method, field, property or event, and can then be safely downcasted to IMember.

bool IsTypeOrMember { get; }

Property Value

bool

Name

Gets a string representing the name of this code element.

string Name { get; }

Property Value

string

The name of this code element.

Remarks

  • In case of a code base, the name is equal to the IProject.Properties.Name.
  • In case of a type the name is TypeName<T> not prefixed with the parent namespace name.
  • In case of a nested type the name is OutterTypeName+TypeName<T> prefixed with the parent type name but not prefixed with the parent namespace name.
  • In case of a method the name is MethodName<T>(parameters types) not prefixed with the parent namespace name or parent type name.
  • In case of a field the name is FieldName not prefixed with the parent namespace name or parent type name.
  • In case of a namespace the name is simply the namespace name like N1.N2.N3.
  • The anonymous namespace of an assembly has a Name equals to the empty string.
  • In case of an assembly the name is the assembly main module file name, without file extension.
This property getter has a constant time complexity.
See Also
WithName<TCodeElement>(IEnumerable<TCodeElement>, string)
WithNameIn<TCodeElement>(IEnumerable<TCodeElement>, string, params string[])
WithNameNotIn<TCodeElement>(IEnumerable<TCodeElement>, string, params string[])
WithNameLike<TCodeElement>(IEnumerable<TCodeElement>, string)
WithNameWildcardMatch<TCodeElement>(IEnumerable<TCodeElement>, string)

Parent

Returns the code element parent of this code element.

ICodeElementParent Parent { get; }

Property Value

ICodeElementParent

Remarks

If this is a code base, returns this.
If this is an assembly, returns this ICodeElement.ParentCodeBase.
If this is a namespace, returns INamespace.ParentAssembly.
If this is a type, returns IMember.ParentNamespace.
If this is a type nested in one or several other types returns also IMember.ParentNamespace.
If this is a member (method or field), returns IMember.ParentType.

ParentAssembly

Gets the parent assembly of this code element, or null if this code element is an assembly or a code base.

IAssembly ParentAssembly { get; }

Property Value

IAssembly

Remarks

This property getter has a constant time complexity.

See Also

ParentCodeBase

Gets the parent code base of this code element

ICodeBase ParentCodeBase { get; }

Property Value

ICodeBase

The parent code base of this code element.

Remarks

If this is a code base, return this.

ParentNamespace

Gets the parent namespace of this code element, or null if this code element is a namespace, an assembly or a code base.

INamespace ParentNamespace { get; }

Property Value

INamespace

Remarks

This property getter has a constant time complexity.

See Also

ParentType

Gets the parent type of this code element, or null if this code element is not a method, a field, a property or an event.

IType ParentType { get; }

Property Value

IType

Remarks

This property getter has a constant time complexity.

See Also

Parents

Returns a sequence of code element parent of this code element.

IEnumerable<ICodeElementParent> Parents { get; }

Property Value

IEnumerable<ICodeElementParent>

Remarks

If this is a code base, the returned sequence is empty.
If this is an assembly, the returned sequence contains only the IAssembly.ParentCodeBase.
If this is a namespace, the returned sequence contains INamespace.ParentAssembly and then INamespace.ParentCodeBase.
If this is a type, the returned sequence contains first IMember.ParentNamespace and IMember.ParentAssembly and then IMember.ParentCodeBase.
If this is a type nested in one or several other types, the returned sequence doesn't contain the parent type(s).
If this is a member (method or field), the returned sequence contains first IMember.ParentType and IMember.ParentNamespace and IMember.ParentAssembly and then IMember.ParentCodeBase.

SimpleName

Gets this code element simple name, without its eventual parameters signature nor its eventual generic signature not prefixed by its parent type or namespace name.

string SimpleName { get; }

Property Value

string

Remarks

  • If this code element is a IType, the simple name is is the type name without the parent namespace name nor the generic arity.
  • If this code element is a IMethod, the simple name is is the method name without the parent type name nor the parameters.
  • If this code element is a INamespace, the simple name is is the namespace name without the parent namespaces names.
  • If this code element is a IField or an IAssembly returns this.Name.
  • See Also
    WithSimpleName<TCodeElement>(IEnumerable<TCodeElement>, string)
    WithSimpleNameIn<TCodeElement>(IEnumerable<TCodeElement>, string, params string[])
    WithSimpleNameNotIn<TCodeElement>(IEnumerable<TCodeElement>, string, params string[])
    WithSimpleNameLike<TCodeElement>(IEnumerable<TCodeElement>, string)
    WithSimpleNameWildcardMatch<TCodeElement>(IEnumerable<TCodeElement>, string)
    WithSimpleNameWildcardMatchIn<TCodeElement>(IEnumerable<TCodeElement>, string, params string[])
    WithSimpleNameWildcardMatchNotIn<TCodeElement>(IEnumerable<TCodeElement>, string, params string[])

    SourceDecls

    Returns one or several source file declarations of this code element. Returns an empty sequence if not SourceFileDeclAvailable.

    IEnumerable<ISourceDecl> SourceDecls { get; }

    Property Value

    IEnumerable<ISourceDecl>

    Remarks

    Assemblies, namespaces and types can have several source file declarations. Methods and fields can have at most one source file declaration.

    See Also

    SourceFileDeclAvailable

    Gets a value indicating whether source file declaration(s) of this code element have been gathered at analysis time and is now available.

    bool SourceFileDeclAvailable { get; }

    Property Value

    bool

    true if source file declaration(s) are available for this code element.

    Remarks

    So far only C# code is parsed and also, source file declarations for abstract methods and fields are not retreived. This situation will evolve in the future.

    See Also

    UniqueID

    Gets an integer identifier for this code element, unique in the scope of this ParentCodeBase.

    int UniqueID { get; }

    Property Value

    int

    Remarks

    This code element's unique identifier might be useful in situations where a unique hash code per code element, unique in the scope of this ParentCodeBase, is needed.

    Method (1)

    SimpleNameEquals(string)

    Returns true if this SimpleName equals name.

    bool SimpleNameEquals(string name)

    Parameters

    name string

    The name to check equality with.

    Returns

    bool

    Remarks

    This method avoid string allocation that occurs when calling SimpleName.

    See Also