public ReadContentAsDateTime ( ) : System.DateTime | ||
Résultat | System.DateTime |
public override DateTime ReadContentAsDateTime() { CheckAsync(); return(_coreReader.ReadContentAsDateTime()); }
private bool ReadinDate(XmlReader reader, Dictionary<DateTime, List<exRateDate>> theDates, DateTime LastReadDate) { DateTime rateDate = reader.ReadContentAsDateTime(); if (LastReadDate.CompareTo(rateDate) < 0) { List<exRateDate> theRates = new List<exRateDate>(); exRateDate newKey; Decimal theRate = 0m; while (reader.Read() && reader.HasAttributes) { if (reader.MoveToAttribute("currency")) { newKey = new exRateDate(rateDate, reader.ReadContentAsString()); if (reader.MoveToAttribute("rate")) { try { theRate = reader.ReadContentAsDecimal(); } catch { theRate = 0m; } } newKey.rate = theRate; theRates.Add(newKey); } } theDates.Add(rateDate, theRates); return true; } else return false; }
public virtual void ReadXml(System.Xml.XmlReader reader) { if (reader.ReadToDescendant("LotsOfData") == false) { throw new Exception("could not find the start of element LotsOfData"); } if (reader.ReadToDescendant("Boolean") == false) { throw new Exception("could not find the start of element Boolean"); } reader.Read(); if (reader.ReadContentAsBoolean() == false) { throw new Exception("did not find the correct value in Boolean"); } //DateTime if (reader.ReadToNextSibling("DateTime") == false) { throw new Exception("could not find the start of element DateTime"); } reader.Read(); DateTime now = reader.ReadContentAsDateTime(); if (now != Now) { TimeSpan diff = new TimeSpan((now.Ticks - Now.Ticks)); if (diff.TotalMilliseconds > 1000) { // seconds are lost in Xml throw new Exception(String.Format("Dates differ {0} {1} Ticks {2}", now, Now, (now.Ticks - Now.Ticks))); } } //DecimalValue if (reader.ReadToNextSibling("DecimalValue") == false) { throw new Exception("could not find the start of element DecimalValue"); } // reader.Read(); decimal decimalValue = (decimal)reader.ReadElementContentAs(typeof(decimal), null); if (decimalValue != CommonUtilities.DecimalValue) { string msg = String.Format("different decimal Values {0} {1}", decimalValue, CommonUtilities.DecimalValue); throw new Exception(msg); } //DoubleValue if (reader.NodeType != System.Xml.XmlNodeType.Element && reader.Name != "DoubleValue") { if (reader.ReadToNextSibling("DoubleValue") == false) { throw new Exception("could not find the start of element DoubleValue"); } } //reader.Read(); double doubleValue = (double)reader.ReadElementContentAsDouble(); if (doubleValue != CommonUtilities.DoubleValue) { string msg = String.Format("different double Values {0} {1}", doubleValue, CommonUtilities.DoubleValue); throw new Exception(msg); } //FloatValue if (reader.NodeType != System.Xml.XmlNodeType.Element && reader.Name != "FloatValue") { if (reader.ReadToNextSibling("FloatValue") == false) { throw new Exception("could not find the start of element FloatValue"); } } //reader.Read(); float floatValue = (float)reader.ReadElementContentAs(typeof(float), null); if (floatValue != CommonUtilities.FloatValue) { string msg = String.Format("different floatValue Values {0} {1}", floatValue, CommonUtilities.FloatValue); throw new MyException(msg); } //IntValue if (reader.NodeType != System.Xml.XmlNodeType.Element && reader.Name != "IntValue") { if (reader.ReadToNextSibling("IntValue") == false) { throw new Exception("could not find the start of element IntValue"); } } // reader.Read(); int intValue = reader.ReadElementContentAsInt(); if (intValue != CommonUtilities.IntValue) { string msg = String.Format("different intValue Values {0} {1}", intValue, CommonUtilities.IntValue); throw new MyException(msg); } //LongValue if (reader.NodeType != System.Xml.XmlNodeType.Element && reader.Name != "LongValue") { if (reader.ReadToNextSibling("LongValue") == false) { throw new Exception("could not find the start of element LongValue"); } } //reader.Read(); long longValue = (long)reader.ReadElementContentAs(typeof(long), null); if (longValue != CommonUtilities.LongValue) { string msg = String.Format("different longValue Values {0} {1}", longValue, CommonUtilities.LongValue); throw new MyException(msg); } //Object if (reader.NodeType != System.Xml.XmlNodeType.Element && reader.Name != "Object") { if (reader.ReadToNextSibling("Object") == false) { throw new MyException("could not find the start of element Object"); } } //reader.Read(); TimeSpan objectValue = (TimeSpan)reader.ReadElementContentAs(typeof(TimeSpan), null); if (objectValue != CommonUtilities.TimeSpanValue) { string msg = String.Format("different objectValue Values {0} {1}", objectValue, CommonUtilities.TimeSpanValue); throw new MyException(msg); } //StringValue if (reader.NodeType != System.Xml.XmlNodeType.Element && reader.Name != "StringValue") { if (reader.ReadToNextSibling("StringValue") == false) { throw new MyException("could not find the start of element StringValue"); } } //reader.Read(); string stringValue = reader.ReadElementContentAsString(); if (stringValue == null || stringValue.Equals(CommonUtilities.XmlStringForAttributes) == false) { string msg = String.Format("different stringValue Values {0} {1}", stringValue, CommonUtilities.XmlStringForAttributes); throw new MyException(msg); } int counter = 0; const int NODES_AT_END = 1; while (reader.Read()) { counter++; } if (counter != NODES_AT_END) { throw new MyException(String.Format("expected {0} nodes, but found {1}", NODES_AT_END, counter)); } }
void IXmlSerializable.ReadXml(System.Xml.XmlReader reader) { LinkItem item = new LinkItem(); while (reader.IsStartElement()) { reader.MoveToContent(); reader.Read(); if (reader.IsStartElement("Id")) { reader.MoveToContent(); item.Id = int.Parse(reader.ReadString()); reader.MoveToContent(); reader.ReadEndElement(); } else { throw new XmlException("ExpectedElementMissing: Id element was expected."); } if (reader.IsStartElement("Title")) { reader.MoveToContent(); item.Title = reader.ReadString(); reader.MoveToContent(); reader.ReadEndElement(); } else { throw new XmlException("ExpectedElementMissing: Title element was expected."); } if (reader.IsStartElement("Description")) { reader.MoveToContent(); item.Description = reader.ReadString(); reader.MoveToContent(); reader.ReadEndElement(); } else { throw new XmlException("ExpectedElementMissing: Description element was expected."); } if (reader.IsStartElement("DateStart")) { reader.MoveToContent(); reader.Read(); item.DateStart = reader.ReadContentAsDateTime(); reader.MoveToContent(); reader.ReadEndElement(); } else { throw new XmlException("ExpectedElementMissing: DateStart element was expected."); } if (reader.IsStartElement("DateEnd")) { reader.MoveToContent(); reader.Read(); item.DateEnd = reader.ReadContentAsDateTime(); reader.MoveToContent(); reader.ReadEndElement(); } // optional if (reader.IsStartElement("Url")) { reader.MoveToContent(); item.Url = reader.ReadString(); reader.MoveToContent(); reader.ReadEndElement(); } else { throw new XmlException("ExpectedElementMissing: Url element was expected."); } reader.MoveToContent(); reader.ReadEndElement(); } this.m_linkItem = item; }
private static TableStorageField ToObject(XmlReader reader, string edmType, bool isNull, string propertyName) { object value; Type dataType; string formatString; if(edmType == TableStorageConstants.Edm.TYPE_BINARY) { if(isNull) { value = DBNull.Value; } else { using(Stream stream = new MemoryStream()) { const int size = 256; byte[] buffer = new byte[size]; int count; while((count = reader.ReadContentAsBase64(buffer, 0, size)) > 0) { stream.Write(buffer, 0, count); } stream.Seek(0, SeekOrigin.Begin); value = stream; } } dataType = typeof(byte[]); formatString = "{0}"; } else if(edmType == TableStorageConstants.Edm.TYPE_BOOLEAN) { if(isNull) { value = DBNull.Value; } else { value = reader.ReadContentAsBoolean(); } dataType = typeof(bool); formatString = "{0}"; } else if(edmType == TableStorageConstants.Edm.TYPE_DATETIME) { if(isNull) { value = DBNull.Value; } else { value = reader.ReadContentAsDateTime(); } dataType = typeof(DateTime); formatString = TableStorageConstants.Edm.DATE_TIME_FORMAT; } else if(edmType == TableStorageConstants.Edm.TYPE_DOUBLE) { if(isNull) { value = DBNull.Value; } else { value = reader.ReadContentAsDouble(); } dataType = typeof(double); formatString = "{0}"; } else if(edmType == TableStorageConstants.Edm.TYPE_GUID) { if(isNull) { value = DBNull.Value; } else { value = Guid.Parse(reader.ReadContentAsString()); } dataType = typeof(Guid); formatString = "{0:D}"; } else if(edmType == TableStorageConstants.Edm.TYPE_INT) { if(isNull) { value = DBNull.Value; } else { value = reader.ReadContentAsInt(); } dataType = typeof(int); formatString = "{0}"; } else if(edmType == TableStorageConstants.Edm.TYPE_LONG) { if(isNull) { value = DBNull.Value; } else { value = reader.ReadContentAsLong(); } dataType = typeof(long); formatString = "{0}"; } else if(StringComparer.OrdinalIgnoreCase.Equals(TableStorageConstants.Edm.TYPE_STRING, edmType)) { if(isNull) { value = DBNull.Value; } else { value = reader.ReadContentAsString(); } dataType = typeof(string); formatString = "{0}"; } else { throw new TableStorageException(string.Format("The type, '{0},' is not supported.", edmType)); } return new TableStorageField(value, edmType, propertyName, isNull, dataType, formatString); }