static Func <TValue> MakeFieldValueGetter(IGraphElementModel model, string fieldName) { var target = model is IHasInspectorSurrogate hasInspectorSurrogate ? hasInspectorSurrogate.Surrogate : model; var fieldInfo = SerializedFieldsInspector.GetInspectableField(target, fieldName); if (fieldInfo != null) { Debug.Assert(typeof(TValue) == fieldInfo.FieldType); return(() => (TValue)fieldInfo.GetValue(target)); } return(null); }
/// <summary> /// Default command handler /// </summary> /// <param name="graphToolState">The state to modify.</param> /// <param name="command">The command to apply to the state.</param> public static void DefaultCommandHandler(GraphToolState graphToolState, SetModelFieldCommand command) { graphToolState.PushUndo(command); if (command.Models != null) { using (var updater = graphToolState.GraphViewState.UpdateScope) { foreach (var model in command.Models) { var target = model is IHasInspectorSurrogate hasInspectorSurrogate ? hasInspectorSurrogate.Surrogate : model; if (target != null) { var fieldInfo = SerializedFieldsInspector.GetInspectableField(target, command.FieldName); fieldInfo?.SetValue(target, command.Value); } } updater.MarkChanged(command.Models); } } }