public static Type GetType(string name) { var tn = new TypeNameParser(name); var a = LoadAssembly(tn.AssemblyNameOrPath); var t = a.GetType(tn.TypeName, true); return t; }
private unsafe Type ConstructType(Func<AssemblyName, Assembly> assemblyResolver, Func<Assembly, string, bool, Type> typeResolver, bool throwOnError, bool ignoreCase, ref StackCrawlMark stackMark) { Assembly assembly = null; int[] numArray2; string assemblyName = this.GetAssemblyName(); if (assemblyName.Length > 0) { assembly = ResolveAssembly(assemblyName, assemblyResolver, throwOnError, ref stackMark); if (assembly == null) { return null; } } string[] names = this.GetNames(); if (names == null) { if (throwOnError) { throw new TypeLoadException(Environment.GetResourceString("Arg_TypeLoadNullStr")); } return null; } Type typeStart = ResolveType(assembly, names, typeResolver, throwOnError, ignoreCase, ref stackMark); if (typeStart == null) { return null; } SafeTypeNameParserHandle[] typeArguments = this.GetTypeArguments(); Type[] genericArgs = null; if (typeArguments != null) { genericArgs = new Type[typeArguments.Length]; for (int i = 0; i < typeArguments.Length; i++) { using (TypeNameParser parser = new TypeNameParser(typeArguments[i])) { genericArgs[i] = parser.ConstructType(assemblyResolver, typeResolver, throwOnError, ignoreCase, ref stackMark); } if (genericArgs[i] == null) { return null; } } } int[] modifiers = this.GetModifiers(); if (((numArray2 = modifiers) == null) || (numArray2.Length == 0)) { numRef = null; goto Label_00EE; } fixed (int* numRef = numArray2) { IntPtr ptr; Label_00EE: ptr = new IntPtr((void*) numRef); return RuntimeTypeHandle.GetTypeHelper(typeStart, genericArgs, ptr, (modifiers == null) ? 0 : modifiers.Length); } }
public static Type GetType( string typeName, Func <AssemblyName, Assembly>?assemblyResolver, Func <Assembly, string, bool, Type>?typeResolver) { StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; return(TypeNameParser.GetType(typeName, assemblyResolver, typeResolver, false, false, ref stackMark)); }
private unsafe Type ConstructType(Func <AssemblyName, Assembly> assemblyResolver, Func <Assembly, string, bool, Type> typeResolver, bool throwOnError, bool ignoreCase, ref StackCrawlMark stackMark) { Assembly assembly = null; string assemblyName = this.GetAssemblyName(); if (assemblyName.Length > 0) { assembly = TypeNameParser.ResolveAssembly(assemblyName, assemblyResolver, throwOnError, ref stackMark); if (assembly == null) { return(null); } } string[] names = this.GetNames(); if (names == null) { if (throwOnError) { throw new TypeLoadException(Environment.GetResourceString("Arg_TypeLoadNullStr")); } return(null); } else { Type type = TypeNameParser.ResolveType(assembly, names, typeResolver, throwOnError, ignoreCase, ref stackMark); if (type == null) { return(null); } SafeTypeNameParserHandle[] typeArguments = this.GetTypeArguments(); Type[] array = null; if (typeArguments != null) { array = new Type[typeArguments.Length]; for (int i = 0; i < typeArguments.Length; i++) { using (TypeNameParser typeNameParser = new TypeNameParser(typeArguments[i])) { array[i] = typeNameParser.ConstructType(assemblyResolver, typeResolver, throwOnError, ignoreCase, ref stackMark); } if (array[i] == null) { return(null); } } } int[] modifiers = this.GetModifiers(); fixed(int *ptr = modifiers) { IntPtr pModifiers = new IntPtr((void *)ptr); return(RuntimeTypeHandle.GetTypeHelper(type, array, pModifiers, (modifiers == null) ? 0 : modifiers.Length)); } } }
[System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod public static Type?GetType( string typeName, Func <AssemblyName, Assembly?>?assemblyResolver, Func <Assembly?, string, bool, Type?>?typeResolver, bool throwOnError, bool ignoreCase) { StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; return(TypeNameParser.GetType(typeName, assemblyResolver, typeResolver, throwOnError, ignoreCase, ref stackMark)); }
private unsafe Type ConstructType(Func <AssemblyName, Assembly> assemblyResolver, Func <Assembly, string, bool, Type> typeResolver, bool throwOnError, bool ignoreCase, ref StackCrawlMark stackMark) { Assembly assembly = (Assembly)null; string assemblyName = this.GetAssemblyName(); if (assemblyName.Length > 0) { assembly = TypeNameParser.ResolveAssembly(assemblyName, assemblyResolver, throwOnError, ref stackMark); if (assembly == (Assembly)null) { return((Type)null); } } string[] names = this.GetNames(); if (names == null) { if (throwOnError) { throw new TypeLoadException(Environment.GetResourceString("Arg_TypeLoadNullStr")); } return((Type)null); } Type typeStart = TypeNameParser.ResolveType(assembly, names, typeResolver, throwOnError, ignoreCase, ref stackMark); if (typeStart == (Type)null) { return((Type)null); } SafeTypeNameParserHandle[] typeArguments = this.GetTypeArguments(); Type[] genericArgs = (Type[])null; if (typeArguments != null) { genericArgs = new Type[typeArguments.Length]; for (int index = 0; index < typeArguments.Length; ++index) { using (TypeNameParser typeNameParser = new TypeNameParser(typeArguments[index])) genericArgs[index] = typeNameParser.ConstructType(assemblyResolver, typeResolver, throwOnError, ignoreCase, ref stackMark); if (genericArgs[index] == (Type)null) { return((Type)null); } } } int[] modifiers = this.GetModifiers(); fixed(int *numPtr = modifiers) { IntPtr pModifiers = new IntPtr((void *)numPtr); return(RuntimeTypeHandle.GetTypeHelper(typeStart, genericArgs, pModifiers, modifiers == null ? 0 : modifiers.Length)); } }
private static Type ResolveType(Assembly assembly, string[] names, Func <Assembly, string, bool, Type> typeResolver, bool throwOnError, bool ignoreCase, ref StackCrawlMark stackMark) { string str = TypeNameParser.EscapeTypeName(names[0]); Type type; if (typeResolver != null) { type = typeResolver(assembly, str, ignoreCase); if (type == (Type)null & throwOnError) { string resourceString; if (!(assembly == (Assembly)null)) { resourceString = Environment.GetResourceString("TypeLoad_ResolveTypeFromAssembly", (object)str, (object)assembly.FullName); } else { resourceString = Environment.GetResourceString("TypeLoad_ResolveType", (object)str); } throw new TypeLoadException(resourceString); } } else { type = !(assembly == (Assembly)null) ? assembly.GetType(str, throwOnError, ignoreCase) : (Type)RuntimeType.GetType(str, throwOnError, ignoreCase, false, ref stackMark); } if (type != (Type)null) { BindingFlags bindingAttr = BindingFlags.Public | BindingFlags.NonPublic; if (ignoreCase) { bindingAttr |= BindingFlags.IgnoreCase; } for (int index = 1; index < names.Length; ++index) { type = type.GetNestedType(names[index], bindingAttr); if (type == (Type)null) { if (throwOnError) { throw new TypeLoadException(Environment.GetResourceString("TypeLoad_ResolveNestedType", (object)names[index], (object)names[index - 1])); } break; } } } return(type); }
internal static Type GetType(string typeName, Func <AssemblyName, Assembly> assemblyResolver, Func <Assembly, string, bool, Type> typeResolver, bool throwOnError, bool ignoreCase, ref StackCrawlMark stackMark) { if (typeName == null) { throw new ArgumentNullException("typeName"); } if (typeName.Length > 0 && (int)typeName[0] == 0) { throw new ArgumentException(Environment.GetResourceString("Format_StringZeroLength")); } Type type = (Type)null; SafeTypeNameParserHandle typeNameParser1 = TypeNameParser.CreateTypeNameParser(typeName, throwOnError); if (typeNameParser1 != null) { using (TypeNameParser typeNameParser2 = new TypeNameParser(typeNameParser1)) type = typeNameParser2.ConstructType(assemblyResolver, typeResolver, throwOnError, ignoreCase, ref stackMark); } return(type); }
internal static Type GetType(string typeName, Func<AssemblyName, Assembly> assemblyResolver, Func<Assembly, string, bool, Type> typeResolver, bool throwOnError, bool ignoreCase, ref StackCrawlMark stackMark) { if (typeName == null) { throw new ArgumentNullException("typeName"); } if (typeName.Length > 0 && typeName[0] == '\0') { throw new ArgumentException(Environment.GetResourceString("Format_StringZeroLength")); } Type result = null; SafeTypeNameParserHandle safeTypeNameParserHandle = TypeNameParser.CreateTypeNameParser(typeName, throwOnError); if (safeTypeNameParserHandle != null) { using (TypeNameParser typeNameParser = new TypeNameParser(safeTypeNameParserHandle)) { result = typeNameParser.ConstructType(assemblyResolver, typeResolver, throwOnError, ignoreCase, ref stackMark); } } return result; }
internal static Type?GetType( string typeName, Func <AssemblyName, Assembly?>?assemblyResolver, Func <Assembly?, string, bool, Type?>?typeResolver, bool throwOnError, bool ignoreCase, ref StackCrawlMark stackMark ) { if (typeName == null) { throw new ArgumentNullException(nameof(typeName)); } if (typeName.Length > 0 && typeName[0] == '\0') { throw new ArgumentException(SR.Format_StringZeroLength); } Type?ret = null; SafeTypeNameParserHandle?handle = CreateTypeNameParser(typeName, throwOnError); if (handle != null) { // If we get here the typeName must have been successfully parsed. // Let's construct the Type object. using (TypeNameParser parser = new TypeNameParser(handle)) { ret = parser.ConstructType( assemblyResolver, typeResolver, throwOnError, ignoreCase, ref stackMark ); } } return(ret); }
internal static Type GetType(string typeName, Func <AssemblyName, Assembly> assemblyResolver, Func <Assembly, string, bool, Type> typeResolver, bool throwOnError, bool ignoreCase, ref StackCrawlMark stackMark) { if (typeName == null) { throw new ArgumentNullException("typeName"); } if ((typeName.Length > 0) && (typeName[0] == '\0')) { throw new ArgumentException(Environment.GetResourceString("Format_StringZeroLength")); } Type type = null; SafeTypeNameParserHandle handle = CreateTypeNameParser(typeName, throwOnError); if (handle == null) { return(type); } using (TypeNameParser parser = new TypeNameParser(handle)) { return(parser.ConstructType(assemblyResolver, typeResolver, throwOnError, ignoreCase, ref stackMark)); } }
private unsafe Type?ConstructType( Func <AssemblyName, Assembly?>?assemblyResolver, Func <Assembly?, string, bool, Type?>?typeResolver, bool throwOnError, bool ignoreCase, ref StackCrawlMark stackMark) { // assembly name Assembly?assembly = null; string asmName = GetAssemblyName(); // GetAssemblyName never returns null Debug.Assert(asmName != null); if (asmName.Length > 0) { assembly = ResolveAssembly(asmName, assemblyResolver, throwOnError, ref stackMark); if (assembly == null) { // Cannot resolve the assembly. If throwOnError is true we should have already thrown. return(null); } } string[]? names = GetNames(); if (names == null) { // This can only happen if the type name is an empty string or if the first char is '\0' if (throwOnError) { throw new TypeLoadException(SR.Arg_TypeLoadNullStr); } return(null); } Type?baseType = ResolveType(assembly, names, typeResolver, throwOnError, ignoreCase, ref stackMark); if (baseType == null) { // Cannot resolve the type. If throwOnError is true we should have already thrown. Debug.Assert(throwOnError == false); return(null); } SafeTypeNameParserHandle[]? typeArguments = GetTypeArguments(); Type?[]? types = null; if (typeArguments != null) { types = new Type[typeArguments.Length]; for (int i = 0; i < typeArguments.Length; i++) { Debug.Assert(typeArguments[i] != null); using (TypeNameParser argParser = new TypeNameParser(typeArguments[i])) { types[i] = argParser.ConstructType(assemblyResolver, typeResolver, throwOnError, ignoreCase, ref stackMark); } if (types[i] == null) { // If throwOnError is true argParser.ConstructType should have already thrown. Debug.Assert(throwOnError == false); return(null); } } } int[]? modifiers = GetModifiers(); fixed(int *ptr = modifiers) { IntPtr intPtr = new IntPtr(ptr); return(RuntimeTypeHandle.GetTypeHelper(baseType, types !, intPtr, modifiers == null ? 0 : modifiers.Length)); } }
internal static Type GetType( string typeName, Func<AssemblyName, Assembly> assemblyResolver, Func<Assembly, string, bool, Type> typeResolver, bool throwOnError, bool ignoreCase, ref StackCrawlMark stackMark) { if (typeName == null) throw new ArgumentNullException("typeName"); if (typeName.Length > 0 && typeName[0] == '\0') throw new ArgumentException(Environment.GetResourceString("Format_StringZeroLength")); Contract.EndContractBlock(); Type ret = null; SafeTypeNameParserHandle handle = CreateTypeNameParser(typeName, throwOnError); if (handle != null) { // If we get here the typeName must have been successfully parsed. // Let's construct the Type object. using (TypeNameParser parser = new TypeNameParser(handle)) { ret = parser.ConstructType(assemblyResolver, typeResolver, throwOnError, ignoreCase, ref stackMark); } } return ret; }
public static bool TryParse(string typeNameString, SerializedTypeName typeName) { var parser = new TypeNameParser(typeNameString, typeName); return parser.Start(); }
private SafeTypeNameParserHandle[] GetTypeArguments() { SafeTypeNameParserHandle[] o = (SafeTypeNameParserHandle[])null; TypeNameParser._GetTypeArguments(this.m_NativeParser, JitHelpers.GetObjectHandleOnStack <SafeTypeNameParserHandle[]>(ref o)); return(o); }
private unsafe Type ConstructType( Func<AssemblyName, Assembly> assemblyResolver, Func<Assembly, string, bool, Type> typeResolver, bool throwOnError, bool ignoreCase, ref StackCrawlMark stackMark) { // assembly name Assembly assembly = null; string asmName = GetAssemblyName(); // GetAssemblyName never returns null Contract.Assert(asmName != null); if (asmName.Length > 0) { assembly = ResolveAssembly(asmName, assemblyResolver, throwOnError, ref stackMark); if (assembly == null) { // Cannot resolve the assembly. If throwOnError is true we should have already thrown. return null; } } string[] names = GetNames(); if (names == null) { // This can only happen if the type name is an empty string or if the first char is '\0' if (throwOnError) throw new TypeLoadException(Environment.GetResourceString("Arg_TypeLoadNullStr")); return null; } Type baseType = ResolveType(assembly, names, typeResolver, throwOnError, ignoreCase, ref stackMark); if (baseType == null) { // Cannot resolve the type. If throwOnError is true we should have already thrown. Contract.Assert(throwOnError == false); return null; } SafeTypeNameParserHandle[] typeArguments = GetTypeArguments(); Type[] types = null; if (typeArguments != null) { types = new Type[typeArguments.Length]; for (int i = 0; i < typeArguments.Length; i++) { Contract.Assert(typeArguments[i] != null); using (TypeNameParser argParser = new TypeNameParser(typeArguments[i])) { types[i] = argParser.ConstructType(assemblyResolver, typeResolver, throwOnError, ignoreCase, ref stackMark); } if (types[i] == null) { // If throwOnError is true argParser.ConstructType should have already thrown. Contract.Assert(throwOnError == false); return null; } } } int[] modifiers = GetModifiers(); fixed (int* ptr = modifiers) { IntPtr intPtr = new IntPtr(ptr); return RuntimeTypeHandle.GetTypeHelper(baseType, types, intPtr, modifiers == null ? 0 : modifiers.Length); } }
private unsafe Type ConstructType(Func<AssemblyName, Assembly> assemblyResolver, Func<Assembly, string, bool, Type> typeResolver, bool throwOnError, bool ignoreCase, ref StackCrawlMark stackMark) { Assembly assembly = null; string assemblyName = this.GetAssemblyName(); if (assemblyName.Length > 0) { assembly = TypeNameParser.ResolveAssembly(assemblyName, assemblyResolver, throwOnError, ref stackMark); if (assembly == null) { return null; } } string[] names = this.GetNames(); if (names == null) { if (throwOnError) { throw new TypeLoadException(Environment.GetResourceString("Arg_TypeLoadNullStr")); } return null; } else { Type type = TypeNameParser.ResolveType(assembly, names, typeResolver, throwOnError, ignoreCase, ref stackMark); if (type == null) { return null; } SafeTypeNameParserHandle[] typeArguments = this.GetTypeArguments(); Type[] array = null; if (typeArguments != null) { array = new Type[typeArguments.Length]; for (int i = 0; i < typeArguments.Length; i++) { using (TypeNameParser typeNameParser = new TypeNameParser(typeArguments[i])) { array[i] = typeNameParser.ConstructType(assemblyResolver, typeResolver, throwOnError, ignoreCase, ref stackMark); } if (array[i] == null) { return null; } } } int[] modifiers = this.GetModifiers(); fixed (int* ptr = modifiers) { IntPtr pModifiers = new IntPtr((void*)ptr); return RuntimeTypeHandle.GetTypeHelper(type, array, pModifiers, (modifiers == null) ? 0 : modifiers.Length); } } }
private int[] GetModifiers() { int[] o = (int[])null; TypeNameParser._GetModifiers(this.m_NativeParser, JitHelpers.GetObjectHandleOnStack <int[]>(ref o)); return(o); }
private unsafe Type ConstructType(Func <AssemblyName, Assembly> assemblyResolver, Func <Assembly, string, bool, Type> typeResolver, bool throwOnError, bool ignoreCase, ref StackCrawlMark stackMark) { Assembly assembly = null; int[] numArray2; string assemblyName = this.GetAssemblyName(); if (assemblyName.Length > 0) { assembly = ResolveAssembly(assemblyName, assemblyResolver, throwOnError, ref stackMark); if (assembly == null) { return(null); } } string[] names = this.GetNames(); if (names == null) { if (throwOnError) { throw new TypeLoadException(Environment.GetResourceString("Arg_TypeLoadNullStr")); } return(null); } Type typeStart = ResolveType(assembly, names, typeResolver, throwOnError, ignoreCase, ref stackMark); if (typeStart == null) { return(null); } SafeTypeNameParserHandle[] typeArguments = this.GetTypeArguments(); Type[] genericArgs = null; if (typeArguments != null) { genericArgs = new Type[typeArguments.Length]; for (int i = 0; i < typeArguments.Length; i++) { using (TypeNameParser parser = new TypeNameParser(typeArguments[i])) { genericArgs[i] = parser.ConstructType(assemblyResolver, typeResolver, throwOnError, ignoreCase, ref stackMark); } if (genericArgs[i] == null) { return(null); } } } int[] modifiers = this.GetModifiers(); if (((numArray2 = modifiers) == null) || (numArray2.Length == 0)) { numRef = null; goto Label_00EE; } fixed(int *numRef = numArray2) { IntPtr ptr; Label_00EE: ptr = new IntPtr((void *)numRef); return(RuntimeTypeHandle.GetTypeHelper(typeStart, genericArgs, ptr, (modifiers == null) ? 0 : modifiers.Length)); } }
private string[] GetNames() { string[] o = (string[])null; TypeNameParser._GetNames(this.m_NativeParser, JitHelpers.GetObjectHandleOnStack <string[]>(ref o)); return(o); }
private int[] GetModifiers() { int[] result = null; TypeNameParser._GetModifiers(this.m_NativeParser, JitHelpers.GetObjectHandleOnStack <int[]>(ref result)); return(result); }
private static Type?GetType(string typeName, Func <AssemblyName, Assembly?>?assemblyResolver, Func <Assembly?, string, bool, Type?>?typeResolver, bool throwOnError, bool ignoreCase, ref StackCrawlMark stackMark) { return(TypeNameParser.GetType(typeName, assemblyResolver, typeResolver, throwOnError, ignoreCase, ref stackMark)); }
private string[] GetNames() { string[] result = null; TypeNameParser._GetNames(this.m_NativeParser, JitHelpers.GetObjectHandleOnStack <string[]>(ref result)); return(result); }