System.Security.PermissionToken.IsMscorlibClassName C# (CSharp) Method

IsMscorlibClassName() static private method

static private IsMscorlibClassName ( string className ) : bool
className string
return bool
        internal static bool IsMscorlibClassName (string className) {
            BCLDebug.Assert( c_mscorlibName == Assembly.GetExecutingAssembly().nGetSimpleName(),
                "mscorlib name mismatch" );

            // If the class name does not look like a fully qualified name, we cannot simply determine if it's 
            // an mscorlib.dll type so we should return true so the type can be matched with the
            // right index in the TokenBasedSet.
            int index = className.IndexOf(',');
            if (index == -1)
                return true;

            index = className.LastIndexOf(']');
            if (index == -1)
                index = 0;

            // Search for the string 'mscorlib' in the classname. If we find it, we will conservatively assume it's an mscorlib.dll type and load it.
            for (int i = index; i < className.Length; i++) {
                if (className[i] == 'm' || className[i] == 'M') {
                    if (String.Compare(className, i, c_mscorlibName, 0, c_mscorlibName.Length, StringComparison.OrdinalIgnoreCase) == 0)
                        return true;
                }
            }
            return false;
        }

Usage Example

Example #1
0
 public static PermissionToken GetToken(string typeStr, bool bCreateMscorlib)
 {
     if (typeStr == null)
     {
         return((PermissionToken)null);
     }
     if (!PermissionToken.IsMscorlibClassName(typeStr))
     {
         return(PermissionToken.s_theTokenFactory.GetToken(typeStr));
     }
     if (!bCreateMscorlib)
     {
         return((PermissionToken)null);
     }
     return(PermissionToken.FindToken(Type.GetType(typeStr)));
 }