/// <summary>Canonicalizes the specified Access Control List.</summary> /// <param name="acl">The Access Control List.</param> public static void Canonicalize(this RawAcl acl) { if (acl == null) { throw new ArgumentNullException(nameof(acl)); } // Extract aces to list var aces = new System.Collections.Generic.List <GenericAce>(acl.Cast <GenericAce>()); // Sort aces based on canonical order aces.Sort((a, b) => System.Collections.Generic.Comparer <byte> .Default.Compare(GetComparisonValue(a), GetComparisonValue(b))); // Add sorted aces back to ACL while (acl.Count > 0) { acl.RemoveAce(0); } var aceIndex = 0; aces.ForEach(ace => acl.InsertAce(aceIndex++, ace)); }