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