// This file is autogenerated by ClassMapGen. DO NOT EDIT using System; using System.Collections.Generic; using System.Linq; using System.Reflection; namespace OSGeo.MapGuide { internal static class MgClassMap { static HashSet assemblyNames; static Dictionary classIdCtorMap; static Dictionary nameClassMap; static MgClassMap() { assemblyNames = new HashSet { "OSGeo.MapGuide.Foundation", "OSGeo.MapGuide.Geometry", "OSGeo.MapGuide.PlatformBase", "OSGeo.MapGuide.MapGuideCommon", "OSGeo.MapGuide.Web", "OSGeo.MapGuide.Portable" }; classIdCtorMap = new Dictionary(); var classNameMap = new Dictionary(); nameClassMap = new Dictionary(); $CLASS_NAME_MAP_BODY$ //Sanity check that we haven't double registered the same type name under different //class ids (Only possible when class id is being accidentally reused in a base or //derived C++ class) foreach (var kvp in classNameMap) { if (nameClassMap.ContainsKey(kvp.Value)) { throw new Exception($"Failed sanity check. Type ({kvp.Value}) already registered with class id of ({kvp.Key})"); } nameClassMap[kvp.Value] = kvp.Key; } } internal static IEnumerable ClassIds => classIdCtorMap.Keys; internal static int? GetClassId(string typeName) { return nameClassMap.ContainsKey(typeName) ? nameClassMap[typeName] : (int?)null; } internal static ConstructorInfo GetProxyConstructor(int classId) { return classIdCtorMap.ContainsKey(classId) ? classIdCtorMap[classId] : null; } static bool HasAssemblyInAppDomain(string assemblyName) { #if MONOLITHIC_ASSEMBLY return true; #else var assemblies = global::System.AppDomain.CurrentDomain.GetAssemblies(); foreach (var assem in assemblies) { var asmName = new global::System.Reflection.AssemblyName(assem.FullName); if (asmName.Name == assemblyName) { return true; } } return false; #endif } static ConstructorInfo ResolveConstructor(string typeName) { var type = global::System.Type.GetType(typeName); if (type == null) { // Find the specified class in the pre-defined assemblies var assemblies = global::System.AppDomain.CurrentDomain.GetAssemblies(); foreach (var assem in assemblies) { var assemblyName = new global::System.Reflection.AssemblyName(assem.FullName); if (assemblyNames.Contains(assemblyName.Name)) { type = assem.GetType(typeName, false); if (type != null) break; } } // Fall back to finding the type in every assembly in the current appdomain foreach (var assem in global::System.AppDomain.CurrentDomain.GetAssemblies()) { type = assem.GetType(typeName, false); if (type != null) break; } } if (type == null) //Shouldn't happen. But if it did, this would mean we didn't expose this class to SWIG { throw new global::System.Exception("The type " + typeName + " does not exist in the list of loaded assemblies"); } else { //The constructor we require has been assigned internal visibility by SWIG. We could change it to public, but the internal //visibility is the ideal one for purposes of encapulsation (this is internal use only). So instead of Activator.CreateInstance() //which does not work with internal constructors, we'll find the ctor ourselves and invoke it. var flags = global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.Instance; var ctors = type.GetTypeInfo().GetConstructors(flags); var ctor = ctors.FirstOrDefault(ci => { var parms = ci.GetParameters(); if (parms.Length == 2) { return parms[0].ParameterType == typeof(global::System.IntPtr) && parms[1].ParameterType == typeof(bool); } return false; }); if (ctor == null) throw new global::System.Exception("Could not find required constructor among " + ctors.Length + " constructors with signature (IntPtr, bool) on type: " + type.Name); return ctor; } } } }