aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/OptionalModules/Scripting/Minimodule/ExtensionHandler.cs
blob: d3efe9cdbd24c2cebc110250263e2071686971b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System;
using System.Collections.Generic;
using System.Text;
using OpenSim.Region.OptionalModules.Scripting.Minimodule.Interfaces;

namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
{
    class ExtensionHandler : IExtension 
    {
        private readonly Dictionary<Type, object> m_instances;

        public ExtensionHandler(Dictionary<Type, object> instances)
        {
            m_instances = instances;
        }

        public T Get<T>()
        {
            return (T) m_instances[typeof (T)];
        }

        public bool TryGet<T>(out T extension)
        {
            if (!m_instances.ContainsKey(typeof(T)))
            {
                extension = default(T);
                return false;
            }

            extension = Get<T>();
            return true;
        }

        public bool Has<T>()
        {
            return m_instances.ContainsKey(typeof (T));
        }
    }
}