public static FilePermissionSet FromString(string permissions)
        {
            var set = new FilePermissionSet();

            permissions = permissions?.Trim() ?? "---";

            if (permissions.Length != 3)
            {
                throw new ArgumentException("Permission set must be 3 characters long");
            }

            if (string.IsNullOrWhiteSpace(permissions))
            {
                return(set);
            }

            set.NumericValue = permissions
                               .ToLower()
                               .ToCharArray()
                               .Distinct()
                               .Sum(y =>
            {
                switch (y)
                {
                case 'r':
                    set._charVal[0] = 'r';
                    set.CanRead     = true;
                    return(4);

                case 'w':
                    set._charVal[1] = 'w';
                    set.CanWrite    = true;
                    return(2);

                case 'x':
                    set._charVal[2] = 'x';
                    set.CanExecute  = true;
                    return(1);

                default: return(0);
                }
            });

            return(set);
        }
        public static FilePermissionCollection FromString(string permissions)
        {
            permissions = permissions?.Trim() ?? "---------";

            var fp = new FilePermissionCollection();

            if (permissions.Length != 9)
            {
                throw new ArgumentException("Permission string must be 9 characters long");
            }

            if (string.IsNullOrWhiteSpace(permissions))
            {
                return(new FilePermissionCollection());
            }

            fp.User  = FilePermissionSet.FromString(permissions.Substring(0, 3));
            fp.Group = FilePermissionSet.FromString(permissions.Substring(3, 3));
            fp.Other = FilePermissionSet.FromString(permissions.Substring(6, 3));

            return(fp);
        }
 internal FilePermissionCollection()
 {
     User  = new FilePermissionSet();
     Group = new FilePermissionSet();
     Other = new FilePermissionSet();
 }