public override IPermission Union(IPermission other)
        {
            EnvironmentPermission ep = Cast(other);

            if (ep == null)
            {
                return(Copy());
            }

            if (IsUnrestricted() || ep.IsUnrestricted())
            {
                return(new EnvironmentPermission(PermissionState.Unrestricted));
            }

            if (IsEmpty() && ep.IsEmpty())
            {
                return(null);
            }

            EnvironmentPermission result = (EnvironmentPermission)Copy();
            string path = ep.GetPathList(EnvironmentPermissionAccess.Read);

            if (path != null)
            {
                result.AddPathList(EnvironmentPermissionAccess.Read, path);
            }
            path = ep.GetPathList(EnvironmentPermissionAccess.Write);
            if (path != null)
            {
                result.AddPathList(EnvironmentPermissionAccess.Write, path);
            }
            return(result);
        }
        public override IPermission Intersect(IPermission target)
        {
            EnvironmentPermission ep = Cast(target);

            if (ep == null)
            {
                return(null);
            }

            if (IsUnrestricted())
            {
                return(ep.Copy());
            }
            if (ep.IsUnrestricted())
            {
                return(Copy());
            }

            int n = 0;
            EnvironmentPermission result = new EnvironmentPermission(PermissionState.None);
            string readTarget            = ep.GetPathList(EnvironmentPermissionAccess.Read);

            if (readTarget != null)
            {
                string[] targets = readTarget.Split(';');
                foreach (string t in targets)
                {
                    if (readList.Contains(t))
                    {
                        result.AddPathList(EnvironmentPermissionAccess.Read, t);
                        n++;
                    }
                }
            }

            string writeTarget = ep.GetPathList(EnvironmentPermissionAccess.Write);

            if (writeTarget != null)
            {
                string[] targets = writeTarget.Split(';');
                foreach (string t in targets)
                {
                    if (writeList.Contains(t))
                    {
                        result.AddPathList(EnvironmentPermissionAccess.Write, t);
                        n++;
                    }
                }
            }
            return((n > 0) ? result : null);
        }
        private EnvironmentPermission Cast(IPermission target)
        {
            if (target == null)
            {
                return(null);
            }

            EnvironmentPermission ep = (target as EnvironmentPermission);

            if (ep == null)
            {
                ThrowInvalidPermission(target, typeof(EnvironmentPermission));
            }

            return(ep);
        }
        public override IPermission Copy()
        {
            EnvironmentPermission ep = new EnvironmentPermission(_state);
            string path = GetPathList(EnvironmentPermissionAccess.Read);

            if (path != null)
            {
                ep.SetPathList(EnvironmentPermissionAccess.Read, path);
            }
            path = GetPathList(EnvironmentPermissionAccess.Write);
            if (path != null)
            {
                ep.SetPathList(EnvironmentPermissionAccess.Write, path);
            }
            return(ep);
        }
        public override bool IsSubsetOf(IPermission target)
        {
            EnvironmentPermission ep = Cast(target);

            if (ep == null)
            {
                return(false);
            }

            if (IsUnrestricted())
            {
                return(ep.IsUnrestricted());
            }
            else if (ep.IsUnrestricted())
            {
                return(true);
            }

            foreach (string s in readList)
            {
                if (!ep.readList.Contains(s))
                {
                    return(false);
                }
            }

            foreach (string s in writeList)
            {
                if (!ep.writeList.Contains(s))
                {
                    return(false);
                }
            }

            return(true);
        }