0

In an XML that I am parsing, I have the following:

<event>
    <book>Felicity Fly</book>
    <author>Christina Gabbitas</author>
    <bookImgUrl>http://www.whsmith.co.uk/Images/Products\957\255\9780957255203_t_f.jpg</bookImgUrl>
    <info>Christina Gabbitas will be signing copies of her new book, Felicity Fly. Books should be bought from WHSmith. Proof of purchase may be necessary</info>
    <date>20 Apr 2013</date>
    <startTime>10:30</startTime>
    <location>
        <name>WHSmith Chester</name>
        <address>5-7 Foregate Street</address>
        <city>Chester</city>
        <county>Cheshire</county>
        <postcode>CH1 1HH</postcode>
        <tel>01244 321106</tel>
    </location>
</event>

I want to create a DateTime object from the two nodes <date> and <startTime>. So I am doing this:

var EventEntity = new Event()
{
    Book = e.Book,
    BookImgUrl = e.BookImgUrl,
    Info = e.Info,
    Start = new DateTime().**?**
};

But When I press the dot [.] after the DateTime object, I am not getting the Parse method from Intellisense, why is this? What am I doing wrong?

I was planning on using the solution outlined in this post.

Community
  • 1
  • 1
J86
  • 14,345
  • 47
  • 130
  • 228

1 Answers1

1

Parse is a static method but you are calling it as it were an instance method. You should call it in this way:

var EventEntity = new Event()
{
    Book = e.Book,
    BookImgUrl = e.BookImgUrl,
    Info = e.Info,
    Start = DateTime.ParseExact(...) // or DateTime.TryParseExact(...)
};
Daniele Armanasco
  • 7,289
  • 9
  • 43
  • 55
  • Thank You Daniele. And will this format be correct `"dd MMM YYYY HH:mm"` if I add my date and startTime with a space in between them? – J86 Apr 12 '13 at 12:04
  • I meant if I concatenate my `date` and `startTime` with a blank space between them. – J86 Apr 12 '13 at 12:11
  • I haven't tried the format, but it sounds good to me. You have to pay attention to the culture, otherwise your month will not be parsed correctly (InvariantCulture is not mean to work for everything; there are some posts about it ...) – Daniele Armanasco Apr 12 '13 at 12:17