Example #1
0
        public virtual void FromXml(SecurityElement et)
        {
            if (et == null)
            {
                throw new ArgumentNullException("et");
            }
            if (et.Tag != tagName)
            {
                string msg = String.Format("Invalid tag {0} expected {1}", et.Tag, tagName);
                throw new ArgumentException(msg, "et");
            }

            list.Clear();

            if (CodeAccessPermission.IsUnrestricted(et))
            {
                state = PermissionState.Unrestricted;
#if NET_2_0
                // no need to continue for an unrestricted permission
                // because identity permissions now "supports" unrestricted
                return;
#endif
            }
            else
            {
                state = PermissionState.None;
            }

            if (et.Children != null)
            {
                foreach (SecurityElement se in et.Children)
                {
                    string className = se.Attribute("class");
                    if (className == null)
                    {
                        throw new ArgumentException(Locale.GetText(
                                                        "No permission class is specified."));
                    }
                    if (Resolver != null)
                    {
                                                #if !DISABLE_SECURITY
                        // policy class names do not have to be fully qualified
                        className = Resolver.ResolveClassName(className);
                                                #else
                        className = null;
                                                #endif
                    }

                    list.Add(PermissionBuilder.Create(className, se));
                }
            }
        }