All pastes #244803 Raw Edit

Miscellany

public text v1 · immutable
#244803 ·published 2006-11-10 05:27 UTC
rendered paste body
using System;
using System.Collections.Generic;
using System.Text;

namespace FlatRedBall
{
    public class FlatRedBallServices
    {

        private static Dictionary<Type, object> mPool;

        static FlatRedBallServices()
        {
            mPool = new Dictionary<Type, object>();
        }

        public static void RegisterService(object service)
        {
            Type t = service.GetType();
            RegisterService(t, service);
        }

        public static void RegisterService<T>(object service)
        {
            RegisterService(typeof(T), service);
        }

        public static void RegisterService(Type t, object service)
        {
            if (!mPool.Contains(t))
            {
                mPool.Add(t, service);
            }
            else
                mPool[t] = service;
        }

        public static T GetService<T>()
        {
            if(mPool.Contains(typeof(t))
                return (T)mPool[typeof(T)];
            else
                return null;
        }
    }
}