-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
87db902
commit 63198eb
Showing
10 changed files
with
372 additions
and
311 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
using ILSourceParser.Syntax; | ||
using System.Globalization; | ||
|
||
namespace ILSourceParser.Utilities; | ||
|
||
/// <summary> | ||
/// Represents a single extension method that provides the <see cref="AsByte(ByteSyntax)"/> method | ||
/// to <see cref="ByteSyntax"/>. | ||
/// </summary> | ||
public static class AsByteExtension | ||
{ | ||
private const NumberStyles s_preferredAsByteNumberStyle = NumberStyles.HexNumber; | ||
|
||
/// <summary> | ||
/// Converts the string value of <see cref="ByteSyntax"/> as <see cref="byte"/>. | ||
/// </summary> | ||
/// <param name="syntax">The input <see cref="ByteSyntax"/>.</param> | ||
/// <returns><see cref="ByteSyntax"/> value converted to <see cref="byte"/>.</returns> | ||
public static byte AsByte(this ByteSyntax syntax) | ||
=> byte.Parse(syntax.Value, s_preferredAsByteNumberStyle); | ||
} | ||
using ILSourceParser.Syntax; | ||
using System.Globalization; | ||
|
||
namespace ILSourceParser.Utilities; | ||
|
||
/// <summary> | ||
/// Represents a single extension method that provides the <see cref="AsByte(ByteSyntax)"/> method | ||
/// to <see cref="ByteSyntax"/>. | ||
/// </summary> | ||
public static class AsByteExtension | ||
{ | ||
private const NumberStyles s_preferredAsByteNumberStyle = NumberStyles.HexNumber; | ||
|
||
/// <summary> | ||
/// Converts the string value of <see cref="ByteSyntax"/> as <see cref="byte"/>. | ||
/// </summary> | ||
/// <param name="syntax">The input <see cref="ByteSyntax"/>.</param> | ||
/// <returns><see cref="ByteSyntax"/> value converted to <see cref="byte"/>.</returns> | ||
public static byte AsByte(this ByteSyntax syntax) | ||
=> byte.Parse(syntax.Value, s_preferredAsByteNumberStyle); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,23 @@ | ||
using ILSourceParser.Syntax.Marshaling; | ||
|
||
namespace ILSourceParser.Utilities; | ||
|
||
/// <summary> | ||
/// Converts <see cref="MarshalTypeSyntax"/> to <see cref="ParameterMarshalSyntax"/>. | ||
/// </summary> | ||
public static class AsParameterMarshalExtension | ||
{ | ||
/// <summary> | ||
/// Converts <see cref="MarshalTypeSyntax"/> to <see cref="ParameterMarshalSyntax"/>. | ||
/// </summary> | ||
/// <param name="marshalType">The input type of marshal to process.</param> | ||
/// <returns>An output marshal.</returns> | ||
public static ParameterMarshalSyntax AsParameterMarshal( | ||
this MarshalTypeSyntax marshalType) | ||
{ | ||
return new ParameterMarshalSyntax( | ||
leadingTrivia: marshalType.LeadingTrivia, | ||
trailingTrivia: marshalType.TrailingTrivia, | ||
marshalType: marshalType); | ||
} | ||
} | ||
using ILSourceParser.Syntax.Marshaling; | ||
|
||
namespace ILSourceParser.Utilities; | ||
|
||
/// <summary> | ||
/// Converts <see cref="MarshalTypeSyntax"/> to <see cref="ParameterMarshalSyntax"/>. | ||
/// </summary> | ||
public static class AsParameterMarshalExtension | ||
{ | ||
/// <summary> | ||
/// Converts <see cref="MarshalTypeSyntax"/> to <see cref="ParameterMarshalSyntax"/>. | ||
/// </summary> | ||
/// <param name="marshalType">The input type of marshal to process.</param> | ||
/// <returns>An output marshal.</returns> | ||
public static ParameterMarshalSyntax AsParameterMarshal( | ||
this MarshalTypeSyntax marshalType) | ||
{ | ||
return new ParameterMarshalSyntax( | ||
leadingTrivia: marshalType.LeadingTrivia, | ||
trailingTrivia: marshalType.TrailingTrivia, | ||
marshalType: marshalType); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using ILSourceParser.Syntax; | ||
|
||
namespace ILSourceParser.Utilities; | ||
|
||
/// <summary> | ||
/// Represents a single extension that provides the method <see cref="AsVersion(VerDirectiveSyntax)"/> to <see cref="VerDirectiveSyntax"/>. | ||
/// </summary> | ||
public static class AsVersionExtension | ||
{ | ||
/// <summary> | ||
/// Converts values of the <c>.ver</c> directive into <see cref="Version"/>. | ||
/// </summary> | ||
/// <param name="directive">The information about the <c>.ver</c> IL directive.</param> | ||
/// <returns>A new instance of <see cref="Version"/>.</returns> | ||
public static Version AsVersion(this VerDirectiveSyntax directive) => | ||
new(directive.Major - '0', directive.Minor - '0', directive.Build - '0', directive.Revision - '0'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
namespace ILSourceParser.Utilities; | ||
|
||
public static partial class CommonNodeUtilities | ||
{ | ||
} | ||
namespace ILSourceParser.Utilities; | ||
|
||
public static partial class CommonNodeUtilities | ||
{ | ||
} |
236 changes: 118 additions & 118 deletions
236
ILSourceParser/Utilities/GetAssemblyNameExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,118 +1,118 @@ | ||
using ILSourceParser.Syntax; | ||
|
||
namespace ILSourceParser.Utilities; | ||
|
||
/// <summary> | ||
/// A bunch of extension methods that retrieve names of assemblies from | ||
/// given syntax nodes. | ||
/// </summary> | ||
public static class GetAssemblyNameExtensions | ||
{ | ||
/// <summary> | ||
/// Returns the explicit name of the assembly from this syntax node. For example, | ||
/// if the type reference is prefixed with <c>[System.Private.CoreLib]</c>, this | ||
/// method will return <c>System.Private.CoreLib</c> as a string. If assembly reference | ||
/// is omitted, this method returns <see langword="NULL"/>. | ||
/// </summary> | ||
/// <param name="attribute">The syntax node to get assembly name from.</param> | ||
/// <returns> | ||
/// If assembly name is explicitly emitted, returns the name of the assembly. Otherwise, returns <see langword="NULL"/> | ||
/// </returns> | ||
public static string? GetAssemblyName(this AnonymousCustomAttributeSyntax attribute) => | ||
attribute.AttributeConstructorTarget.GetAssemblyName(); | ||
|
||
/// <summary> | ||
/// Returns the explicit name of the assembly from this syntax node. For example, | ||
/// if the type reference is prefixed with <c>[System.Private.CoreLib]</c>, this | ||
/// method will return <c>System.Private.CoreLib</c> as a string. If assembly reference | ||
/// is omitted, this method returns <see langword="NULL"/>. | ||
/// </summary> | ||
/// <param name="customAttribute">The syntax node to get assembly name from.</param> | ||
/// <returns> | ||
/// If assembly name is explicitly emitted, returns the name of the assembly. Otherwise, returns <see langword="NULL"/> | ||
/// </returns> | ||
public static string? GetAssemblyName(this CustomAttributeSyntax customAttribute) => | ||
customAttribute.AttributeConstructorTarget.GetAssemblyName(); | ||
|
||
/// <summary> | ||
/// Returns the explicit name of the assembly from this syntax node. For example, | ||
/// if the type reference is prefixed with <c>[System.Private.CoreLib]</c>, this | ||
/// method will return <c>System.Private.CoreLib</c> as a string. If assembly reference | ||
/// is omitted, this method returns <see langword="NULL"/>. | ||
/// </summary> | ||
/// <param name="reference">The syntax node to get assembly name from.</param> | ||
/// <returns> | ||
/// If assembly name is explicitly emitted, returns the name of the assembly. Otherwise, returns <see langword="NULL"/> | ||
/// </returns> | ||
public static string? GetAssemblyName(this NonGenericTypeReferenceSyntax reference) => | ||
reference.AssemblyReference?.AssemblyName; | ||
|
||
/// <summary> | ||
/// Returns the explicit name of the assembly from this syntax node. For example, | ||
/// if the type reference is prefixed with <c>[System.Private.CoreLib]</c>, this | ||
/// method will return <c>System.Private.CoreLib</c> as a string. If assembly reference | ||
/// is omitted, this method returns <see langword="NULL"/>. | ||
/// </summary> | ||
/// <param name="reference">The syntax node to get assembly name from.</param> | ||
/// <returns> | ||
/// If assembly name is explicitly emitted, returns the name of the assembly. Otherwise, returns <see langword="NULL"/> | ||
/// </returns> | ||
public static string? GetAssemblyName(this GenericTypeReferenceSyntax reference) => | ||
reference.AssemblyReference?.AssemblyName; | ||
|
||
/// <summary> | ||
/// Returns the explicit name of the assembly from this syntax node. For example, | ||
/// if the type reference is prefixed with <c>[System.Private.CoreLib]</c>, this | ||
/// method will return <c>System.Private.CoreLib</c> as a string. If assembly reference | ||
/// is omitted, this method returns <see langword="NULL"/>. | ||
/// </summary> | ||
/// <param name="typeReference">The syntax node to get assembly name from.</param> | ||
/// <returns> | ||
/// If assembly name is explicitly emitted, returns the name of the assembly. Otherwise, returns <see langword="NULL"/> | ||
/// </returns> | ||
public static string? GetAssemblyName(this TypeReferenceSyntax typeReference) => | ||
typeReference is NonGenericTypeReferenceSyntax nonGeneric | ||
? nonGeneric.AssemblyReference?.AssemblyName | ||
: typeReference is GenericTypeReferenceSyntax generic | ||
? generic.AssemblyReference?.AssemblyName | ||
: null; | ||
|
||
/// <summary> | ||
/// Returns the explicit name of the assembly from this syntax node. For example, | ||
/// if the type reference is prefixed with <c>[System.Private.CoreLib]</c>, this | ||
/// method will return <c>System.Private.CoreLib</c> as a string. If assembly reference | ||
/// is omitted, this method returns <see langword="NULL"/>. | ||
/// </summary> | ||
/// <param name="type">The syntax node to get assembly name from.</param> | ||
/// <returns> | ||
/// If assembly name is explicitly emitted, returns the name of the assembly. Otherwise, returns <see langword="NULL"/> | ||
/// </returns> | ||
public static string? GetAssemblyName(this TypeSyntax type) => | ||
type is TypeReferenceSyntax typeReference ? typeReference.GetAssemblyName() : null; | ||
|
||
/// <summary> | ||
/// Returns the explicit name of the assembly from this syntax node. For example, | ||
/// if the type reference is prefixed with <c>[System.Private.CoreLib]</c>, this | ||
/// method will return <c>System.Private.CoreLib</c> as a string. If assembly reference | ||
/// is omitted, this method returns <see langword="NULL"/>. | ||
/// </summary> | ||
/// <param name="invocation">The syntax node to get assembly name from.</param> | ||
/// <returns> | ||
/// If assembly name is explicitly emitted, returns the name of the assembly. Otherwise, returns <see langword="NULL"/> | ||
/// </returns> | ||
public static string? GetAssemblyName(this MethodInvocationSyntax invocation) => | ||
invocation.TypeReference.GetAssemblyName(); | ||
|
||
/// <summary> | ||
/// Returns the explicit name of the assembly from this syntax node. For example, | ||
/// if the type reference is prefixed with <c>[System.Private.CoreLib]</c>, this | ||
/// method will return <c>System.Private.CoreLib</c> as a string. If assembly reference | ||
/// is omitted, this method returns <see langword="NULL"/>. | ||
/// </summary> | ||
/// <param name="call">The syntax node to get assembly name from.</param> | ||
/// <returns> | ||
/// If assembly name is explicitly emitted, returns the name of the assembly. Otherwise, returns <see langword="NULL"/> | ||
/// </returns> | ||
public static string? GetAssemblyName(this MethodCallSyntax call) => | ||
call.MethodInvocation.GetAssemblyName(); | ||
} | ||
using ILSourceParser.Syntax; | ||
|
||
namespace ILSourceParser.Utilities; | ||
|
||
/// <summary> | ||
/// A bunch of extension methods that retrieve names of assemblies from | ||
/// given syntax nodes. | ||
/// </summary> | ||
public static class GetAssemblyNameExtensions | ||
{ | ||
/// <summary> | ||
/// Returns the explicit name of the assembly from this syntax node. For example, | ||
/// if the type reference is prefixed with <c>[System.Private.CoreLib]</c>, this | ||
/// method will return <c>System.Private.CoreLib</c> as a string. If assembly reference | ||
/// is omitted, this method returns <see langword="NULL"/>. | ||
/// </summary> | ||
/// <param name="attribute">The syntax node to get assembly name from.</param> | ||
/// <returns> | ||
/// If assembly name is explicitly emitted, returns the name of the assembly. Otherwise, returns <see langword="NULL"/> | ||
/// </returns> | ||
public static string? GetAssemblyName(this AnonymousCustomAttributeSyntax attribute) => | ||
attribute.AttributeConstructorTarget.GetAssemblyName(); | ||
|
||
/// <summary> | ||
/// Returns the explicit name of the assembly from this syntax node. For example, | ||
/// if the type reference is prefixed with <c>[System.Private.CoreLib]</c>, this | ||
/// method will return <c>System.Private.CoreLib</c> as a string. If assembly reference | ||
/// is omitted, this method returns <see langword="NULL"/>. | ||
/// </summary> | ||
/// <param name="customAttribute">The syntax node to get assembly name from.</param> | ||
/// <returns> | ||
/// If assembly name is explicitly emitted, returns the name of the assembly. Otherwise, returns <see langword="NULL"/> | ||
/// </returns> | ||
public static string? GetAssemblyName(this CustomAttributeSyntax customAttribute) => | ||
customAttribute.AttributeConstructorTarget.GetAssemblyName(); | ||
|
||
/// <summary> | ||
/// Returns the explicit name of the assembly from this syntax node. For example, | ||
/// if the type reference is prefixed with <c>[System.Private.CoreLib]</c>, this | ||
/// method will return <c>System.Private.CoreLib</c> as a string. If assembly reference | ||
/// is omitted, this method returns <see langword="NULL"/>. | ||
/// </summary> | ||
/// <param name="reference">The syntax node to get assembly name from.</param> | ||
/// <returns> | ||
/// If assembly name is explicitly emitted, returns the name of the assembly. Otherwise, returns <see langword="NULL"/> | ||
/// </returns> | ||
public static string? GetAssemblyName(this NonGenericTypeReferenceSyntax reference) => | ||
reference.AssemblyReference?.AssemblyName; | ||
|
||
/// <summary> | ||
/// Returns the explicit name of the assembly from this syntax node. For example, | ||
/// if the type reference is prefixed with <c>[System.Private.CoreLib]</c>, this | ||
/// method will return <c>System.Private.CoreLib</c> as a string. If assembly reference | ||
/// is omitted, this method returns <see langword="NULL"/>. | ||
/// </summary> | ||
/// <param name="reference">The syntax node to get assembly name from.</param> | ||
/// <returns> | ||
/// If assembly name is explicitly emitted, returns the name of the assembly. Otherwise, returns <see langword="NULL"/> | ||
/// </returns> | ||
public static string? GetAssemblyName(this GenericTypeReferenceSyntax reference) => | ||
reference.AssemblyReference?.AssemblyName; | ||
|
||
/// <summary> | ||
/// Returns the explicit name of the assembly from this syntax node. For example, | ||
/// if the type reference is prefixed with <c>[System.Private.CoreLib]</c>, this | ||
/// method will return <c>System.Private.CoreLib</c> as a string. If assembly reference | ||
/// is omitted, this method returns <see langword="NULL"/>. | ||
/// </summary> | ||
/// <param name="typeReference">The syntax node to get assembly name from.</param> | ||
/// <returns> | ||
/// If assembly name is explicitly emitted, returns the name of the assembly. Otherwise, returns <see langword="NULL"/> | ||
/// </returns> | ||
public static string? GetAssemblyName(this TypeReferenceSyntax typeReference) => | ||
typeReference is NonGenericTypeReferenceSyntax nonGeneric | ||
? nonGeneric.AssemblyReference?.AssemblyName | ||
: typeReference is GenericTypeReferenceSyntax generic | ||
? generic.AssemblyReference?.AssemblyName | ||
: null; | ||
|
||
/// <summary> | ||
/// Returns the explicit name of the assembly from this syntax node. For example, | ||
/// if the type reference is prefixed with <c>[System.Private.CoreLib]</c>, this | ||
/// method will return <c>System.Private.CoreLib</c> as a string. If assembly reference | ||
/// is omitted, this method returns <see langword="NULL"/>. | ||
/// </summary> | ||
/// <param name="type">The syntax node to get assembly name from.</param> | ||
/// <returns> | ||
/// If assembly name is explicitly emitted, returns the name of the assembly. Otherwise, returns <see langword="NULL"/> | ||
/// </returns> | ||
public static string? GetAssemblyName(this TypeSyntax type) => | ||
type is TypeReferenceSyntax typeReference ? typeReference.GetAssemblyName() : null; | ||
|
||
/// <summary> | ||
/// Returns the explicit name of the assembly from this syntax node. For example, | ||
/// if the type reference is prefixed with <c>[System.Private.CoreLib]</c>, this | ||
/// method will return <c>System.Private.CoreLib</c> as a string. If assembly reference | ||
/// is omitted, this method returns <see langword="NULL"/>. | ||
/// </summary> | ||
/// <param name="invocation">The syntax node to get assembly name from.</param> | ||
/// <returns> | ||
/// If assembly name is explicitly emitted, returns the name of the assembly. Otherwise, returns <see langword="NULL"/> | ||
/// </returns> | ||
public static string? GetAssemblyName(this MethodInvocationSyntax invocation) => | ||
invocation.TypeReference.GetAssemblyName(); | ||
|
||
/// <summary> | ||
/// Returns the explicit name of the assembly from this syntax node. For example, | ||
/// if the type reference is prefixed with <c>[System.Private.CoreLib]</c>, this | ||
/// method will return <c>System.Private.CoreLib</c> as a string. If assembly reference | ||
/// is omitted, this method returns <see langword="NULL"/>. | ||
/// </summary> | ||
/// <param name="call">The syntax node to get assembly name from.</param> | ||
/// <returns> | ||
/// If assembly name is explicitly emitted, returns the name of the assembly. Otherwise, returns <see langword="NULL"/> | ||
/// </returns> | ||
public static string? GetAssemblyName(this MethodCallSyntax call) => | ||
call.MethodInvocation.GetAssemblyName(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
using ILSourceParser.Syntax; | ||
|
||
namespace ILSourceParser.Utilities; | ||
|
||
/// <summary> | ||
/// Represents a single extension method <see cref="GetBoolean(BooleanLiteralSyntax)"/> | ||
/// for <see cref="BooleanLiteralSyntax"/>. | ||
/// </summary> | ||
public static class GetByteExtension | ||
{ | ||
/// <summary> | ||
/// Returns the boolean for <see cref="BooleanLiteralSyntax"/> based on the value | ||
/// of the literal, whether it is <c>true</c> or <c>false</c>. | ||
/// </summary> | ||
/// <param name="literal">The input boolean literal.</param> | ||
/// <returns>A boolean from the boolean literal.</returns> | ||
public static bool GetBoolean(this BooleanLiteralSyntax literal) => | ||
literal.Value.Equals(BooleanLiteralSyntax.TrueEqualityString); | ||
} | ||
using ILSourceParser.Syntax; | ||
|
||
namespace ILSourceParser.Utilities; | ||
|
||
/// <summary> | ||
/// Represents a single extension method <see cref="GetBoolean(BooleanLiteralSyntax)"/> | ||
/// for <see cref="BooleanLiteralSyntax"/>. | ||
/// </summary> | ||
public static class GetByteExtension | ||
{ | ||
/// <summary> | ||
/// Returns the boolean for <see cref="BooleanLiteralSyntax"/> based on the value | ||
/// of the literal, whether it is <c>true</c> or <c>false</c>. | ||
/// </summary> | ||
/// <param name="literal">The input boolean literal.</param> | ||
/// <returns>A boolean from the boolean literal.</returns> | ||
public static bool GetBoolean(this BooleanLiteralSyntax literal) => | ||
literal.Value.Equals(BooleanLiteralSyntax.TrueEqualityString); | ||
} |
Oops, something went wrong.