public void SetValue(IScriptExpressionNameResolver 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] + "'");
}
}
}