Showing posts with label API. Show all posts
Showing posts with label API. Show all posts

Monday, August 26, 2013

Convert all the (C#) types!

Well, almost all. So here is an incredible handy conversion class that I always carry around in all my projects. It has never failed me, never let me down... you get the idea. Although I cannot take full credit for it, thank Steven for the initial setup, I have done some minor tweaks in the past.

Usage is pretty straight forward. Call the (generic) method, put in a string in the correct format, converted and casted type comes out.

var value = Conversion.AsValue<int>("123"); 
//// Returns 123 as int

var value = Conversion.AsValue<int?>("123"); 
//// Returns 123 as nullable int

var value = Conversion.AsValue<int?>(""); 
//// Returns null (handy for webrequest parameters)

Monday, April 8, 2013

Improved compiletime supported validators

After a the initial post on the compile-time supporting webform validators, a few itches started to surface. Mainly the extendability and cleanliness. With some slight changes it was possible to categorize the validators (thus enforcing more of the Single Responsibility Principle).

Usage


The following code demonstrates the usage of this API. Note that there are breaking changes if you are replacing the previous version.
protected override void OnInit(EventArgs e)
{
    base.OnInit(e);

    this.UsernameField.Validation().RequiredField("username");
    this.PasswordField.Validation().RequiredField("password");
}
Read the original post for implementation details.

Thursday, January 6, 2011

ASP.NET Compile Time Supported Validators

UPDATED VERSION

Click here for the latest blog.

With.NET 3.5 extension methods were introduced, these methods provide a great way built features into 'closed' objects or doing a way of IOC.

Either way, the following example shows the usages a 'simple' validation framework. It provides extensions to validate web controls with compile time support. Which is quiet nice if don't have to write any markup code anymore.

Tuesday, November 30, 2010

Serialize to XML made a little easier

COVERAGE: XML Serialization, C#.
While digging, breaking and smashing around some code (aka refactoring), I found some redundant code that serialized and deserialized objects to files at various places. With a little effort a centralized helper class was created.

Wednesday, November 10, 2010

Creating compile time supported URLs

COVERAGE: ASP.Net C#, Microsoft AntiXss, LINQ, CuttingEdge Conditions.

When it comes to ASP.Net and linking to other pages it's a very lose system. Which is strange when you think about it. We're working in assemblies here, pages are classes and classes can have 'relations' with other classes and be supported by the compiler. Yet there are a lot of NavigateUrl's being filled with strings from either code or markup. Brrr.