summary refs log tree commit diff
path: root/crypto/src/asn1/DerVisibleString.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/asn1/DerVisibleString.cs')
-rw-r--r--crypto/src/asn1/DerVisibleString.cs25
1 files changed, 13 insertions, 12 deletions
diff --git a/crypto/src/asn1/DerVisibleString.cs b/crypto/src/asn1/DerVisibleString.cs
index 359370040..77fe54c9a 100644
--- a/crypto/src/asn1/DerVisibleString.cs
+++ b/crypto/src/asn1/DerVisibleString.cs
@@ -28,24 +28,25 @@ namespace Org.BouncyCastle.Asn1
          *
          * @exception ArgumentException if the object cannot be converted.
          */
-        public static DerVisibleString GetInstance(
-            object obj)
+        public static DerVisibleString GetInstance(object obj)
         {
-            if (obj == null || obj is DerVisibleString)
-            {
-                return (DerVisibleString)obj;
-            }
-            else if (obj is IAsn1Convertible)
+            if (obj == null)
+                return null;
+
+            if (obj is DerVisibleString derVisibleString)
+                return derVisibleString;
+
+            if (obj is IAsn1Convertible asn1Convertible)
             {
-                Asn1Object asn1Object = ((IAsn1Convertible)obj).ToAsn1Object();
-                if (asn1Object is DerVisibleString)
-                    return (DerVisibleString)asn1Object;
+                Asn1Object asn1Object = asn1Convertible.ToAsn1Object();
+                if (asn1Object is DerVisibleString converted)
+                    return converted;
             }
-            else if (obj is byte[])
+            else if (obj is byte[] bytes)
             {
                 try
                 {
-                    return (DerVisibleString)Meta.Instance.FromByteArray((byte[])obj);
+                    return (DerVisibleString)Meta.Instance.FromByteArray(bytes);
                 }
                 catch (IOException e)
                 {