/// <summary> /// Creates an enabling condition for an action method. /// If the action method takes no input parameters or parameterless = true /// then mayDependOnState should be true, /// otherwise the condition will either always hold or never hold. /// </summary> internal EnablingCondition(ActionInfo actionInfo, bool mayDependOnState, bool parameterless) { this.actionInfo = actionInfo; Type type = actionInfo.model.GetType(); Type[] paramTypes = (parameterless ? Type.EmptyTypes : actionInfo.inputParameterTypes); foreach (ModelRequirementAttribute attr in ActionInfo.GetModelRequirementAttributes(actionInfo.method)) { MethodInfo pred = type.GetMethod(attr.MethodName,paramTypes); if (pred != null && pred.ReturnType == typeof(bool) && (mayDependOnState || IsStateIndependent(pred))) { predicates.Add(pred); } } }
void Initialize() { Type/*?*/[]/*?*/ allTypes = modelAssembly.GetTypes(); List<StateField> stateVars = new List<StateField>() ; //extract those classes that have the Model attribute foreach (Type t in allTypes) { if (IsModelClass(t)) { //create an instance of the model class object model = CreateModelInstance(t); //create a state variable for all model variable fields foreach (FieldInfo field in t.GetFields()) { if (IsModelVariable(field)) { stateVars.Add(new StateField(model,field)); } } //create actions foreach (MethodInfo method in t.GetMethods()) { if (IsModelActionSymbol(method)) { //TBD : split up into a Start and a Finish action symbols ActionInfo am = new ActionInfo(model, method, ActionKind.Atomic, this); this.actionMethodMap[am.actionSymbol] = am; } } } } this.actionSymbols = new ActionSymbol[this.actionMethodMap.Keys.Count]; int j =0; foreach (ActionSymbol a in actionMethodMap.Keys) this.actionSymbols[j++] = a; this.stateFields = stateVars.ToArray(); this.stateVariables = new StateVariable[this.stateFields.Length]; for (int i = 0; i < this.stateVariables.Length; i++) this.stateVariables[i] = this.stateFields[i].stateVariable; }