@@ -872,169 +872,8 @@ private static SafePeerList<T> PeerEnum<T>(Func<SafeHPEERENUM> setup) where T :
872872 return hEnum . GetItems < T > ( ) ;
873873 }
874874
875- /// <summary>Provides a handle to a peer enumeration.</summary>
876- [ StructLayout ( LayoutKind . Sequential ) ]
877- public struct HPEERENUM : IHandle
875+ public partial class SafeHPEERENUM
878876 {
879- private IntPtr handle ;
880-
881- /// <summary>Initializes a new instance of the <see cref="HPEERENUM"/> struct.</summary>
882- /// <param name="preexistingHandle">An <see cref="IntPtr"/> object that represents the pre-existing handle to use.</param>
883- public HPEERENUM ( IntPtr preexistingHandle ) => handle = preexistingHandle ;
884-
885- /// <summary>Returns an invalid handle by instantiating a <see cref="HPEERENUM"/> object with <see cref="IntPtr.Zero"/>.</summary>
886- public static HPEERENUM NULL => new ( IntPtr . Zero ) ;
887-
888- /// <summary>Gets a value indicating whether this instance is a null handle.</summary>
889- public bool IsNull => handle == IntPtr . Zero ;
890-
891- /// <summary>Performs an explicit conversion from <see cref="HPEERENUM"/> to <see cref="IntPtr"/>.</summary>
892- /// <param name="h">The handle.</param>
893- /// <returns>The result of the conversion.</returns>
894- public static explicit operator IntPtr ( HPEERENUM h ) => h . handle ;
895-
896- /// <summary>Performs an implicit conversion from <see cref="IntPtr"/> to <see cref="HPEERENUM"/>.</summary>
897- /// <param name="h">The pointer to a handle.</param>
898- /// <returns>The result of the conversion.</returns>
899- public static implicit operator HPEERENUM ( IntPtr h ) => new ( h ) ;
900-
901- /// <summary>Implements the operator !=.</summary>
902- /// <param name="h1">The first handle.</param>
903- /// <param name="h2">The second handle.</param>
904- /// <returns>The result of the operator.</returns>
905- public static bool operator != ( HPEERENUM h1 , HPEERENUM h2 ) => ! ( h1 == h2 ) ;
906-
907- /// <summary>Implements the operator ==.</summary>
908- /// <param name="h1">The first handle.</param>
909- /// <param name="h2">The second handle.</param>
910- /// <returns>The result of the operator.</returns>
911- public static bool operator == ( HPEERENUM h1 , HPEERENUM h2 ) => h1 . Equals ( h2 ) ;
912-
913- /// <inheritdoc/>
914- public override bool Equals ( object ? obj ) => obj is HPEERENUM h && handle == h . handle ;
915-
916- /// <inheritdoc/>
917- public override int GetHashCode ( ) => handle . GetHashCode ( ) ;
918-
919- /// <inheritdoc/>
920- public IntPtr DangerousGetHandle ( ) => handle ;
921- }
922-
923- /// <summary>Provides a handle to the PNRP registration for the calling peer node.</summary>
924- [ StructLayout ( LayoutKind . Sequential ) ]
925- public struct HREGISTRATION : IHandle
926- {
927- private IntPtr handle ;
928-
929- /// <summary>Initializes a new instance of the <see cref="HREGISTRATION"/> struct.</summary>
930- /// <param name="preexistingHandle">An <see cref="IntPtr"/> object that represents the pre-existing handle to use.</param>
931- public HREGISTRATION ( IntPtr preexistingHandle ) => handle = preexistingHandle ;
932-
933- /// <summary>Returns an invalid handle by instantiating a <see cref="HREGISTRATION"/> object with <see cref="IntPtr.Zero"/>.</summary>
934- public static HREGISTRATION NULL => new ( IntPtr . Zero ) ;
935-
936- /// <summary>Gets a value indicating whether this instance is a null handle.</summary>
937- public bool IsNull => handle == IntPtr . Zero ;
938-
939- /// <summary>Performs an explicit conversion from <see cref="HREGISTRATION"/> to <see cref="IntPtr"/>.</summary>
940- /// <param name="h">The handle.</param>
941- /// <returns>The result of the conversion.</returns>
942- public static explicit operator IntPtr ( HREGISTRATION h ) => h . handle ;
943-
944- /// <summary>Performs an implicit conversion from <see cref="IntPtr"/> to <see cref="HREGISTRATION"/>.</summary>
945- /// <param name="h">The pointer to a handle.</param>
946- /// <returns>The result of the conversion.</returns>
947- public static implicit operator HREGISTRATION ( IntPtr h ) => new ( h ) ;
948-
949- /// <summary>Implements the operator !=.</summary>
950- /// <param name="h1">The first handle.</param>
951- /// <param name="h2">The second handle.</param>
952- /// <returns>The result of the operator.</returns>
953- public static bool operator != ( HREGISTRATION h1 , HREGISTRATION h2 ) => ! ( h1 == h2 ) ;
954-
955- /// <summary>Implements the operator ==.</summary>
956- /// <param name="h1">The first handle.</param>
957- /// <param name="h2">The second handle.</param>
958- /// <returns>The result of the operator.</returns>
959- public static bool operator == ( HREGISTRATION h1 , HREGISTRATION h2 ) => h1 . Equals ( h2 ) ;
960-
961- /// <inheritdoc/>
962- public override bool Equals ( object ? obj ) => obj is HREGISTRATION h && handle == h . handle ;
963-
964- /// <inheritdoc/>
965- public override int GetHashCode ( ) => handle . GetHashCode ( ) ;
966-
967- /// <inheritdoc/>
968- public IntPtr DangerousGetHandle ( ) => handle ;
969- }
970-
971- /// <summary>Provides a handle to an asynchronous peer name resolution operation.</summary>
972- [ StructLayout ( LayoutKind . Sequential ) ]
973- public struct HRESOLUTION : IHandle
974- {
975- private IntPtr handle ;
976-
977- /// <summary>Initializes a new instance of the <see cref="HRESOLUTION"/> struct.</summary>
978- /// <param name="preexistingHandle">An <see cref="IntPtr"/> object that represents the pre-existing handle to use.</param>
979- public HRESOLUTION ( IntPtr preexistingHandle ) => handle = preexistingHandle ;
980-
981- /// <summary>Returns an invalid handle by instantiating a <see cref="HRESOLUTION"/> object with <see cref="IntPtr.Zero"/>.</summary>
982- public static HRESOLUTION NULL => new ( IntPtr . Zero ) ;
983-
984- /// <summary>Gets a value indicating whether this instance is a null handle.</summary>
985- public bool IsNull => handle == IntPtr . Zero ;
986-
987- /// <summary>Performs an explicit conversion from <see cref="HRESOLUTION"/> to <see cref="IntPtr"/>.</summary>
988- /// <param name="h">The handle.</param>
989- /// <returns>The result of the conversion.</returns>
990- public static explicit operator IntPtr ( HRESOLUTION h ) => h . handle ;
991-
992- /// <summary>Performs an implicit conversion from <see cref="IntPtr"/> to <see cref="HRESOLUTION"/>.</summary>
993- /// <param name="h">The pointer to a handle.</param>
994- /// <returns>The result of the conversion.</returns>
995- public static implicit operator HRESOLUTION ( IntPtr h ) => new ( h ) ;
996-
997- /// <summary>Implements the operator !=.</summary>
998- /// <param name="h1">The first handle.</param>
999- /// <param name="h2">The second handle.</param>
1000- /// <returns>The result of the operator.</returns>
1001- public static bool operator != ( HRESOLUTION h1 , HRESOLUTION h2 ) => ! ( h1 == h2 ) ;
1002-
1003- /// <summary>Implements the operator ==.</summary>
1004- /// <param name="h1">The first handle.</param>
1005- /// <param name="h2">The second handle.</param>
1006- /// <returns>The result of the operator.</returns>
1007- public static bool operator == ( HRESOLUTION h1 , HRESOLUTION h2 ) => h1 . Equals ( h2 ) ;
1008-
1009- /// <inheritdoc/>
1010- public override bool Equals ( object ? obj ) => obj is HRESOLUTION h && handle == h . handle ;
1011-
1012- /// <inheritdoc/>
1013- public override int GetHashCode ( ) => handle . GetHashCode ( ) ;
1014-
1015- /// <inheritdoc/>
1016- public IntPtr DangerousGetHandle ( ) => handle ;
1017- }
1018-
1019- /// <summary>Provides a <see cref="SafeHandle"/> for <see cref="HPEERENUM"/> that is disposed using <see cref="PeerEndEnumeration"/>.</summary>
1020- /// <seealso cref="Vanara.PInvoke.SafeHANDLE"/>
1021- public class SafeHPEERENUM : SafeHANDLE
1022- {
1023- /// <summary>Initializes a new instance of the <see cref="SafeHPEERENUM"/> class and assigns an existing handle.</summary>
1024- /// <param name="preexistingHandle">An <see cref="IntPtr"/> object that represents the pre-existing handle to use.</param>
1025- /// <param name="ownsHandle">
1026- /// <see langword="true"/> to reliably release the handle during the finalization phase; otherwise, <see langword="false"/> (not recommended).
1027- /// </param>
1028- public SafeHPEERENUM ( IntPtr preexistingHandle , bool ownsHandle = true ) : base ( preexistingHandle , ownsHandle ) { }
1029-
1030- /// <summary>Initializes a new instance of the <see cref="SafeHPEERENUM"/> class.</summary>
1031- private SafeHPEERENUM ( ) : base ( ) { }
1032-
1033- /// <summary>Performs an implicit conversion from <see cref="SafeHPEERENUM"/> to <see cref="HPEERENUM"/>.</summary>
1034- /// <param name="h">The safe handle instance.</param>
1035- /// <returns>The result of the conversion.</returns>
1036- public static implicit operator HPEERENUM ( SafeHPEERENUM h ) => h . handle ;
1037-
1038877 /// <summary>Gets the enumerated items.</summary>
1039878 /// <typeparam name="T">The type of the structure that can be enumerated.</typeparam>
1040879 /// <returns>A <see cref="SafePeerList{T}"/> that exposes the enumeration.</returns>
@@ -1051,32 +890,17 @@ public SafePeerList<T> GetItems<T>() where T : struct
1051890 else
1052891 return new SafePeerList < T > ( ) ;
1053892 }
1054-
1055- /// <inheritdoc/>
1056- protected override bool InternalReleaseHandle ( ) => PeerEndEnumeration ( handle ) . Succeeded ;
1057893 }
1058894
1059895 /// <summary>Provides a <see cref="SafeHandle"/> for data that is disposed using <see cref="PeerFreeData"/>.</summary>
1060- public class SafePeerData : SafeHANDLE
896+ [ AutoSafeHandle ( "{ PeerFreeData(handle); return true; }" ) ]
897+ public partial class SafePeerData
1061898 {
1062- /// <summary>Initializes a new instance of the <see cref="SafePeerData"/> class.</summary>
1063- protected internal SafePeerData ( ) : base ( ) { }
1064-
1065- /// <summary>Initializes a new instance of the <see cref="SafePeerData"/> class.</summary>
1066- /// <param name="preexistingHandle">An <see cref="T:System.IntPtr"/> object that represents the pre-existing handle to use.</param>
1067- /// <param name="ownsHandle">
1068- /// <see langword="true"/> to reliably release the handle during the finalization phase; otherwise, <see langword="false"/> (not recommended).
1069- /// </param>
1070- protected SafePeerData ( IntPtr preexistingHandle , bool ownsHandle = true ) : base ( preexistingHandle , ownsHandle ) { }
1071-
1072899 /// <summary>
1073900 /// Marshals data from an unmanaged block of memory to a newly allocated managed object of the type specified by a generic type parameter.
1074901 /// </summary>
1075902 /// <typeparam name="T">The type of the object to which the data is to be copied. This must be a structure.</typeparam>
1076903 public T ToStructure < T > ( ) where T : struct => handle . ToStructure < T > ( ) ;
1077-
1078- /// <inheritdoc/>
1079- protected override bool InternalReleaseHandle ( ) { PeerFreeData ( handle ) ; return true ; }
1080904 }
1081905
1082906 /// <summary>Provides a <see cref="SafeHandle"/> for an array that is disposed using <see cref="PeerFreeData"/>.</summary>
0 commit comments