object IDynamicParameters.GetDynamicParameters()
        {
            bool access_mandatory = !RawAccess.HasValue;

            _dict = new RuntimeDefinedParameterDictionary();
            if (NtSecurity.IsCallbackAceType(Type) || Type == AceType.AccessFilter)
            {
                _dict.AddDynamicParameter("Condition", typeof(string), false);
            }

            if (NtSecurity.IsObjectAceType(Type))
            {
                _dict.AddDynamicParameter("ObjectType", typeof(Guid?), false);
                _dict.AddDynamicParameter("InheritedObjectType", typeof(Guid?), false);
            }

            if (Type == AceType.AllowedCompound)
            {
                _dict.AddDynamicParameter("ServerSid", typeof(Sid), true);
            }

            if (Type == AceType.ResourceAttribute)
            {
                _dict.AddDynamicParameter("SecurityAttribute", typeof(ClaimSecurityAttribute), true);
                access_mandatory = false;
            }

            Type access_type = SecurityDescriptor?.AccessRightsType ?? typeof(GenericAccessRights);

            if (Type == AceType.MandatoryLabel)
            {
                access_type = typeof(MandatoryLabelPolicy);
            }
            _dict.AddDynamicParameter("Access", access_type, access_mandatory, 2);

            return(_dict);
        }
        /// <summary>
        /// Process Record.
        /// </summary>
        protected override void ProcessRecord()
        {
            if (!_dict.GetValue("Access", out Enum access))
            {
                if (!RawAccess.HasValue && RequiresAccess(Type))
                {
                    throw new ArgumentException("Invalid access value.");
                }
                else
                {
                    access = GenericAccessRights.None;
                }
            }

            _dict.GetValue("Condition", out string condition);
            _dict.GetValue("ObjectType", out Guid? object_type);
            _dict.GetValue("InheritedObjectType", out Guid? inherited_object_type);
            _dict.GetValue("ServerSid", out Sid server_sid);
            _dict.GetValue("SecurityAttribute", out ClaimSecurityAttribute security_attribute);

            Acl acl;

            if (NtSecurity.IsSystemAceType(Type))
            {
                if (SecurityDescriptor.Sacl == null)
                {
                    SecurityDescriptor.Sacl = new Acl();
                }
                acl = SecurityDescriptor.Sacl;
            }
            else
            {
                if (SecurityDescriptor.Dacl == null)
                {
                    SecurityDescriptor.Dacl = new Acl();
                }
                acl = SecurityDescriptor.Dacl;
            }

            AccessMask mask = access;

            if (RawAccess.HasValue)
            {
                mask |= RawAccess.Value;
            }

            if (MapGeneric)
            {
                NtType type = SecurityDescriptor.NtType;
                if (type == null)
                {
                    WriteWarning("No NtType specified in security descriptor. Defaulting to File.");
                    type = NtType.GetTypeByType <NtFile>();
                }
                mask = type.MapGenericRights(mask);
            }

            Ace ace = new Ace(Type, Flags, mask, GetSid());

            if ((NtSecurity.IsCallbackAceType(Type) || Type == AceType.AccessFilter) && !string.IsNullOrWhiteSpace(condition))
            {
                ace.Condition = condition;
            }
            if (NtSecurity.IsObjectAceType(Type))
            {
                ace.ObjectType          = object_type;
                ace.InheritedObjectType = inherited_object_type;
            }
            if (Type == AceType.AllowedCompound)
            {
                ace.ServerSid = server_sid;
            }
            if (Type == AceType.ResourceAttribute)
            {
                ace.ResourceAttribute = security_attribute;
            }

            acl.Add(ace);
            if (PassThru)
            {
                WriteObject(ace);
            }
        }