mirror of
https://github.com/opensim/opensim.git
synced 2026-06-07 20:15:43 +08:00
45 lines
1.1 KiB
C#
45 lines
1.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
|
|
namespace OpenSim.Framework
|
|
{
|
|
public class RegistryCore : IRegistryCore
|
|
{
|
|
protected Dictionary<Type, object> m_moduleInterfaces = new Dictionary<Type, object>();
|
|
|
|
/// <summary>
|
|
/// Register an Module interface.
|
|
/// </summary>
|
|
/// <typeparam name="T"></typeparam>
|
|
/// <param name="iface"></param>
|
|
public void RegisterInterface<T>(T iface)
|
|
{
|
|
lock (m_moduleInterfaces)
|
|
{
|
|
if (!m_moduleInterfaces.ContainsKey(typeof(T)))
|
|
{
|
|
m_moduleInterfaces.Add(typeof(T), iface);
|
|
}
|
|
}
|
|
}
|
|
|
|
public bool TryGet<T>(out T iface)
|
|
{
|
|
if (m_moduleInterfaces.ContainsKey(typeof(T)))
|
|
{
|
|
iface = (T)m_moduleInterfaces[typeof(T)];
|
|
return true;
|
|
}
|
|
iface = default(T);
|
|
return false;
|
|
}
|
|
|
|
public T Get<T>()
|
|
{
|
|
return (T)m_moduleInterfaces[typeof(T)];
|
|
}
|
|
|
|
}
|
|
}
|