internal Credential GetCredential() { if (!IsInvalid) { // Get the Credential from the mem location NativeCredential nativeCredential = (NativeCredential)Marshal.PtrToStructure(handle, typeof(NativeCredential)); // Create a managed Credential type and fill it with data from the native counterpart. Credential credential = nativeCredential.ToCredential(); return(credential); } else { throw new InvalidOperationException("Invalid CriticalHandle!"); } }
public Credential[] GetCredentials(int count) { if (IsInvalid) { throw new InvalidOperationException("Invalid CriticalHandle!"); } Credential[] credentials = new Credential[count]; for (int inx = 0; inx < count; inx++) { IntPtr pCred = Marshal.ReadIntPtr(handle, inx * IntPtr.Size); NativeCredential nativeCredential = (NativeCredential)Marshal.PtrToStructure(pCred, typeof(NativeCredential)); Credential credential = nativeCredential.ToCredential(); credentials[inx] = credential; } return(credentials); }
public void ToCredentialTest() { NativeCredential nativeCredential = new NativeCredential() { AttributeCount = 0, Attributes = new IntPtr(0), Comment = new IntPtr(0), CredentialBlob = new IntPtr(0), CredentialBlobSize = 0, Flags = 0, LastWritten = new System.Runtime.InteropServices.ComTypes.FILETIME(), Persist = 0, TargetAlias = new IntPtr(0), TargetName = new IntPtr(0), Type = CredType.Generic, UserName = new IntPtr(0) }; Credential credential = nativeCredential.ToCredential(); Assert.IsNotNull(credential); Assert.IsInstanceOfType(credential, typeof(Credential)); }