private static object GetValueFromContext(string Key, string Value, FrontContext context) { if (!DataSources.ParameterBinder.IsValueBinding(Value)) { return(Value); } object ValueResult = null; string expression = DataSources.ParameterBinder.GetBindingKey(Value); // rule 1, get the value directly from context.. ValueResult = context.RenderContext.DataContext.GetValue(expression); // TODO: this is new method... should be replaced by this only in the near future... if (ValueResult == null) { ValueResult = RenderContextHelper.GetValue(Key, Value, context.RenderContext); } if (ValueResult == null) { // rule 2, get the value as field value from all data objects... // first check the value that has the same type as the datamethod return type. ValueResult = GetValueByMethodReturnType(Key, Value, context); } if (ValueResult == null) { ValueResult = GetValueByNamingConvention(Key, Value, context); } return(ValueResult); }
public static object GetValueFromContext(string Key, string Value, RenderContext context) { //if (!DataSources.ParameterBinder.IsValueBinding(Value)) //{ // return Value; //} //object ValueResult = null; //string expression = DataSources.ParameterBinder.GetBindingKey(Value); //// rule 1, get the value directly from context.. //ValueResult = context.RenderContext.DataContext.GetValue(expression); //// TODO: this is new method... should be replaced by this only in the near future... //if (ValueResult == null) //{ // ValueResult = RenderContextHelper.GetValue(Key, Value, context.RenderContext); //} var ValueResult = RenderContextHelper.GetValue(Key, Value, context); //if (ValueResult == null) //{ // // rule 2, get the value as field value from all data objects... // // first check the value that has the same type as the datamethod return type. // ValueResult = GetValueByMethodReturnType(Key, Value, context); //} //if (ValueResult == null) //{ // ValueResult = GetValueByNamingConvention(Key, Value, context); //} // last try to id alternative. if (ValueResult == null) { //check for id == _id convertion. string lower = Key.ToLower(); if (lower == "_id") { ValueResult = context.DataContext.GetValue("id"); if (ValueResult == null) { ValueResult = RenderContextHelper.GetValue("{id}", Value, context); } } else if (lower == "id") { ValueResult = context.DataContext.GetValue("_id"); if (ValueResult == null) { ValueResult = RenderContextHelper.GetValue("{_id}", Value, context); } } } return(ValueResult); }