Elegant way to check if .Net object is empty
<p>I have an <code>X509Certificate2</code> property, and I want to check in the set section, if the value that was set is empty.
When I try to access to any <code>X509Certificate2</code> property such as publickey, I got this exception:
<code>System.Security.Cryptography.CryptographicException</code> occurred in <code>mscorlib.dll</code>.</p>

<p>sure, I can write something such this example:</p>

<pre><code>private static X509Certificate2 _certificate;

    public X509Certificate2 Certificate
    {
        get
        {
            return _certificate;
        }
        set
        {
            try
            {
                if (value.PublicKey != null)
                    _certificate = value;
            }
            catch(CryptographicException)
            {
                _certificate = null;
            }

        }
    } 
</code></pre>

<p>but I want a nicer way, does any one have an idea?</p>
