docs: anna sig stuff helpers

This commit is contained in:
goat 2022-01-26 03:54:07 +01:00
parent 89240c0e1e
commit 4dc0096ff3
No known key found for this signature in database
GPG key ID: 7773BB5B43BA52E5
8 changed files with 69 additions and 5 deletions

View file

@ -6,12 +6,30 @@ using System.Reflection;
namespace Dalamud.Utility.Signatures
{
/// <summary>
/// Class providing info about field, property or parameter nullability.
/// </summary>
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);
/// <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);
/// <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);
private static bool IsNullableHelper(Type memberType, MemberInfo? declaringType, IEnumerable<CustomAttributeData> customAttributes)

View file

@ -1,4 +1,6 @@
namespace Dalamud.Utility.Signatures
using Dalamud.Game;
namespace Dalamud.Utility.Signatures
{
/// <summary>
/// The type of scan to perform with a signature.
@ -13,7 +15,7 @@
/// <summary>
/// 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>
StaticAddress,
}

View file

@ -61,7 +61,7 @@ namespace Dalamud.Utility.Signatures
/// <summary>
/// Initializes a new instance of the <see cref="SignatureAttribute"/> class.
/// </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)
{
this.Signature = signature;

View file

@ -12,6 +12,8 @@ namespace Dalamud.Utility.Signatures
/// </summary>
/// <param name="message">Message.</param>
internal SignatureException(string message)
: base(message) { }
: base(message)
{
}
}
}

View file

@ -3,26 +3,38 @@ using System.Reflection;
namespace Dalamud.Utility.Signatures.Wrappers
{
/// <summary>
/// Class providing information about a field.
/// </summary>
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)
{
this.Info = info;
}
/// <inheritdoc/>
public string Name => this.Info.Name;
/// <inheritdoc/>
public Type ActualType => this.Info.FieldType;
/// <inheritdoc/>
public bool IsNullable => NullabilityUtil.IsNullable(this.Info);
private FieldInfo Info { get; }
/// <inheritdoc/>
public void SetValue(object? self, object? value)
{
this.Info.SetValue(self, value);
}
/// <inheritdoc/>
public T? GetCustomAttribute<T>() where T : Attribute
{
return this.Info.GetCustomAttribute<T>();

View file

@ -2,16 +2,38 @@ using System;
namespace Dalamud.Utility.Signatures.Wrappers
{
/// <summary>
/// Interface providing information about a field or a property.
/// </summary>
internal interface IFieldOrPropertyInfo
{
/// <summary>
/// Gets the name of the field or property.
/// </summary>
string Name { get; }
/// <summary>
/// Gets the actual type of the field or property.
/// </summary>
Type ActualType { get; }
/// <summary>
/// Gets a value indicating whether or not the field or property is nullable.
/// </summary>
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);
/// <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;
}
}

View file

@ -3,6 +3,9 @@ using System.Reflection;
namespace Dalamud.Utility.Signatures.Wrappers
{
/// <summary>
/// Class providing information about a property.
/// </summary>
internal sealed class PropertyInfoWrapper : IFieldOrPropertyInfo
{
/// <summary>
@ -14,19 +17,24 @@ namespace Dalamud.Utility.Signatures.Wrappers
this.Info = info;
}
/// <inheritdoc/>
public string Name => this.Info.Name;
/// <inheritdoc/>
public Type ActualType => this.Info.PropertyType;
/// <inheritdoc/>
public bool IsNullable => NullabilityUtil.IsNullable(this.Info);
private PropertyInfo Info { get; }
/// <inheritdoc/>
public void SetValue(object? self, object? value)
{
this.Info.SetValue(self, value);
}
/// <inheritdoc/>
public T? GetCustomAttribute<T>() where T : Attribute
{
return this.Info.GetCustomAttribute<T>();

View file

@ -335,7 +335,7 @@ namespace Dalamud.Utility
if (exit)
Environment.Exit(-1);
}
/// <summary>
/// Transform byte count to human readable format.
/// </summary>