Tag Archives: coding

Date Validation in ASP.NET

No custom code needed… <asp:CompareValidator id=”dateValidator” runat=”server” Type=”Date” Operator=”DataTypeCheck” ControlToValidate=”dateTextbox” ErrorMessage=”The date you entered is not valid.”></asp:CompareValidator>

More Good Coding Practices

Don’t introduce ordering where not necessary. Be advised of more subtleties here than are visible at first glance. Consider enumerations; an enumeration value has a name and a code. The code is redundant and is probably there for optimization purposes; as such, you should not work with it. The code associated with a value is [...]

XmlSerializer Namespaces

If you worked with NHibernate mappings, you know very well about the namespace declarations on the root element: <hibernate-mapping xmlns=”urn:nhibernate-mapping-2.2″>. We generate these mappings programmatically, and we naturally wondered how to remove the default xmlns:xsd and xmlns:xsi declarations that the XmlSerializer adds, and add the NHibernate URN in the mix. The recipe below outlines the three necessary steps. [...]

.NET Extension Methods How-To

I had to learn the following simple steps for making an extensions method the hard way. You don’t have to. Procedure To write an extension method: Create a static class. Write a static method taking an object of the type being extended as first parameter. Add method parameters. Prepend the keyword this to this this [...]

Annotations and Attributes Are Evil

Relax, relax, they aren’t evil. They’re just misused, their misuse is easily promoted, and it can even come across as appealing. Spring enables AOP through annotations, Hibernate understands metadata specified as annotations, .NET’s XML serializer allows inline attributes to specify how to serialize an object’s properties, a certain JSON library does about the same thing [...]