public ComputationCommand Get(string archetype, string mode = "singleton")
        {
            if (mode != "singleton" && mode != "prototype")
            {
                return(null);
            }
            ComputationCommand temp = null;

            if (commands.TryGetValue(archetype, out temp))
            {
                return((mode == "singleton")?temp:
                       temp.DeepClone <ComputationCommand>());
            }

            string classname = plugins[archetype];

            if (classname == null)
            {
                return(null);
            }
            string fullpackage = classname;

            Type t = Type.GetType(fullpackage);

            if (t == null)
            {
                return(null);
            }
            commands[archetype] = (ComputationCommand)Activator.CreateInstance(t);
            return(commands[archetype]);
        }
Ejemplo n.º 2
0
        public ComputationCommand Get(string archetype, string mode = "singleton")
        {
            //---- We can create a new instance, when a
            //---- prototype is asked, otherwise we will
            //---- return the same instance stored in the dictionary
            if (mode != "singleton" && mode != "prototype")
            {
                return(null);
            }

            ComputationCommand temp = null;

            //--- if an instance is already found, return
            // it (singleton) or clone (prototype
            if (commands.TryGetValue(archetype, out temp))
            {
                return((mode == "singleton") ? temp :
                       temp.DeepClone <ComputationCommand>());
            }

            //---- retreive the commandclass name
            string classname = plugins[archetype];

            if (classname == null)
            {
                return(null);
            }
            //------ retreieve the classname, if it
            //------ is available with CLR
            Type t = Type.GetType(classname);

            if (t == null)
            {
                return(null);
            }
            //---- Create a new Instance and store it
            //---- in commandclass instance dictionary
            commands[archetype] = (ComputationCommand)Activator.CreateInstance(t);
            return(commands[archetype]);
        }