Esempio n. 1
0
        internal static InjectionMapping FromProjectInjectionMapping(ProjectInjectionMapping projMapping)
        {
            MonoAssemblyResolver targetAssembly = null;
            TypeDefinition       type           = null;
            MethodDefinition     method         = null;
            Type injector = null;

            if (CacheStore.Exists <MonoAssemblyResolver>(projMapping.TargetAssemblyPath))
            {
                targetAssembly = CacheStore.Get <MonoAssemblyResolver>(projMapping.TargetAssemblyPath);
            }
            else
            {
                targetAssembly = new MonoAssemblyResolver(projMapping.TargetAssemblyPath);
                CacheStore.Add <MonoAssemblyResolver>(projMapping.TargetAssemblyPath, targetAssembly);
            }

            string classNameKey = targetAssembly.Assembly.Name.Name + "." + projMapping.ClassName;

            if (CacheStore.Exists <TypeDefinition>(classNameKey))
            {
                type = CacheStore.Get <TypeDefinition>(classNameKey);
            }
            else
            {
                type = targetAssembly.Assembly.MainModule.GetType(classNameKey);
                CacheStore.Add <TypeDefinition>(classNameKey, type);
            }

            if (CacheStore.Exists <MethodDefinition>(classNameKey + projMapping.MethodName))
            {
                method = CacheStore.Get <MethodDefinition>(classNameKey + projMapping.MethodName);
            }
            else
            {
                method = type.GetMethodDefinition(projMapping.MethodName, projMapping.MethodParameters);
                CacheStore.Add <MethodDefinition>(classNameKey + projMapping.MethodName, method);
            }

            if (CacheStore.Exists <Type>(projMapping.InjectorType))
            {
                injector = CacheStore.Get <Type>(projMapping.InjectorType);
            }
            else
            {
                injector = Type.GetType(projMapping.InjectorType);
                CacheStore.Add <Type>(projMapping.InjectorType, injector);
            }

            return(new InjectionMapping(targetAssembly, method, injector));
        }
        internal static ProjectInjectionMapping FromInjectionMapping(InjectionMapping mapping)
        {
            ProjectInjectionMapping projMapping = new ProjectInjectionMapping();

            projMapping.ClassName          = mapping.Method.DeclaringType.Name;
            projMapping.TargetAssemblyPath = mapping.Assembly.Path;
            projMapping.MethodName         = mapping.Method.Name;
            projMapping.MethodParameters   = mapping.Method.Parameters.Count;

            projMapping.InjectorAssemblyPath = mapping.Injector.Assembly.GetPath();
            projMapping.InjectorType         = mapping.Injector.AssemblyQualifiedName;

            return(projMapping);
        }