CreateCodeGroup (SecurityElement el)
{
if (el == null || !el.Tag.Equals("CodeGroup"))
throw new ArgumentException( String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString( "Argument_WrongElementType" ), "<CodeGroup>" ) ) ;
String className;
int classNameLength;
int classNameStart;
if (!ParseElementForObjectCreation( el,
BuiltInCodeGroup,
out className,
out classNameStart,
out classNameLength ))
{
goto USEREFLECTION;
}
switch (classNameLength)
{
case 12:
// NetCodeGroup
if (String.Compare(className, classNameStart, "NetCodeGroup", 0, classNameLength, StringComparison.Ordinal) == 0)
return new NetCodeGroup();
else
goto USEREFLECTION;
case 13:
// FileCodeGroup
if (String.Compare(className, classNameStart, "FileCodeGroup", 0, classNameLength, StringComparison.Ordinal) == 0)
return new FileCodeGroup();
else
goto USEREFLECTION;
case 14:
// UnionCodeGroup
if (String.Compare(className, classNameStart, "UnionCodeGroup", 0, classNameLength, StringComparison.Ordinal) == 0)
return new UnionCodeGroup();
else
goto USEREFLECTION;
case 19:
// FirstMatchCodeGroup
if (String.Compare(className, classNameStart, "FirstMatchCodeGroup", 0, classNameLength, StringComparison.Ordinal) == 0)
return new FirstMatchCodeGroup();
else
goto USEREFLECTION;
default:
goto USEREFLECTION;
}
USEREFLECTION:
Type groupClass = null;
CodeGroup group = null;
new ReflectionPermission(ReflectionPermissionFlag.MemberAccess).Assert();
groupClass = GetClassFromElement(el, true);
if (groupClass == null)
return null;
if (!(typeof(CodeGroup).IsAssignableFrom(groupClass)))
throw new ArgumentException( Environment.GetResourceString("Argument_NotACodeGroupType") );
group = (CodeGroup) Activator.CreateInstance(groupClass, true);
BCLDebug.Assert( groupClass.Module.Assembly != Assembly.GetExecutingAssembly(),
"This path should not get called for mscorlib based classes" );
return group;
}