protected void AddAffordance(MethodInfo method, AffordanceAttribute attr) { if (method == null || method.ReturnType != typeof(RunStatus) || method.GetParameters().Length != 1 || method.GetParameters()[0].ParameterType != typeof(Character)) throw new ApplicationException( this.gameObject.name + ": Wrong function signature for affordance"); // Reads the methodinfo and converts it into a pre-compiled Func<> // expression. This should make it cheaper to invoke at runtime. ParameterExpression param = ParameterExpression.Parameter(typeof(Character), "c"); Expression invoke = Expression.Call(Expression.Constant(this), method, param); Func<Character, RunStatus> result = Expression.Lambda<Func<Character, RunStatus>>(invoke, param).Compile(); this.registry.Add(method.Name, result); }
protected void AddAffordance(MethodInfo method, AffordanceAttribute attr) { if (method == null || method.ReturnType != typeof(RunStatus) || method.GetParameters().Length != 1 || method.GetParameters()[0].ParameterType != typeof(Character)) { throw new ApplicationException( this.gameObject.name + ": Wrong function signature for affordance"); } // Reads the methodinfo and converts it into a pre-compiled Func<> // expression. This should make it cheaper to invoke at runtime. ParameterExpression param = ParameterExpression.Parameter(typeof(Character), "c"); Expression invoke = Expression.Call(Expression.Constant(this), method, param); Func <Character, RunStatus> result = Expression.Lambda <Func <Character, RunStatus> >(invoke, param).Compile(); this.registry.Add(method.Name, result); }
private void AddAffordance( MethodInfo method, AffordanceAttribute attr) { Type requiredType = method.GetParameters()[0].ParameterType; bool compatibleType = typeof(SmartObject).IsAssignableFrom(requiredType); if (method == null || method.ReturnType != typeof(Node) || method.GetParameters().Length != 1 || compatibleType == false) throw new ApplicationException( this.gameObject.name + ": Wrong function signature for affordance"); string name = method.Name; Affordance affordance = new Affordance( name, attr.Reflexive, requiredType, method); this.affordances.Add(name, affordance); }