Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Boyd 2 posts 22 karma points
    Sep 14, 2011 @ 22:18
    Boyd
    0

    Textstring being returned as a datetime.

    We are storing a simple textstring property with the following format: ##-### or 12-377. We'll say this property has an alias of prop.

    We then load the node as follows:

    dynamic node= new DynamicNode(nodeId)

    and try and retrieve the data as follows:

    string propValue = node.prop;

    An exception is thrown because somehow the value is being interpreted as a date. When clearly it is not. I created a test and I know that dynamic alone will not auto convert a string with this format to a date so it has to be something wrong with dynamic node. Can we confirm that this is a bug? Is there another solution where we can store a 'string' and not have it's value automatically converted?

    I'm having to use getproperty as a workaround, but I don't like workarounds, especially not in this case. This is clearly an issue that could very easily bite us again. I don't want to be afraid that just because of how something is stored that it could potentially break. It's a textstring, there is no reason for dynamicnode to be looking into it's contents to figure out what it is and change it's type.

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Sep 14, 2011 @ 22:19
    Sebastiaan Janssen
    0

    You can get the pure text in 4.7.0 by using:

    @Model.GetProperty("propName").Value

    or in 4.7.1:

    @Model.GetPropertyValue("propName")

    These are not really workarounds, but intended behaviour. Part of doing ducktyping / dynamic typing is that sometimes it'll be wrong. If you need to do your own typing, GetProperty(Value) needs to be used.

  • Boyd 2 posts 22 karma points
    Sep 14, 2011 @ 22:55
    Boyd
    0

    Damnit I accidentally clicked the solved button. This is in fact not helpful. As I mentioned already this exact 'workaround' above.

    However our sites are already coded with a different pattern and at any time they could go up in smoke because dynamic node is broken. 

    What I was looking for, if I was not explicit enough, is how I can set a datatype to return exactly as a string and not something else entirely.

    If its possible, please 'unsolve' this issue. 

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Sep 14, 2011 @ 23:02
    Sebastiaan Janssen
    0

    Sorry, both are not possible. You CAN, however change your razor scripts and turn everything into GetProperty instead of Model.propName.. That would make 100% sure that this doesn't happen again.

Please Sign in or register to post replies

Write your reply to:

Draft