locked
Is there any library to parse strings like "DateTime.Now() " into DateTime for Silverlight/

    Question

  • Is there any library to parse strings like "DateTime.Now() " into DateTime for Silverlight?

    We cannot Compile the string at runtime , since Compiler class has  limited access for Silverlight.

    Thanx and regards

    Amarnath Panda

    Wednesday, June 28, 2017 1:34 PM

All replies


  • Hi Amarnath Panda,

    >>Is there any library to parse strings like "DateTime.Now() " into DateTime for Silverlight?

    As far as I know, , NET framework does not have the library to parse strings like "DateTime.Now() " into DateTime.

    We will use the following code to parse strings into DateTime.

    DateTime.ParseExact Method (String, String, IFormatProvider)
    https://msdn.microsoft.com/en-us/library/w2sa9yss(v=vs.110).aspx

    If you need to deal with your special characters, you can customize the extension method to handle it.

     DateTime dt2= (DateTime)MoreConvert.ToDateTimeOrNull("DateTime.Now()");
    
     public static class MoreConvert
        {
            public static DateTime? ToDateTimeOrNull(string text)
            {
                return text == null || text != "DateTime.Now()" ? (DateTime?)null : DateTime.Now;
            }
        }

    Best Regards,

    Yohann Lu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, July 3, 2017 8:44 AM