protected void Validate(ExprLeaf exprLeaf) { this.ValidateBase((ExprItem)exprLeaf); Invariant(exprLeaf.Item != null, string.Format(CommonStrings.XMustNotBeNull, "ExprLeaf.Item")); Invariant(exprLeaf.ReferenceType != null, string.Format(CommonStrings.XMustNotBeNull, "ExprLeaf.ReferenceType")); }
private void ReadXml(ExprLeaf exprLeaf) { reader.ReadStartElement(); reader.MoveToContent(); this.ReadXmlBase((ExprItem)exprLeaf); if (reader.LocalName != "item") throw new InvalidXmlException("item", reader.LocalName); exprLeaf.Item = GetAnyObject(exprLeaf.Type, reader.LocalName); reader.MoveToContent(); if (reader.LocalName != "reference_type") throw new InvalidXmlException("reference_type", reader.LocalName); exprLeaf.ReferenceType = reader.ReadElementContentAsString("reference_type", OpenEhrNamespace); reader.MoveToContent(); reader.ReadEndElement(); reader.MoveToContent(); }
internal static ExprItem ExprItem(string typeName) { DesignByContract.Check.Require(!string.IsNullOrEmpty(typeName), string.Format(CommonStrings.XMustNotBeNullOrEmpty, "typeName")); ExprItem exprItem = null; switch (typeName) { case "EXPR_LEAF": exprItem = new ExprLeaf(); break; case "EXPR_UNARY_OPERATOR": exprItem = new ExprUnaryOperator(); break; case "EXPR_BINARY_OPERATOR": exprItem = new ExprBinaryOperator(); break; default: throw new NotSupportedException("type not supported: " + typeName); } DesignByContract.Check.Ensure(exprItem != null, "exprItem must not be null."); return exprItem; }
private void WriteXml(ExprLeaf exprItem) { Check.Require(exprItem.Item != null, string.Format(CommonStrings.XMustNotBeNull, "exprItem.Item")); Check.Require(!string.IsNullOrEmpty(exprItem.ReferenceType), string.Format(CommonStrings.XMustNotBeNullOrEmpty, "exprItem.ReferenceType")); this.WriteXmlBase((ExprItem)exprItem); writer.WriteStartElement(UseOpenEhrPrefix(writer), "item", OpenEhrNamespace); string itemType = exprItem.Type; if (itemType.StartsWith("C_")) { writer.WriteAttributeString(UseXsiPrefix(writer), "type", XsiNamespace, itemType); } else { itemType = UseXsdPrefix(writer) + ":" + itemType.ToLower(); writer.WriteAttributeString(UseXsiPrefix(writer), "type", XsiNamespace, itemType); } if (exprItem.Item is CPrimitive) this.WriteXml((CPrimitive)(exprItem.Item)); else { if (exprItem.Type.ToLower() == "boolean") writer.WriteString(exprItem.Item.ToString().ToLower()); else writer.WriteString(exprItem.Item.ToString()); } writer.WriteEndElement(); writer.WriteElementString(UseOpenEhrPrefix(writer), "reference_type", OpenEhrNamespace, exprItem.ReferenceType); }