Class ExtensionMethodsHelpers
Provides a set of extension methods that makes the code model API usage more convenient to use.
public static class ExtensionMethodsHelpers
- Inheritance
-
ExtensionMethodsHelpers
- Inherited Members
Methods (15)
ContainsSameCodeElementsThan<TCodeElement>(HashSet<TCodeElement>, HashSet<TCodeElement>)
Returns true if this codeElementsHashset hashset contains the same set of code elements than the otherCodeElementsHashset hashset. Otherwise returns false.
public static bool ContainsSameCodeElementsThan<TCodeElement>(this HashSet<TCodeElement> codeElementsHashset, HashSet<TCodeElement> otherCodeElementsHashset) where TCodeElement : class, ICodeElement
Parameters
codeElementsHashsetHashSet<TCodeElement>This hahshet of code elements objects.
otherCodeElementsHashsetHashSet<TCodeElement>The other hahshet of code elements objects.
Returns
Type Parameters
TCodeElementThe code element type that is ICodeElement or that implements ICodeElement.
Remarks
This ContainsSameCodeElementsThan<TCodeElement>(IEnumerable<TCodeElement>, IEnumerable<TCodeElement>) overload, relies on the fact that both codeElementsHashset and otherCodeElementsHashset are hashsets, to execute with a faster O(codeElementsHashset.Count) time complexity.
ContainsSameCodeElementsThan<TCodeElement>(HashSet<TCodeElement>, IEnumerable<TCodeElement>)
Returns true if this codeElementsHashset hashset contains the same set of code elements than the otherCodeElements sequence. Otherwise returns false.
public static bool ContainsSameCodeElementsThan<TCodeElement>(this HashSet<TCodeElement> codeElementsHashset, IEnumerable<TCodeElement> otherCodeElements) where TCodeElement : class, ICodeElement
Parameters
codeElementsHashsetHashSet<TCodeElement>This hahshet of code elements objects.
otherCodeElementsIEnumerable<TCodeElement>The other sequence of code elements objects.
Returns
Type Parameters
TCodeElementThe code element type that is ICodeElement or that implements ICodeElement.
Remarks
This ContainsSameCodeElementsThan<TCodeElement>(IEnumerable<TCodeElement>, IEnumerable<TCodeElement>) overload, relies on the fact that both codeElementsHashset and otherCodeElements are hashsets, to execute with a faster O(otherCodeElements.Count) time complexity.
Notice that otherCodeElements can contain doublons, hence this operation first gets otherCodeElements.Distinct().codeElementsHashset necessarily contains distinct code elements.
ContainsSameCodeElementsThan<TCodeElement>(IEnumerable<TCodeElement>, HashSet<TCodeElement>)
Returns true if this codeElements sequence contains the same set of code elements than the otherCodeElementsHashset hashset. Otherwise returns false.
public static bool ContainsSameCodeElementsThan<TCodeElement>(this IEnumerable<TCodeElement> codeElements, HashSet<TCodeElement> otherCodeElementsHashset) where TCodeElement : class, ICodeElement
Parameters
codeElementsIEnumerable<TCodeElement>This sequence of code elements objects.
otherCodeElementsHashsetHashSet<TCodeElement>The hahshet of code elements objects.
Returns
Type Parameters
TCodeElementThe code element type that is ICodeElement or that implements ICodeElement.
Remarks
This ContainsSameCodeElementsThan<TCodeElement>(IEnumerable<TCodeElement>, IEnumerable<TCodeElement>) overload, relies on the fact that otherCodeElementsHashset is a hashset to execute with a faster O(codeElements.Count) time complexity.
Notice that codeElements can contain doublons, hence this operation first gets codeElements.Distinct().otherCodeElementsHashset necessarily contains distinct code elements.
ContainsSameCodeElementsThan<TCodeElement>(IEnumerable<TCodeElement>, IEnumerable<TCodeElement>)
Returns true if this codeElements sequence contains the same set of code elements than the otherCodeElements sequence. Otherwise returns false.
public static bool ContainsSameCodeElementsThan<TCodeElement>(this IEnumerable<TCodeElement> codeElements, IEnumerable<TCodeElement> otherCodeElements) where TCodeElement : class, ICodeElement
Parameters
codeElementsIEnumerable<TCodeElement>This sequence of code elements objects.
otherCodeElementsIEnumerable<TCodeElement>The other sequence of code elements objects.
Returns
Type Parameters
TCodeElementThe code element type that is ICodeElement or that implements ICodeElement.
Remarks
Notice that both sequences can contain doublons, hence this operation first gets codeElements.Distinct() and otherCodeElements.Distinct().
This extension method has a O(codeElements.Count + otherCodeElements.Count) time complexity.
CreateCompareContextWithOlder(ICodeBase, ICodeBase)
Creates a new ICompareContext object, with newer for NewerCodeBase and older for OlderCodeBase.
public static ICompareContext CreateCompareContextWithOlder(this ICodeBase newer, ICodeBase older)
Parameters
newerICodeBaseThe ICodeBase object that represents the NewerCodeBase in the created compare context.
olderICodeBaseThe ICodeBase object that represents the OlderCodeBase in the created compare context.
Returns
Remarks
newer can be equal to older. This possibility is convenient if you need a see ICompareContext object from a ICodeBase object.
- See Also
ExceptTestCode<TCodeElement>(IEnumerable<TCodeElement>)
Filter code elements object from this codeElements sequence. Keeps only code elements for those ICodeElement.IsTestCode is false.
public static IEnumerable<TCodeElement> ExceptTestCode<TCodeElement>(this IEnumerable<TCodeElement> codeElements) where TCodeElement : class, ICodeElement
Parameters
codeElementsIEnumerable<TCodeElement>This sequence of code elements objects.
Returns
- IEnumerable<TCodeElement>
A sequence of code elements objects with a false value for IsTestCode.
Type Parameters
TCodeElementThe code element type that is ICodeElement or that implements ICodeElement.
Remarks
This extension method has a O(codeElements.Count) time complexity.
- See Also
ExceptThirdParty<TCodeElement>(IEnumerable<TCodeElement>)
Filter code elements object from this codeElements sequence. Keeps only code elements for those ICodeElement.IsThirdParty is false.
public static IEnumerable<TCodeElement> ExceptThirdParty<TCodeElement>(this IEnumerable<TCodeElement> codeElements) where TCodeElement : class, ICodeElement
Parameters
codeElementsIEnumerable<TCodeElement>This sequence of code elements objects.
Returns
- IEnumerable<TCodeElement>
A sequence of code elements objects with a false value for IsThirdParty.
Type Parameters
TCodeElementThe code element type that is ICodeElement or that implements ICodeElement.
Remarks
This extension method has a O(codeElements.Count) time complexity.
- See Also
FillIncremental<TCodeElement>(IEnumerable<TCodeElement>, Func<IEnumerable<TCodeElement>, IEnumerable<TCodeElement>>)
Iteratively fills a sequence of code elements, until no new element can be added. The first iteration starts with initialSeq, and the function func is used to compute new elements of the iteration N+1 from all elements computed until the iteration N.
public static ICodeMetric<TCodeElement, ushort> FillIncremental<TCodeElement>(this IEnumerable<TCodeElement> initialSeq, Func<IEnumerable<TCodeElement>, IEnumerable<TCodeElement>> func) where TCodeElement : class, ICodeElement
Parameters
initialSeqIEnumerable<TCodeElement>The initial sequence of code elements consumed by the first iteration.
funcFunc<IEnumerable<TCodeElement>, IEnumerable<TCodeElement>>The function used to compute new elements of the iteration N+1 from all elements computed until the iteration N.
Returns
- ICodeMetric<TCodeElement, ushort>
A new ICodeMetric<TCodeElement, TNumeric> object. The code metric value for each element in DefinitionDomain is the iteration number when it was added. Value for code elements in
initialSeqis 0.
Type Parameters
TCodeElementThe code element type that is ICodeElement or that implements ICodeElement.
Remarks
This method differs from FillIterative<TCodeElement>(IEnumerable<TCodeElement>, Func<IEnumerable<TCodeElement>, IEnumerable<TCodeElement>>) because all elements computed until iteration N are used to compute elements of iteration N+1.
Exceptions
- InvalidOperationException
The number of iterations has outreached the maximum iterations threshold, which is fixed to 100.
- ArgumentNullException
initialSeqor a sequence returned by a call tofunccontains a nullTCodeElement.
FillIterative<TCodeElement>(IEnumerable<TCodeElement>, Func<IEnumerable<TCodeElement>, IEnumerable<TCodeElement>>)
Iteratively fills a sequence of code elements, until no new element can be added. The first iteration starts with initialSeq, and the function func is used to compute new elements of the iteration N+1 from new elements computed at iteration N.
public static ICodeMetric<TCodeElement, ushort> FillIterative<TCodeElement>(this IEnumerable<TCodeElement> initialSeq, Func<IEnumerable<TCodeElement>, IEnumerable<TCodeElement>> func) where TCodeElement : class, ICodeElement
Parameters
initialSeqIEnumerable<TCodeElement>The initial sequence of code elements consumed by the first iteration.
funcFunc<IEnumerable<TCodeElement>, IEnumerable<TCodeElement>>The function used to compute new elements of the iteration N+1 from new elements computed at iteration N.
Returns
- ICodeMetric<TCodeElement, ushort>
A new ICodeMetric<TCodeElement, TNumeric> object. The code metric value for each element in DefinitionDomain is the iteration number when it was added. Value for code elements in
initialSeqis 0.
Type Parameters
TCodeElementThe code element type that is ICodeElement or that implements ICodeElement.
Remarks
This method differs from FillIncremental<TCodeElement>(IEnumerable<TCodeElement>, Func<IEnumerable<TCodeElement>, IEnumerable<TCodeElement>>) because only elements computed at iteration N are used to compute elements of iteration N+1.
Exceptions
- InvalidOperationException
The number of iterations has outreached the maximum iterations threshold, which is fixed to 100.
- ArgumentNullException
initialSeqor a sequence returned by a call tofunccontains a nullTCodeElement.
GetImage<T>(ICodeElement)
Get the image that represents the codeElement.
public static T GetImage<T>(this ICodeElement codeElement) where T : class
Parameters
codeElementICodeElementThe code element.
Returns
- T
Type Parameters
T
GetNbLinesOfCode_GuaranteedIfPDBFound(ICodeElement)
Try gets a number of lines of code for an application codeElement.
This value is guaranteed not being zero if the code element is in an assembly for which PDB file has been found and parsed.
public static uint? GetNbLinesOfCode_GuaranteedIfPDBFound(this ICodeElement codeElement)
Parameters
codeElementICodeElementThe code element for which we want to obtain the number of line of code
Returns
- uint?
Remarks
The metric ICodeContainer.NbLinesOfCode is computed from number of sequence points obtained at analysis time when parsing a PDB file.
As a consequence, if a PDB file is not found, all associated ICodeElement objects have a nullNbLinesOfCode.
s
However there are several cases where this metric is not defined for a code elements declared in an assembly with PDB file found:
- Abstract method
- Implicit constructor
- Field
- Interface
- Enumeration
- Namespace, assembly or code base that contains only interfaces and enumerations
This method is returning a non-null, non-zero value ifcodeElementsatisfies the PDB found condition. - This value is 1 for any abstract method, implicit constructor or field.
- In all other cases,
codeElementis a ICodeElementParent object, and this methods returns NbLinesOfCode + MeAndRecursiveChildren.Count<TSource>(IEnumerable<TSource>).
Notice that in the peculiar case wherecodeElementis a ICodeBase, the PDB found condition means that a PDB file must have been resolved for all application assemblies at analysis time.
Notice that this method returns null for any third-party code element.
- See Also
ToFullNameLikePredicate(string)
Returns a predicate object that takes a IMember object as input parameter, and returns a boolean that determines whether the member's FullName matches the regular expression regexString.
public static Predicate<ICodeElement> ToFullNameLikePredicate(this string regexString)
Parameters
regexStringstringThe regular expression string.
Returns
Remarks
The regular expression is defined with the System.Text.RegularExpressions syntax.
The regular expression string can be suffixed with "\i" to specify the ignore case option.
Exceptions
- ArgumentException
regexStringis an invalid regular exception.
- See Also
ToNameLikePredicate(string)
Returns a predicate object that takes a ICodeElement object as input parameter, and returns a boolean that determines whether the code element's Name matches the regular expression regexString.
public static Predicate<ICodeElement> ToNameLikePredicate(this string regexString)
Parameters
regexStringstringThe regular expression string.
Returns
Remarks
The regular expression is defined with the System.Text.RegularExpressions syntax.
The regular expression string can be suffixed with "\i" to specify the ignore case option.
Exceptions
- ArgumentException
regexStringis an invalid regular exception.
- See Also
ToSimpleNameLikePredicate(string)
Returns a predicate object that takes a IMethod object as input parameter, and returns a boolean that determines whether the code element's SimpleName matches the regular expression regexString.
public static Predicate<ICodeElement> ToSimpleNameLikePredicate(this string regexString)
Parameters
regexStringstringThe regular expression string.
Returns
Remarks
The regular expression is defined with the System.Text.RegularExpressions syntax.
The regular expression string can be suffixed with "\i" to specify the ignore case option.
Exceptions
- ArgumentException
regexStringis an invalid regular exception.
- See Also
TryGetSourceFileContent(ICodeBase, IAbsoluteFilePath, out string, out string)
Try to get the content of a source file as it was at analysis time.
public static bool TryGetSourceFileContent(this ICodeBase codeBase, IAbsoluteFilePath sourceFilePath, out string sourceFileContent, out string failureReason)
Parameters
codeBaseICodeBaseThe code base that contains the source file.
sourceFilePathIAbsoluteFilePathThe source file absolute path obtained from ICodeElement.SourceDecls or from ICodeBase.SourceFiles.
sourceFileContentstringIf this method succeeds and returns true, contains source file content.
failureReasonstringIf this method fails and returns false, contains a plain-english description of the failure.
Returns
Remarks
If ZipSourceFiles is true (which is the default value) source files get zipped at analysis time.
This method attempts to retrieve a source file content from this zipped store.
This method is different than trying to get the content from sourceFilePath. Since the analysis has been executed the source file might have been edited or removed.