Exemple #1
0
        public override IPermission Union(IPermission target)
        {
#if (debug)
            Console.WriteLine("************* Entering Union *********************");
#endif
            if (target == null)
            {
                return(this);
            }
#if (debug)
            Console.WriteLine("This is = " + (( NameIdPermission)this).Name);
            Console.WriteLine("Target is " + (( NameIdPermission)target).m_Name);
#endif
            if (!VerifyType(target))
            {
                throw new ArgumentException(String.Format("Argument_WrongType", this.GetType().FullName));
            }

            NameIdPermission operand = ( NameIdPermission)target;

            if (operand.IsSubsetOf(this))
            {
                return(this.Copy());
            }
            else if (this.IsSubsetOf(operand))
            {
                return(operand.Copy());
            }
            else
            {
                return(null);
            }
        }
Exemple #2
0
        public override bool IsSubsetOf(IPermission target)
        {
#if (debug)
            Console.WriteLine("************* Entering IsSubsetOf *********************");
#endif
            if (target == null)
            {
                Console.WriteLine("IsSubsetOf: target == null");
                return(false);
            }
#if (debug)
            Console.WriteLine("This is = " + (( NameIdPermission)this).Name);
            Console.WriteLine("Target is " + (( NameIdPermission)target).m_Name);
#endif
            try
            {
                NameIdPermission operand = ( NameIdPermission)target;

                // The following check for unrestricted permission is only included as an example for
                // permissions that allow the unrestricted state. It is of no value for this permission.
                if (true == operand.m_Unrestricted)
                {
                    return(true);
                }
                else if (true == this.m_Unrestricted)
                {
                    return(false);
                }

                if (this.m_Name != null)
                {
                    if (operand.m_Name == null)
                    {
                        return(false);
                    }

                    if (this.m_Name == "")
                    {
                        return(true);
                    }
                }

                if (this.m_Name.Equals(operand.m_Name))
                {
                    return(true);
                }
                else
                {
                    // Check for wild card character '*'.
                    int i = operand.m_Name.LastIndexOf("*");

                    if (i > 0)
                    {
                        string prefix = operand.m_Name.Substring(0, i);

                        if (this.m_Name.StartsWith(prefix))
                        {
                            return(true);
                        }
                    }
                }

                return(false);
            }
            catch (InvalidCastException)
            {
                throw new ArgumentException(String.Format("Argument_WrongType", this.GetType().FullName));
            }
        }
Exemple #3
0
		static void Main(string[] args)
		{
			NameIdPermission nameIdPermission = new NameIdPermission("Donal");
			IPermission otherPermission = nameIdPermission.Copy();

			nameIdPermission.IsSubsetOf(otherPermission);
			nameIdPermission.Intersect(otherPermission);
			nameIdPermission.Union(otherPermission);

			Console.WriteLine(nameIdPermission.ToXml());

			Console.Read();
		}