Skip to content

Commit

Permalink
Add more extension methods (0xd4d#328)
Browse files Browse the repository at this point in the history
  • Loading branch information
CreateAndInject authored and wtfsck committed Dec 6, 2019
1 parent 6564f90 commit ebd0585
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/DotNet/ICodedToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,28 @@ static internal IAssembly GetDefinitionAssembly(this MemberRef mr) {

return null;
}

/// <summary>
/// Gets the normal visible parameters, doesn't include the hidden 'this' parameter
/// </summary>
/// <param name="method">this</param>
/// <returns>The normal visible parameters</returns>
public static IList<TypeSig> GetParams(this IMethod method) => method?.MethodSig.GetParams();

/// <summary>
/// Gets the normal visible parameter count, doesn't include the hidden 'this' parameter
/// </summary>
/// <param name="method">this</param>
/// <returns>Normal visible parameter count</returns>
public static int GetParamCount(this IMethod method) => method?.MethodSig.GetParamCount() ?? 0;

/// <summary>
/// Gets a normal visible parameter, doesn't include the hidden 'this' parameter
/// </summary>
/// <param name="method">this</param>
/// <param name="index">Normal visible parameter index</param>
/// <returns></returns>
public static TypeSig GetParam(this IMethod method, int index) => method?.MethodSig?.Params?[index];
}

/// <summary>
Expand Down
7 changes: 7 additions & 0 deletions src/DotNet/TypeSig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,13 @@ public static TypeSig RemovePinnedAndModifiers(this TypeSig a) {
/// <returns>Namespace of the type</returns>
public static string GetNamespace(this TypeSig a) => a is null ? string.Empty : a.Namespace;

/// <summary>
/// Returns the <see cref="ITypeDefOrRef"/> if it is a <see cref="TypeDefOrRefSig"/>.
/// </summary>
/// <param name="a">this</param>
/// <returns>A <see cref="ITypeDefOrRef"/> or <c>null</c> if none found</returns>
public static ITypeDefOrRef TryGetTypeDefOrRef(this TypeSig a) => (a.RemovePinnedAndModifiers() as TypeDefOrRefSig)?.TypeDefOrRef;

/// <summary>
/// Returns the <see cref="TypeRef"/> if it is a <see cref="TypeDefOrRefSig"/>.
/// </summary>
Expand Down

0 comments on commit ebd0585

Please sign in to comment.