﻿using System;
using System.Reflection;
using Pal.Core.Interface.Services;
using Pal.Core.Interface.Wrappers;
using Pal.Core.Wrappers;

namespace Pal.Core.Services
{
    public class AssemblyService: IAssemblyService
    {
        public IAssemblyWrapper GetExecutingAssembly()
        {
            var assembly = Assembly.GetExecutingAssembly();
            return new AssemblyWrapper(assembly);
        }

        public IAssemblyWrapper GetAssembly(string name)
        {
            foreach (var currentAssembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                if (currentAssembly.GetName().Name == name)
                {
                    return new AssemblyWrapper(currentAssembly);
                }
            }

            throw new Exception("Assembly "+ name + " not found in the AppDomain.");
        }
    }
}
