[Mono-dev] Replicating System.Web.Script.Serialization bugs

Vladimir Giszpenc vgiszpenc at dsci.com
Mon Oct 15 07:57:47 EDT 2007


My apologies for being nosy, but if performance is what you preach, using
"as" is even better...

String s = obj as string;
If (string.IsNullOrEmpty(s))
{
	return null;
}

> 3. Please commit the code below for performance reasons.
> a. 'is' and casting are much cheaper.
> b. don't need to create an instance, returning null should be OK, isn't?
> 
> +                       /*
> +                        * Take care of the special case whereas in JSON
> an empty string ("") really means
> +                        * an empty value
> +                        * (see:
> https://bugzilla.novell.com/show_bug.cgi?id=328836)
> +                        */
> +                       if ( (type.IsGenericType) &&
> (type.GetGenericTypeDefinition() == typeof(Nullable<>)) )
> +                       {
> +                               if ( (obj is String) &&
> (((String)obj).Length == 0) )
> +                               {
> +                                       return null;
> +                               }
> +                       }
> +

Vladimir Giszpenc

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3329 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20071015/46478a4e/attachment.bin 


More information about the Mono-devel-list mailing list