1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Reflection;
- using log4net;
- using OpenSim.Region.ScriptEngine.Interfaces;
- namespace OpenSim.Region.ScriptEngine.Shared.Api
- {
- public class ApiManager
- {
- private Dictionary<string,Type> m_Apis = new Dictionary<string,Type>();
- public string[] GetApis()
- {
- if (m_Apis.Count <= 0)
- {
- Assembly a = Assembly.GetExecutingAssembly();
- Type[] types = a.GetExportedTypes();
- foreach (Type t in types)
- {
- string name = t.ToString();
- int idx = name.LastIndexOf('.');
- if (idx != -1)
- name = name.Substring(idx+1);
- if (name.EndsWith("_Api"))
- {
- name = name.Substring(0, name.Length - 4);
- m_Apis[name] = t;
- }
- }
- }
- return new List<string>(m_Apis.Keys).ToArray();
- }
- public IScriptApi CreateApi(string api)
- {
- if (!m_Apis.ContainsKey(api))
- return null;
- IScriptApi ret = (IScriptApi)(Activator.CreateInstance(m_Apis[api]));
- return ret;
- }
- }
- }
|