void WriteDefaultDouble(GeometryToken geometryToken, double val, double defaultValue) { if (val != defaultValue) { WriteAttribute(geometryToken, DoubleToString(val)); } }
static internal string FirstCharToLower(GeometryToken attrKind) { var attrString = attrKind.ToString(); attrString = attrString.Substring(0, 1).ToLowerInvariant() + attrString.Substring(1, attrString.Length - 1); return(attrString); }
void WriteBorderInfo(GeometryToken token, BorderInfo borderInfo) { WriteStartElement(token); WriteAttribute(GeometryToken.InnerMargin, borderInfo.InnerMargin); WriteAttribute(GeometryToken.FixedPosition, borderInfo.FixedPosition); WriteAttribute(GeometryToken.Weight, borderInfo.Weight); WriteEndElement(); }
void WriteAttribute(GeometryToken attrKind, object val) { var attrString = FirstCharToLower(attrKind); if (val is Point) { XmlWriter.WriteAttributeString(attrString, PointToString((Point)val)); } else if (val is Double) { XmlWriter.WriteAttributeString(attrString, DoubleToString((double)val)); } else { XmlWriter.WriteAttributeString(attrString, val.ToString()); } }
//static void WriteStartElement(XmlWriter writer, Tokens token) { // writer.WriteStartElement(token.ToString()); //} /// <summary> /// WriteStringElement with double /// </summary> /// <param name="tokens"></param> /// <param name="element"></param> void WriteStringElement(GeometryToken tokens, double element) { XmlWriter.WriteElementString(tokens.ToString(), XmlConvert.ToString(element)); }
/// <summary> /// writes the starte element with the token /// </summary> /// <param name="token"></param> void WriteStartElement(GeometryToken token) { XmlWriter.WriteStartElement(FirstCharToLower(token)); }
private void WritePointElement(GeometryToken siteV, Point point) { //XmlWriter.WriteAttributeString("pt",point.X.ToString() +","+point.Y.ToString()); XmlWriter.WriteElementString("pt", PointToString(point)); }
bool TryGetAttribute(GeometryToken token, out string val) { return (val = GetAttribute(token)) != null; }
/// <summary> /// writes the starte element with the token /// </summary> /// <param name="token"></param> void WriteStartElement(GeometryToken token) { XmlWriter.WriteStartElement( FirstCharToLower( token)); }
void WriteAttribute(GeometryToken attrKind, object val) { var attrString = FirstCharToLower(attrKind); if (val is Point) XmlWriter.WriteAttributeString(attrString, PointToString((Point) val)); else if (val is Double) XmlWriter.WriteAttributeString(attrString, DoubleToString((double) val)); else XmlWriter.WriteAttributeString(attrString, val.ToString()); }
double GetDoubleAttribute(GeometryToken token) { var val = GetAttribute(token); if (val == null) Error(String.Format("attribute {0} not found", token)); double ret; if (double.TryParse(val, out ret)) return ret; Error("cannot parse an int value " + val); return 0; }
bool TokenIs(GeometryToken t) { return XmlReader.IsStartElement(GeometryGraphWriter.FirstCharToLower(t)) || XmlReader.IsStartElement(t.ToString()); }
Point TryGetPointAttribute(GeometryToken token) { string val = GetAttribute(token); return val == null ? new Point() : ParsePoint(val); }
int GetIntAttributeOrDefault(GeometryToken token, int defaultVal) { string val = GetAttribute(token); if (val == null) return defaultVal; int ret; if (int.TryParse(val, out ret)) return ret; Error("cannot parse a bool value " + val); return 0; }
bool GetBoolAttributeOrDefault(GeometryToken token, bool defaultVal) { string val = GetAttribute(token); if (val == null) return defaultVal; bool ret; if (bool.TryParse(val, out ret)) return ret; Error("cannot parse a bool value " + val); return false; }
double GetDoubleAttributeOrDefault(GeometryToken token, double defaultVal) { string val = GetAttribute(token); if (val == null) return defaultVal; double ret; if (double.TryParse(val, out ret)) return ret; Error("cannot parse a double value " + val); return 0; }
///<summary> ///used only in Debug configuration ///<param name="token">the token that should be here</param> ///</summary> void CheckToken(GeometryToken token) { if (!XmlReader.IsStartElement(GeometryGraphWriter.FirstCharToLower(token)) && !XmlReader.IsStartElement(token.ToString())) { string positionInfo = GetPositionInfo(); throw new InvalidDataException( String.Format(CultureInfo.InvariantCulture, "expected {0}, {1}", token, positionInfo)); } }
string GetMustAttribute(GeometryToken token) { var s = GeometryGraphWriter.FirstCharToLower(token); var ret = XmlReader.GetAttribute(GeometryGraphWriter.FirstCharToLower(token)); if (ret != null) return ret; Error("attribute " + s + " not found"); return null; }
bool ReadBooleanElement(GeometryToken tokens) { CheckToken(tokens); return ReadElementContentAsBoolean(); }
int ReadIntElement(GeometryToken token) { CheckToken(token); return ReadElementContentAsInt(); }
void WriteDefaultDouble(GeometryToken geometryToken, double val, double defaultValue) { if (val != defaultValue) WriteAttribute(geometryToken, DoubleToString(val)); }
BorderInfo ReadBorderInfo(GeometryToken token) { XmlRead(); CheckToken(token); var bi = new BorderInfo { InnerMargin = GetDoubleAttribute(GeometryToken.InnerMargin), FixedPosition = GetDoubleAttribute(GeometryToken.FixedPosition), Weight = GetDoubleAttribute(GeometryToken.Weight) }; return bi; }
static internal string FirstCharToLower(GeometryToken attrKind) { var attrString = attrKind.ToString(); attrString = attrString.Substring(0, 1).ToLower(CultureInfo.InvariantCulture) + attrString.Substring(1, attrString.Length - 1); return attrString; }
void WriteStringElement(GeometryToken tokens, bool b) { XmlWriter.WriteElementString(tokens.ToString(), XmlConvert.ToString(b)); }
string GetAttribute(GeometryToken token) { return XmlReader.GetAttribute(GeometryGraphWriter.FirstCharToLower(token)); }