private void HighlightDictionary(IDictionary value, string name, bool addAnnotation) { Type keyType; Type valueType; ContainerHelper.GetDictionaryTypes(value.GetType(), out keyType, out valueType); if (valueType == typeof(SetValueType)) { foreach (DictionaryEntry entry in value) { if (entry.Key is IGraphElement) { HighlightSingleValue(entry.Key, name, addAnnotation); } } } else { int cnt = 0; foreach (DictionaryEntry entry in value) { if (entry.Key is INode && entry.Value is INode) { HighlightMapping((INode)entry.Key, (INode)entry.Value, name, cnt, addAnnotation); ++cnt; } else { if (entry.Key is IGraphElement) { HighlightSingleValue(entry.Key, name + ".Domain -> " + EmitHelper.ToString(entry.Value, shellProcEnv.ProcEnv.NamedGraph), addAnnotation); } if (entry.Value is IGraphElement) { HighlightSingleValue(entry.Value, EmitHelper.ToString(entry.Key, shellProcEnv.ProcEnv.NamedGraph) + " -> " + name + ".Range", addAnnotation); } } } } }
public readonly IGraph _graph; // for ToString only public LGSPUndoAttributeChanged(IGraphElement elem, AttributeType attrType, AttributeChangeType changeType, Object newValue, Object keyValue, LGSPGraphProcessingEnvironment procEnv) { _elem = elem; _attrType = attrType; if (procEnv.graph is LGSPNamedGraph) { _name = ((LGSPNamedGraph)procEnv.graph).GetElementName(_elem); } else { _name = "?"; } _graph = procEnv.graph; if (_attrType.Kind == AttributeKind.SetAttr) { if (changeType == AttributeChangeType.PutElement) { IDictionary dict = (IDictionary)_elem.GetAttribute(_attrType.Name); if (dict.Contains(newValue)) { _undoOperation = UndoOperation.None; } else { _undoOperation = UndoOperation.RemoveElement; _value = newValue; } } else if (changeType == AttributeChangeType.RemoveElement) { IDictionary dict = (IDictionary)_elem.GetAttribute(_attrType.Name); if (dict.Contains(newValue)) { _undoOperation = UndoOperation.PutElement; _value = newValue; } else { _undoOperation = UndoOperation.None; } } else // Assign { Type keyType; Type valueType; IDictionary dict = ContainerHelper.GetDictionaryTypes( _elem.GetAttribute(_attrType.Name), out keyType, out valueType); IDictionary clonedDict = ContainerHelper.NewDictionary(keyType, valueType, dict); _undoOperation = UndoOperation.Assign; _value = clonedDict; } } else if (_attrType.Kind == AttributeKind.ArrayAttr) { if (changeType == AttributeChangeType.PutElement) { IList array = (IList)_elem.GetAttribute(_attrType.Name); _undoOperation = UndoOperation.RemoveElement; _keyOfValue = keyValue; } else if (changeType == AttributeChangeType.RemoveElement) { IList array = (IList)_elem.GetAttribute(_attrType.Name); _undoOperation = UndoOperation.PutElement; if (keyValue == null) { _value = array[array.Count - 1]; } else { _value = array[(int)keyValue]; _keyOfValue = keyValue; } } else if (changeType == AttributeChangeType.AssignElement) { IList array = (IList)_elem.GetAttribute(_attrType.Name); _undoOperation = UndoOperation.AssignElement; _value = array[(int)keyValue]; _keyOfValue = keyValue; } else // Assign { Type valueType; IList array = ContainerHelper.GetListType( _elem.GetAttribute(_attrType.Name), out valueType); IList clonedArray = ContainerHelper.NewList(valueType, array); _undoOperation = UndoOperation.Assign; _value = clonedArray; } } else if (_attrType.Kind == AttributeKind.DequeAttr) { if (changeType == AttributeChangeType.PutElement) { IDeque deque = (IDeque)_elem.GetAttribute(_attrType.Name); _undoOperation = UndoOperation.RemoveElement; _keyOfValue = keyValue; } else if (changeType == AttributeChangeType.RemoveElement) { IDeque deque = (IDeque)_elem.GetAttribute(_attrType.Name); _undoOperation = UndoOperation.PutElement; if (keyValue == null) { _value = deque.Front; } else { _value = deque[(int)keyValue]; _keyOfValue = keyValue; } } else if (changeType == AttributeChangeType.AssignElement) { IDeque deque = (IDeque)_elem.GetAttribute(_attrType.Name); _undoOperation = UndoOperation.AssignElement; _value = deque[(int)keyValue]; _keyOfValue = keyValue; } else // Assign { Type valueType; IDeque deque = ContainerHelper.GetDequeType( _elem.GetAttribute(_attrType.Name), out valueType); IDeque clonedDeque = ContainerHelper.NewDeque(valueType, deque); _undoOperation = UndoOperation.Assign; _value = clonedDeque; } } else if (_attrType.Kind == AttributeKind.MapAttr) { if (changeType == AttributeChangeType.PutElement) { IDictionary dict = (IDictionary)_elem.GetAttribute(_attrType.Name); if (dict.Contains(keyValue)) { if (dict[keyValue] == newValue) { _undoOperation = UndoOperation.None; } else { _undoOperation = UndoOperation.PutElement; _value = dict[keyValue]; _keyOfValue = keyValue; } } else { _undoOperation = UndoOperation.RemoveElement; _value = newValue; _keyOfValue = keyValue; } } else if (changeType == AttributeChangeType.RemoveElement) { IDictionary dict = (IDictionary)_elem.GetAttribute(_attrType.Name); if (dict.Contains(keyValue)) { _undoOperation = UndoOperation.PutElement; _value = dict[keyValue]; _keyOfValue = keyValue; } else { _undoOperation = UndoOperation.None; } } else if (changeType == AttributeChangeType.AssignElement) { IDictionary dict = (IDictionary)_elem.GetAttribute(_attrType.Name); if (dict[keyValue] == newValue) { _undoOperation = UndoOperation.None; } else { _undoOperation = UndoOperation.AssignElement; _value = dict[keyValue]; _keyOfValue = keyValue; } } else // Assign { Type keyType, valueType; IDictionary dict = ContainerHelper.GetDictionaryTypes( _elem.GetAttribute(_attrType.Name), out keyType, out valueType); IDictionary clonedDict = ContainerHelper.NewDictionary(keyType, valueType, dict); _undoOperation = UndoOperation.Assign; _value = clonedDict; } } else // Primitve Type Assign { _undoOperation = UndoOperation.Assign; _value = _elem.GetAttribute(_attrType.Name); } }
public string GetConstant(object constant) { if (constant is bool) { return((bool)constant == true ? "true" : "false"); } else if (constant is Enum) { Enum enumConst = (Enum)constant; return(enumConst.GetType().ToString() + "." + enumConst.ToString()); } else if (constant is IDictionary) { Type keyType; Type valueType; ContainerHelper.GetDictionaryTypes(constant, out keyType, out valueType); String srcType = "typeof(" + TypesHelper.PrefixedTypeFromType(keyType) + ")"; String dstType = "typeof(" + TypesHelper.PrefixedTypeFromType(valueType) + ")"; return("GRGEN_LIBGR.ContainerHelper.NewDictionary(" + srcType + "," + dstType + ")"); } else if (constant is IList) { Type valueType; ContainerHelper.GetListType(constant, out valueType); String dequeValueType = "typeof(" + TypesHelper.PrefixedTypeFromType(valueType) + ")"; return("GRGEN_LIBGR.ContainerHelper.NewList(" + dequeValueType + ")"); } else if (constant is IDeque) { Type valueType; ContainerHelper.GetDequeType(constant, out valueType); String dequeValueType = "typeof(" + TypesHelper.PrefixedTypeFromType(valueType) + ")"; return("GRGEN_LIBGR.ContainerHelper.NewDeque(" + dequeValueType + ")"); } else if (constant is string) { return("\"" + constant.ToString() + "\""); } else if (constant is float) { return(((float)constant).ToString(System.Globalization.CultureInfo.InvariantCulture) + "f"); } else if (constant is double) { return("((double)" + ((double)constant).ToString(System.Globalization.CultureInfo.InvariantCulture) + ")"); } else if (constant is sbyte) { return("((sbyte)" + constant.ToString() + ")"); } else if (constant is short) { return("((short)" + constant.ToString() + ")"); } else if (constant is long) { return("((long)" + constant.ToString() + ")"); } else if (constant is NodeType) { return("(GRGEN_LIBGR.TypesHelper.GetNodeType(\"" + constant + "\", graph.Model))"); } else if (constant is EdgeType) { return("(GRGEN_LIBGR.TypesHelper.GetEdgeType(\"" + constant + "\", graph.Model))"); } else { if (constant == null) { return("null"); } else { return(constant.ToString()); } } }