private void AutoDetectSecretKind()

in Vault/Explorer/SecretDialog.cs [204:244]


        private void AutoDetectSecretKind()
        {
            SecretKind defaultSecretKind = TryGetDefaultSecretKind(); // Default is the first one which is always Custom
            SecretKind autoDetectSecretKind = new SecretKind(defaultSecretKind.Alias); 
            TagItem currentSKTag = PropertyObject.Tags.GetOrNull(new TagItem(Consts.SecretKindKey, ""));
            bool shouldAddNew = true;

            // Read the CustomTags and determine the SecretKind
            foreach (SecretKind sk in uxMenuSecretKind.Items) // Auto detect 'last' secret kind based on the name only
            {

                if (currentSKTag == null)
                {
                    autoDetectSecretKind = defaultSecretKind;
                    shouldAddNew = false;
                    break;
                }

                // If the current Secret Kind is in the list of menu items,
                if (currentSKTag.Value == sk.Alias)
                {
                    autoDetectSecretKind = sk;
                    shouldAddNew = false;
                    break;
                }
            }
            if (shouldAddNew)
            {
                autoDetectSecretKind = new SecretKind(currentSKTag.Value);
                uxMenuSecretKind.Items.Add(autoDetectSecretKind);
            }

            // Apply last found secret kind, only when both Content Type and SecretKind are certificate or both not, otherwise fallback to Custom (the first one)
            if ((!PropertyObject.ContentType.IsCertificate() || !autoDetectSecretKind.IsCertificate) &&
                (PropertyObject.ContentType.IsCertificate() || autoDetectSecretKind.IsCertificate))
            {
                autoDetectSecretKind = TryGetDefaultSecretKind();
            }
            _certificateObj = PropertyObject.ContentType.IsCertificate() ? CertificateValueObject.FromValue(uxTextBoxValue.Text) : null;
            autoDetectSecretKind?.PerformClick();
        }