Added PIDL conversion to byte[]

pull/180/head
dahall 2020-10-26 18:24:12 -06:00
parent c4e2a15ba0
commit 2473914e7d
1 changed files with 8 additions and 0 deletions

View File

@ -29,6 +29,10 @@ namespace Vanara.PInvoke
/// <param name="path">A string that contains the path.</param>
public PIDL(string path) : this(IntILCreateFromPath(path)) { }
/// <summary>Initializes a new instance of the <see cref="PIDL"/> class from an array of bytes.</summary>
/// <param name="bytes">The bytes.</param>
public PIDL(byte[] bytes) : this() { using var p = new PinnedObject(bytes); SetHandle(IntILClone(p)); }
/// <summary>Initializes a new instance of the <see cref="PIDL"/> class.</summary>
internal PIDL() : base(Free) { }
@ -126,6 +130,10 @@ namespace Vanara.PInvoke
/// <returns>true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.</returns>
public bool Equals(PIDL other) => ReferenceEquals(this, other) || Equals(other?.handle ?? IntPtr.Zero);
/// <summary>Gets the ID list as an array of bytes.</summary>
/// <returns>An array of bytes representing the ID list.</returns>
public byte[] GetBytes() => handle.ToArray<byte>((int)Size);
/// <summary>Returns an enumerator that iterates through the collection.</summary>
/// <returns>A <see cref="T:System.Collections.Generic.IEnumerator{PIDL}"/> that can be used to iterate through the collection.</returns>
public IEnumerator<PIDL> GetEnumerator() => new InternalEnumerator(handle);