/// <summary> /// Property getter. /// </summary> public IVelPropertyGet GetPropertyGet(Object obj, String identifier, Info i) { AbstractExecutor executor; Type type = obj.GetType(); // First try for a getFoo() type of property (also getfoo()) executor = new PropertyExecutor(runtimeLogger, introspector, type, identifier); // If that didn't work, look for get("foo") if (!executor.IsAlive) { executor = new GetExecutor(runtimeLogger, introspector, type, identifier); } // If that didn't work, look for boolean isFoo() if (!executor.IsAlive) { executor = new BooleanPropertyExecutor(runtimeLogger, introspector, type, identifier); } // If that didn't work, look for an enumeration if (!executor.IsAlive && (obj is Type) && (obj as Type).IsEnum) { executor = new EnumValueExecutor(runtimeLogger, introspector, obj as Type, identifier); } return new VelGetterImpl(executor); }
/// <summary> /// simple init - don't do anything that is context specific. /// just get what we need from the AST, which is static. /// </summary> public override Object Init(IInternalContextAdapter context, Object data) { base.Init(context, data); identifier = FirstToken.Image; uberInfo = new Info(context.CurrentTemplateName, Line, Column); return data; }
/// <summary> /// Method /// </summary> public IVelMethod GetMethod(Object obj, String methodName, Object[] args, Info i) { if (obj == null) { return null; } MethodInfo m = introspector.GetMethod(obj.GetType(), methodName, args); return (m != null) ? new VelMethodImpl(m) : null; }
/// <summary> /// Property setter. /// </summary> public IVelPropertySet GetPropertySet(Object obj, String identifier, Object arg, Info i) { Type type = obj.GetType(); IVelMethod method = null; try { /* * first, we introspect for the set<identifier> setter method */ Object[] parameters = new Object[] {arg}; try { method = GetMethod(obj, string.Format("set{0}", identifier), parameters, i); if (method == null) { throw new MethodAccessException(); } } catch(MethodAccessException) { StringBuilder sb = new StringBuilder("set"); sb.Append(identifier); if (Char.IsLower(sb[3])) { sb[3] = Char.ToUpper(sb[3]); } else { sb[3] = Char.ToLower(sb[3]); } method = GetMethod(obj, sb.ToString(), parameters, i); if (method == null) throw; } } catch(MethodAccessException) { // right now, we only support the IDictionary interface if (typeof(IDictionary).IsAssignableFrom(type)) { Object[] parameters = new Object[] {new Object(), new Object()}; method = GetMethod(obj, "Add", parameters, i); if (method != null) { return new VelSetterImpl(method, identifier); } } } return (method != null) ? new VelSetterImpl(method) : null; }