November, 2009 Archives
Nov
How to change username in Google Wave
by Mikael Lundin in Other
When I was invited to Google Wave a horrible user name was created for me, because I once choose to sign up for an gmail address with that name just to test GMail spam filter against some subscription functionality I was currently developing.
This got me to research how to change the username that is given and I found the following solution.
Edit your profile
Go to your google profile and press Edit Profile. If you’re not logged in you’ll have to authenticate yourself.
At the bottom of this page you should be able to change your profile URL. When you do this you will also change your username inside Google Wave. It required a restart of my browser before the change went through. I’m not sure if it was just a delay or if they caches your user name with Google Gears or some similar technology.
* Note: I did not loose any waves or contacts that I’d set up before the change.
Happy Waving! You may now reach me at mikael.lundin82@googlewave.com.
Nov
Data Annotations
by Mikael Lundin in Programming
I’ve recently discovered the System.ComponentModel.DataAnnotations namespace. This is a collection of Attributes you can use to markup your data objects with conditions, like the following.
public class Person
{
[StringLength(20), Required(ErrorMessage = "Name is a required property")]
public string Name { get; set; }
[Range(0, 150)]
public int Age { get; set; }
[RegularExpression(@"(?i:^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$)")]
public string Email { get; set; }
}
Let’s say that you use this Person object to store user input, you can easily validate that input meets the requirements of the annotations.
var person = new Person
{
Name = "John Doe",
Age = 54,
Email = "john.doe@aol.com"
};
/* Validate */
var result = person.ValidateAnnotations();
What I find even more interesting is that you can annotate a contract and just let your model object inherit the annotations. Consider the following.
[MetadataType(typeof(IPerson))]
public class Person : IPerson
{
public string Name { get; set; }
public int Age { get; set; }
public string Email { get; set; }
}
public interface IPerson
{
[StringLength(20), Required(ErrorMessage = "Name is a required property")]
string Name { get; set; }
[Range(0, 150)]
int Age { get; set; }
[RegularExpression(@"(?i:^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$)")]
string Email { get; set; }
}
Now that’s hot! The annotations are actually part of the interface IPerson that specifies what an IPerson is. Then the concrete Person class just implements that contract. Neat!
My validating extension method and some tests can be downloaded from here. Enjoy!