public void SetValue(ScriptTriggerAction nameResolver, object value) { BindingFlags flags = BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Instance; object obj = nameResolver.ResolveName(_parts[0]); for (int i = 1; i < _parts.Length; i++) { PropertyInfo pi = obj.GetType().GetProperty(_parts[i], flags); if (pi != null) { if (i == _parts.Length - 1) { if ((value == null) || (pi.PropertyType.IsAssignableFrom(value.GetType()) == false)) { value = Convert.ChangeType(value, pi.PropertyType, CultureInfo.CurrentCulture); } pi.SetValue(obj, value, null); } else { obj = pi.GetValue(obj, null); } } else { throw new InvalidOperationException("Unknown property '" + _parts[i] + "'"); } } }
public object GetValue(ScriptTriggerAction nameResolver) { object value = nameResolver.ResolveName(_parts[0]); if (_parts.Length != 1) { BindingFlags flags = BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Instance; for (int i = 1; i < _parts.Length; i++) { PropertyInfo pi = value.GetType().GetProperty(_parts[i], flags); if (pi != null) { value = pi.GetValue(value, null); } else { throw new InvalidOperationException("Unknown property '" + _parts[i] + "'"); } } } return(value); }
public void Execute(ScriptTriggerAction nameResolver) { object value = _rhs.GetValue(nameResolver); if (_lhs != null) { ((PropertyAccessExpression)_lhs).SetValue(nameResolver, value); } }
/// <internalonly /> public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { string s = value as string; if (String.IsNullOrEmpty(s) == false) { ScriptTriggerAction scriptAction = ScriptTriggerAction.Parse(s); if (scriptAction == null) { throw new InvalidOperationException("Unable to parse the script expression '" + s + "' as a valid script action."); } return(scriptAction); } return(null); }
public object GetValue(ScriptTriggerAction nameResolver) { object value = null; BindingFlags flags = BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Instance; object obj = nameResolver.ResolveName(_parts[0]); for (int i = 1; i < _parts.Length; i++) { if (i == _parts.Length - 1) { MethodInfo mi = obj.GetType().GetMethod(_parts[i], flags); if (mi == null) { throw new InvalidOperationException("Unknown method '" + _parts[i] + "'"); } object[] paramValues = null; if (_parameters != null) { ParameterInfo[] paramInfos = mi.GetParameters(); if (_parameters.Count != paramInfos.Length) { throw new InvalidOperationException("Parameter count mismatch for method '" + _parts[i] + "'"); } paramValues = new object[_parameters.Count]; for (int j = 0; j < paramValues.Length; j++) { object paramValue = _parameters[j].GetValue(nameResolver); if ((paramValue == null) || (paramInfos[j].ParameterType.IsAssignableFrom(paramValue.GetType()) == false)) { paramValue = Convert.ChangeType(paramValue, paramInfos[j].ParameterType, CultureInfo.CurrentCulture); } paramValues[j] = paramValue; } } value = mi.Invoke(obj, paramValues); } else { PropertyInfo pi = obj.GetType().GetProperty(_parts[i], flags); if (pi != null) { obj = pi.GetValue(obj, null); } else { throw new InvalidOperationException("Unknown property '" + _parts[i] + "'"); } } } return(value); }
public object GetValue(ScriptTriggerAction nameResolver) { return(_value); }