System.Security.Util.XMLUtil.GetClassFromElement C# (CSharp) Method

GetClassFromElement() static private method

static private GetClassFromElement ( SecurityElement el, bool ignoreTypeLoadFailures ) : Type
el System.Security.SecurityElement
ignoreTypeLoadFailures bool
return System.Type
        GetClassFromElement (SecurityElement el, bool ignoreTypeLoadFailures)
        {
            String className = el.Attribute( "class" );

            if (className == null)
            {
                if (ignoreTypeLoadFailures)
                    return null;
                else
                    throw new ArgumentException( String.Format( null, Environment.GetResourceString("Argument_InvalidXMLMissingAttr"), "class") );
            }

            if (ignoreTypeLoadFailures)
            {
                try
                {
                    return Type.GetType(className, false, false);               
                }
                catch (SecurityException)
                {
                    return null;
                }
            }
            else
                return Type.GetType(className, true, false);               
        }

Usage Example

        public static CodeGroup CreateCodeGroup(SecurityElement el)
        {
            if (el == null || !el.Tag.Equals("CodeGroup"))
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_WrongElementType"), "<CodeGroup>"));
            }
            string strA;
            int    indexA;
            int    num;

            if (XMLUtil.ParseElementForObjectCreation(el, "System.Security.Policy.", out strA, out indexA, out num))
            {
                switch (num)
                {
                case 12:
                    if (string.Compare(strA, indexA, "NetCodeGroup", 0, num, StringComparison.Ordinal) == 0)
                    {
                        return(new NetCodeGroup());
                    }
                    break;

                case 13:
                    if (string.Compare(strA, indexA, "FileCodeGroup", 0, num, StringComparison.Ordinal) == 0)
                    {
                        return(new FileCodeGroup());
                    }
                    break;

                case 14:
                    if (string.Compare(strA, indexA, "UnionCodeGroup", 0, num, StringComparison.Ordinal) == 0)
                    {
                        return(new UnionCodeGroup());
                    }
                    break;

                default:
                    if (num == 19)
                    {
                        if (string.Compare(strA, indexA, "FirstMatchCodeGroup", 0, num, StringComparison.Ordinal) == 0)
                        {
                            return(new FirstMatchCodeGroup());
                        }
                    }
                    break;
                }
            }
            new ReflectionPermission(ReflectionPermissionFlag.MemberAccess).Assert();
            Type classFromElement = XMLUtil.GetClassFromElement(el, true);

            if (classFromElement == null)
            {
                return(null);
            }
            if (!typeof(CodeGroup).IsAssignableFrom(classFromElement))
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_NotACodeGroupType"));
            }
            return((CodeGroup)Activator.CreateInstance(classFromElement, true));
        }
All Usage Examples Of System.Security.Util.XMLUtil::GetClassFromElement