From ce64bf9d9aa703c17a3772918d438b8865cf7675 Mon Sep 17 00:00:00 2001 From: antiduh Date: Tue, 1 Jul 2014 18:40:35 +0000 Subject: [PATCH] Simplified object lifecycle verification. --- NSspi/Credentials/Credential.cs | 40 +++++++++++++-------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/NSspi/Credentials/Credential.cs b/NSspi/Credentials/Credential.cs index e2226ec..5067ab9 100644 --- a/NSspi/Credentials/Credential.cs +++ b/NSspi/Credentials/Credential.cs @@ -38,10 +38,7 @@ namespace NSspi.Credentials { get { - if( this.disposed ) - { - throw new ObjectDisposedException( base.GetType().Name ); - } + CheckLifecycle(); return this.securityPackage; } @@ -56,10 +53,7 @@ namespace NSspi.Credentials string name = null; bool gotRef = false; - if( this.disposed ) - { - throw new ObjectDisposedException( "Credential" ); - } + CheckLifecycle(); status = SecurityStatus.InternalError; carrier = new QueryNameAttribCarrier(); @@ -117,21 +111,15 @@ namespace NSspi.Credentials { get { - if( this.disposed ) - { - throw new ObjectDisposedException( "Credential" ); - } + CheckLifecycle(); return this.expiry; } protected set { - if( this.disposed ) - { - throw new ObjectDisposedException( "Credential" ); - } - + CheckLifecycle(); + this.expiry = value; } } @@ -140,20 +128,14 @@ namespace NSspi.Credentials { get { - if( this.disposed ) - { - throw new ObjectDisposedException( "Credential" ); - } + CheckLifecycle(); return this.safeCredHandle; } protected set { - if( this.disposed ) - { - throw new ObjectDisposedException( "Credential" ); - } + CheckLifecycle(); this.safeCredHandle = value; } @@ -177,5 +159,13 @@ namespace NSspi.Credentials this.disposed = true; } } + + private void CheckLifecycle() + { + if( this.disposed ) + { + throw new ObjectDisposedException( "Credential" ); + } + } } }