public static ParametersSnapshot GetParameterSnapshotWithInnerObjects(this IParametrizedObject @this, string parentFieldName) { ParametersSnapshot result = @this.GetParametersSnapshot(parentFieldName); result.InnerSnapshots = @this .GetInnerParametrizedObjects() .Select(io => GetParameterSnapshotWithInnerObjects(io.ParametrizedObject, io.ParentFieldName)) .ToArray(); return(result); }
private static ParametersSnapshot GetParametersSnapshot(this IParametrizedObject @this, string parentFieldName) { ParametersSnapshot result = new ParametersSnapshot() { ParentFieldName = parentFieldName }; result.ParameterValues = @this .GetParameters() .Select(p => new ParameterValuePair() { Name = p.Field.Name, Value = (string)Convert.ChangeType(p.GetValue(), typeof(string), CultureInfo.InvariantCulture) }) .ToArray(); return(result); }
public static void SetParametersFromSnapshot(this IParametrizedObject @this, ParametersSnapshot snapshot) { Dictionary <string, string> parameterValues = snapshot.ParameterValues.ToDictionary(pvp => pvp.Name, pvp => pvp.Value); foreach (Parameter parameter in @this.GetParameters()) { if (parameterValues.ContainsKey(parameter.Field.Name)) { if (parameter.IsEnum) { parameter.SetValue(Enum.Parse(parameter.FieldType, parameterValues[parameter.Field.Name])); } else { parameter.SetValue(Convert.ChangeType(parameterValues[parameter.Field.Name], parameter.FieldType, CultureInfo.InvariantCulture)); } } } @this.ParametersChanged(); }
public static void SetParametersFromSnapshotWithInnerObjects(this IParametrizedObject @this, ParametersSnapshot snapshot) { @this.SetParametersFromSnapshot(snapshot); Dictionary <string, ParametersSnapshot> snapshots = snapshot.InnerSnapshots.ToDictionary(s => s.ParentFieldName, s => s); foreach (InnerParametrizedObject io in @this.GetInnerParametrizedObjects()) { if (snapshots.ContainsKey(io.ParentFieldName)) { io.ParametrizedObject.SetParametersFromSnapshotWithInnerObjects(snapshots[io.ParentFieldName]); } } @this.ParametersChanged(); }