why not to add TryParse method

Jul 10, 2011 at 3:37 PM

It will be cool it u will add new method TryParse that will get out string param and will  return try or false if parse success

Cuz if something wrong with my template i will get yellow screen of dead: http://my.jetscreenshot.com/2777/20110710-hane-146kb.jpg

Of cause i can use try and catch but still it will be cool to have it option

What do u think about?

Jul 14, 2011 at 7:41 PM

Should it return a bool? Or a collection of errors?

    if (Razor.TryParse(x, y, result).Count!=0) //something went wrong

Jul 14, 2011 at 8:43 PM
I think bool, cuz u wanna try parse and not just a parse

i will like datetime, DateTime.TryParse with out param?

-----Original message-----
From: grauenwolf
Sent: 14/07/2011, 9:42 pm
To: [email removed]
Subject: Re: why not to add TryParse method [razorengine:264585]


From: grauenwolf

Should it return a bool? Or a collection of errors? if (Razor.TryParse(x, y, result).Count!=0) //something went wrong

Coordinator
Jul 14, 2011 at 10:38 PM

By convention it should return a bool as to whether or not it was compiled as all TryParse methods I can think of return a bool.

You could have two overrides one that provides errors and one that doesn't

bool result = Razor.TryParse(code, out textResult, out errors);
bool result = Razor.TryParse(code, out textResult);

The idea sounds ok, but I think a try/catch/finally would probably be better suited and it's not hard to add. We'll have to get the next version of the RazorEngine out first because there are major changes coming.