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