53 lines
1.7 KiB
C#
53 lines
1.7 KiB
C#
using System;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
using System.Drawing;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace Foodsoft.Alpm
|
|
{
|
|
public class Depend : IEquatable<Depend>
|
|
{
|
|
public enum ModType
|
|
{
|
|
Any = 1,
|
|
Equal,
|
|
GreaterThanOrEqual,
|
|
LessThanOrEqual,
|
|
GreaterThan,
|
|
LessThan
|
|
}
|
|
|
|
public string Name { get; }
|
|
public string Version { get; }
|
|
public string Description { get; }
|
|
public ulong NameHash { get; }
|
|
public ModType Mod { get; }
|
|
|
|
public override bool Equals(object? obj) => (obj is Depend other) && this.Equals(other);
|
|
|
|
public bool Equals(Depend? other) => !ReferenceEquals(other, null) && ReferenceEquals(this, other) &&
|
|
Name == other.Name && Version == other.Version && Mod == other.Mod;
|
|
|
|
public override int GetHashCode() => HashCode.Combine(Name, Version, (int) Mod);
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
private readonly unsafe struct NativeDepend
|
|
{
|
|
internal readonly sbyte* name;
|
|
internal readonly sbyte* version;
|
|
internal readonly sbyte* description;
|
|
internal readonly ulong name_hash;
|
|
internal readonly Depend.ModType mod;
|
|
}
|
|
|
|
internal unsafe Depend(IntPtr ptr)
|
|
{
|
|
var native = (NativeDepend*) ptr;
|
|
Name = new string(native->name);
|
|
Version = new string(native->version);
|
|
Description = new string(native->description);
|
|
NameHash = native->name_hash;
|
|
Mod = native->mod;
|
|
}
|
|
}
|
|
} |