mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-14 20:54:16 +01:00
docs: anna sig stuff helpers
This commit is contained in:
parent
89240c0e1e
commit
4dc0096ff3
8 changed files with 69 additions and 5 deletions
|
|
@ -6,12 +6,30 @@ using System.Reflection;
|
||||||
|
|
||||||
namespace Dalamud.Utility.Signatures
|
namespace Dalamud.Utility.Signatures
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Class providing info about field, property or parameter nullability.
|
||||||
|
/// </summary>
|
||||||
internal static class NullabilityUtil
|
internal static class NullabilityUtil
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Check if the provided property is nullable.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="property">The property to check.</param>
|
||||||
|
/// <returns>Whether or not the property is nullable.</returns>
|
||||||
internal static bool IsNullable(PropertyInfo property) => IsNullableHelper(property.PropertyType, property.DeclaringType, property.CustomAttributes);
|
internal static bool IsNullable(PropertyInfo property) => IsNullableHelper(property.PropertyType, property.DeclaringType, property.CustomAttributes);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Check if the provided field is nullable.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="field">The field to check.</param>
|
||||||
|
/// <returns>Whether or not the field is nullable.</returns>
|
||||||
internal static bool IsNullable(FieldInfo field) => IsNullableHelper(field.FieldType, field.DeclaringType, field.CustomAttributes);
|
internal static bool IsNullable(FieldInfo field) => IsNullableHelper(field.FieldType, field.DeclaringType, field.CustomAttributes);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Check if the provided parameter is nullable.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="parameter">The parameter to check.</param>
|
||||||
|
/// <returns>Whether or not the parameter is nullable.</returns>
|
||||||
internal static bool IsNullable(ParameterInfo parameter) => IsNullableHelper(parameter.ParameterType, parameter.Member, parameter.CustomAttributes);
|
internal static bool IsNullable(ParameterInfo parameter) => IsNullableHelper(parameter.ParameterType, parameter.Member, parameter.CustomAttributes);
|
||||||
|
|
||||||
private static bool IsNullableHelper(Type memberType, MemberInfo? declaringType, IEnumerable<CustomAttributeData> customAttributes)
|
private static bool IsNullableHelper(Type memberType, MemberInfo? declaringType, IEnumerable<CustomAttributeData> customAttributes)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
namespace Dalamud.Utility.Signatures
|
using Dalamud.Game;
|
||||||
|
|
||||||
|
namespace Dalamud.Utility.Signatures
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The type of scan to perform with a signature.
|
/// The type of scan to perform with a signature.
|
||||||
|
|
@ -13,7 +15,7 @@
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Scans the text section of the executable in order to find a data section
|
/// Scans the text section of the executable in order to find a data section
|
||||||
/// address. Uses <see cref="SigScanner.TryGetStaticAddressFromSig"/>
|
/// address. Uses <see cref="SigScanner.TryGetStaticAddressFromSig"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
StaticAddress,
|
StaticAddress,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ namespace Dalamud.Utility.Signatures
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="SignatureAttribute"/> class.
|
/// Initializes a new instance of the <see cref="SignatureAttribute"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="signature">signature to scan for, see <see cref="Signature"/></param>
|
/// <param name="signature">signature to scan for, see <see cref="Signature"/>.</param>
|
||||||
public SignatureAttribute(string signature)
|
public SignatureAttribute(string signature)
|
||||||
{
|
{
|
||||||
this.Signature = signature;
|
this.Signature = signature;
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,8 @@ namespace Dalamud.Utility.Signatures
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message">Message.</param>
|
/// <param name="message">Message.</param>
|
||||||
internal SignatureException(string message)
|
internal SignatureException(string message)
|
||||||
: base(message) { }
|
: base(message)
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,26 +3,38 @@ using System.Reflection;
|
||||||
|
|
||||||
namespace Dalamud.Utility.Signatures.Wrappers
|
namespace Dalamud.Utility.Signatures.Wrappers
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Class providing information about a field.
|
||||||
|
/// </summary>
|
||||||
internal sealed class FieldInfoWrapper : IFieldOrPropertyInfo
|
internal sealed class FieldInfoWrapper : IFieldOrPropertyInfo
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="FieldInfoWrapper"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="info">FieldInfo to populate from.</param>
|
||||||
public FieldInfoWrapper(FieldInfo info)
|
public FieldInfoWrapper(FieldInfo info)
|
||||||
{
|
{
|
||||||
this.Info = info;
|
this.Info = info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
public string Name => this.Info.Name;
|
public string Name => this.Info.Name;
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
public Type ActualType => this.Info.FieldType;
|
public Type ActualType => this.Info.FieldType;
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
public bool IsNullable => NullabilityUtil.IsNullable(this.Info);
|
public bool IsNullable => NullabilityUtil.IsNullable(this.Info);
|
||||||
|
|
||||||
private FieldInfo Info { get; }
|
private FieldInfo Info { get; }
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
public void SetValue(object? self, object? value)
|
public void SetValue(object? self, object? value)
|
||||||
{
|
{
|
||||||
this.Info.SetValue(self, value);
|
this.Info.SetValue(self, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
public T? GetCustomAttribute<T>() where T : Attribute
|
public T? GetCustomAttribute<T>() where T : Attribute
|
||||||
{
|
{
|
||||||
return this.Info.GetCustomAttribute<T>();
|
return this.Info.GetCustomAttribute<T>();
|
||||||
|
|
|
||||||
|
|
@ -2,16 +2,38 @@ using System;
|
||||||
|
|
||||||
namespace Dalamud.Utility.Signatures.Wrappers
|
namespace Dalamud.Utility.Signatures.Wrappers
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Interface providing information about a field or a property.
|
||||||
|
/// </summary>
|
||||||
internal interface IFieldOrPropertyInfo
|
internal interface IFieldOrPropertyInfo
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the name of the field or property.
|
||||||
|
/// </summary>
|
||||||
string Name { get; }
|
string Name { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the actual type of the field or property.
|
||||||
|
/// </summary>
|
||||||
Type ActualType { get; }
|
Type ActualType { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether or not the field or property is nullable.
|
||||||
|
/// </summary>
|
||||||
bool IsNullable { get; }
|
bool IsNullable { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Set this field or property's value.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="self">The object instance.</param>
|
||||||
|
/// <param name="value">The value to set.</param>
|
||||||
void SetValue(object? self, object? value);
|
void SetValue(object? self, object? value);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get a custom attribute.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The type of the attribute.</typeparam>
|
||||||
|
/// <returns>The attribute.</returns>
|
||||||
T? GetCustomAttribute<T>() where T : Attribute;
|
T? GetCustomAttribute<T>() where T : Attribute;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,9 @@ using System.Reflection;
|
||||||
|
|
||||||
namespace Dalamud.Utility.Signatures.Wrappers
|
namespace Dalamud.Utility.Signatures.Wrappers
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Class providing information about a property.
|
||||||
|
/// </summary>
|
||||||
internal sealed class PropertyInfoWrapper : IFieldOrPropertyInfo
|
internal sealed class PropertyInfoWrapper : IFieldOrPropertyInfo
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -14,19 +17,24 @@ namespace Dalamud.Utility.Signatures.Wrappers
|
||||||
this.Info = info;
|
this.Info = info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
public string Name => this.Info.Name;
|
public string Name => this.Info.Name;
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
public Type ActualType => this.Info.PropertyType;
|
public Type ActualType => this.Info.PropertyType;
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
public bool IsNullable => NullabilityUtil.IsNullable(this.Info);
|
public bool IsNullable => NullabilityUtil.IsNullable(this.Info);
|
||||||
|
|
||||||
private PropertyInfo Info { get; }
|
private PropertyInfo Info { get; }
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
public void SetValue(object? self, object? value)
|
public void SetValue(object? self, object? value)
|
||||||
{
|
{
|
||||||
this.Info.SetValue(self, value);
|
this.Info.SetValue(self, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
public T? GetCustomAttribute<T>() where T : Attribute
|
public T? GetCustomAttribute<T>() where T : Attribute
|
||||||
{
|
{
|
||||||
return this.Info.GetCustomAttribute<T>();
|
return this.Info.GetCustomAttribute<T>();
|
||||||
|
|
|
||||||
|
|
@ -335,7 +335,7 @@ namespace Dalamud.Utility
|
||||||
if (exit)
|
if (exit)
|
||||||
Environment.Exit(-1);
|
Environment.Exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Transform byte count to human readable format.
|
/// Transform byte count to human readable format.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue