/// <summary> /// Returns the name of the kind /// </summary> /// <returns>The name of the kind of the attribute</returns> public String GetKindName() { switch (Kind) { case AttributeKind.EnumAttr: return(EnumType.PackagePrefixedName); case AttributeKind.MapAttr: return("map<" + KeyType.GetKindName() + "," + ValueType.GetKindName() + ">"); case AttributeKind.SetAttr: return("set<" + ValueType.GetKindName() + ">"); case AttributeKind.ArrayAttr: return("array<" + ValueType.GetKindName() + ">"); case AttributeKind.DequeAttr: return("deque<" + ValueType.GetKindName() + ">"); case AttributeKind.NodeAttr: return(PackagePrefixedTypeName); case AttributeKind.EdgeAttr: return(PackagePrefixedTypeName); } return(GetKindName(Kind)); }
/// <summary> /// Emits the attribute value as code /// for an attribute of the given type with the given value into the stream writer /// </summary> public static void EmitAttribute(AttributeType attrType, object value, INamedGraph graph, StreamWriter sw) { if (attrType.Kind == AttributeKind.SetAttr) { IDictionary set = (IDictionary)value; sw.Write("{0}{{", attrType.GetKindName()); bool first = true; foreach (DictionaryEntry entry in set) { if (first) { sw.Write(ToString(entry.Key, attrType.ValueType, graph)); first = false; } else { sw.Write("," + ToString(entry.Key, attrType.ValueType, graph)); } } sw.Write("}"); } else if (attrType.Kind == AttributeKind.MapAttr) { IDictionary map = (IDictionary)value; sw.Write("{0}{{", attrType.GetKindName()); bool first = true; foreach (DictionaryEntry entry in map) { if (first) { sw.Write(ToString(entry.Key, attrType.KeyType, graph) + "->" + ToString(entry.Value, attrType.ValueType, graph)); first = false; } else { sw.Write("," + ToString(entry.Key, attrType.KeyType, graph) + "->" + ToString(entry.Value, attrType.ValueType, graph)); } } sw.Write("}"); } else if (attrType.Kind == AttributeKind.ArrayAttr) { IList array = (IList)value; sw.Write("{0}[", attrType.GetKindName()); bool first = true; foreach (object entry in array) { if (first) { sw.Write(ToString(entry, attrType.ValueType, graph)); first = false; } else { sw.Write("," + ToString(entry, attrType.ValueType, graph)); } } sw.Write("]"); } else if (attrType.Kind == AttributeKind.DequeAttr) { IDeque deque = (IDeque)value; sw.Write("{0}]", attrType.GetKindName()); bool first = true; foreach (object entry in deque) { if (first) { sw.Write(ToString(entry, attrType.ValueType, graph)); first = false; } else { sw.Write("," + ToString(entry, attrType.ValueType, graph)); } } sw.Write("["); } else { sw.Write("{0}", ToString(value, attrType, graph)); } }
/// <summary> /// Emits the attribute value as code /// for an attribute of the given type with the given value into the stream writer /// Main graph context is needed to get access to the graph -> env dictionary. /// </summary> public static void EmitAttribute(MainGraphExportContext mainGraphContext, AttributeType attrType, object value, INamedGraph graph, StreamWriter sw, StringBuilder deferredInits) { if (attrType.Kind == AttributeKind.SetAttr) { IDictionary set = (IDictionary)value; sw.Write("{0}{{", attrType.GetKindName()); bool first = true; foreach (DictionaryEntry entry in set) { if (first) { EmitAttributeValue(mainGraphContext, entry.Key, attrType.ValueType, graph, sw, deferredInits); first = false; } else { sw.Write(","); EmitAttributeValue(mainGraphContext, entry.Key, attrType.ValueType, graph, sw, deferredInits); } } sw.Write("}"); } else if (attrType.Kind == AttributeKind.MapAttr) { IDictionary map = (IDictionary)value; sw.Write("{0}{{", attrType.GetKindName()); bool first = true; foreach (DictionaryEntry entry in map) { if (first) { EmitAttributeValue(mainGraphContext, entry.Key, attrType.KeyType, graph, sw, deferredInits); sw.Write("->"); EmitAttributeValue(mainGraphContext, entry.Value, attrType.ValueType, graph, sw, deferredInits); first = false; } else { sw.Write(","); EmitAttributeValue(mainGraphContext, entry.Key, attrType.KeyType, graph, sw, deferredInits); sw.Write("->"); EmitAttributeValue(mainGraphContext, entry.Value, attrType.ValueType, graph, sw, deferredInits); } } sw.Write("}"); } else if (attrType.Kind == AttributeKind.ArrayAttr) { IList array = (IList)value; sw.Write("{0}[", attrType.GetKindName()); bool first = true; foreach (object entry in array) { if (first) { EmitAttributeValue(mainGraphContext, entry, attrType.ValueType, graph, sw, deferredInits); first = false; } else { sw.Write(","); EmitAttributeValue(mainGraphContext, entry, attrType.ValueType, graph, sw, deferredInits); } } sw.Write("]"); } else if (attrType.Kind == AttributeKind.DequeAttr) { IDeque deque = (IDeque)value; sw.Write("{0}[", attrType.GetKindName()); bool first = true; foreach (object entry in deque) { if (first) { EmitAttributeValue(mainGraphContext, entry, attrType.ValueType, graph, sw, deferredInits); first = false; } else { sw.Write(","); EmitAttributeValue(mainGraphContext, entry, attrType.ValueType, graph, sw, deferredInits); } } sw.Write("]"); } else { EmitAttributeValue(mainGraphContext, value, attrType, graph, sw, deferredInits); } }