Exemplo n.º 1
0
        public void RemoveTypeNotify <TMembrane, TSource>(IReceptor receptor)
            where TMembrane : IMembrane
            where TSource : ISemanticType
        {
            Type        tsource   = typeof(TSource);
            Type        treceptor = receptor.GetType();
            IMembrane   membrane  = membranes[typeof(TMembrane)];
            List <Type> targets   = GetReceptors(membrane, tsource);

            // Remove from type list for this membrane this receptor, by its type.
            foreach (Type ttarget in targets)
            {
                typeNotifiers[tsource].Remove(ttarget);
            }

            // Remove from instance list.
            List <IReceptor> instanceReceptors = GetStatefulReceptors(membrane, tsource);

            foreach (IReceptor ireceptor in instanceReceptors)
            {
                // Remove only this instance receptor from its membrane.
                if (ireceptor == receptor)
                {
                    instanceNotifiers[tsource].Remove(receptor);
                }
            }
        }
Exemplo n.º 2
0
 public void Store(IReceptor receptor)
 {
     var name = receptor.GetType().Name;
     if (name.IndexOf("Receptor") > 0)
     {
         name = name.Substring(0, name.Length - 8);
     }
     Store(name, receptor);
 }
Exemplo n.º 3
0
        /// <summary>
        /// Register a stateful receptor contained within the specified membrane.
        /// </summary>
        public void Register(IMembrane membrane, IReceptor receptor)
        {
            statefulReceptors.Add(receptor);
            Type ttarget = receptor.GetType();

            MethodInfo[] methods = ttarget.GetMethods();

            foreach (MethodInfo method in methods)
            {
                // TODO: Use attribute, not specific function name.
                if (method.Name == "Process")
                {
                    ParameterInfo[] parameters = method.GetParameters();
                    InstanceNotify(receptor, parameters[2].ParameterType);
                }
            }

            membranes[membrane.GetType()] = membrane;
            membraneReceptorInstances[membrane].Add(receptor);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Get the Process method that implements, in its parameters, the source type.
        /// Only one process method is allowed for a specific type -- the compiler would tell us if there's duplicates.
        /// However, we can have different process methods for interfaces and base classes of a given type, as these
        /// each are maintained in unique receptor target lists, since they are, technically, different types!
        /// </summary>
        protected MethodInfo GetProcessMethod(IReceptor target, Type tsource)
        {
            // TODO: Cache the (target type, source type) MethodInfo
            MethodInfo[] methods = target.GetType().GetMethods();

            // Also check interfaces implemented by the source.
            Type[] interfaces = tsource.GetInterfaces();

            foreach (MethodInfo method in methods)
            {
                if (method.Name == "Process")
                {
                    ParameterInfo[] parameters = method.GetParameters();

                    foreach (ParameterInfo parameter in parameters)
                    {
                        // Do we have a match for the concrete source type?
                        if (parameter.ParameterType == tsource)
                        {
                            return(method);
                        }

                        // Do we have a match for any interfaces the concrete source type implements?
                        foreach (Type iface in interfaces)
                        {
                            if (parameter.ParameterType == iface)
                            {
                                return(method);
                            }
                        }
                    }
                }
            }

            return(null);
        }