public override object Execute(IContext context, Stream writer) { if (_expressions != null) { object data = _expressions.Execute(context, writer); string val; if (data is Array) { val = WriteArray((Array)data); } else { val = data.ToString(); } byte[] bytes = WebAppConfig.TemplateFileEncoding.GetBytes(val); writer.Write(bytes, 0, bytes.Length); } return(null); }
public override object Execute(IContext context, Stream writer) { return(_expressions.Execute(context, writer)); }
public override object Execute(IContext context, Stream writer) { object lValue = _leftSide.Execute(context, writer); object rValue = _expressions.Execute(context, writer); if (lValue is Array) { Array arrRight = (Array)rValue; if (arrRight.Length == 1) { Array arrLeft = (Array)lValue; return(arrLeft.GetValue(Convert.ToInt32(arrRight.GetValue(0)))); } else if (arrRight.Length > 1) { object o = lValue; for (int i = 0; i < arrRight.Length; i++) { if (o is Array) { o = ((Array)o).GetValue(Convert.ToInt32(arrRight.GetValue(i))); } else { break; } } return(o); } else { throw new CException("Syntax error, value expected of array"); } } else if (lValue is IDictionary) { IDictionary dic = (IDictionary)lValue; Array arrRight = (Array)rValue; if (arrRight.Length == 1) { return(dic[arrRight.GetValue(0)]); } } else if (lValue is IList) { IList ls = (IList)lValue; Array arrRight = (Array)rValue; if (arrRight.Length == 1) { return(ls[Convert.ToInt32(arrRight.GetValue(0))]); } } else { Type type = lValue.GetType(); PropertyInfo property = type.GetProperty("Item"); if (property != null) { object[] arrRight = (object[])rValue; return(property.GetValue(lValue, arrRight)); } } return(null); }