C#

Sample Code for Getting the User Location based on the IP Address

Yesterday I introduced a free service to get the location of the IP Address. If you haven’t read it, go on read that first (it’s very short, I promise). So here I am today, showing you my small .NET API to abstract the XML returned by the service. First we need an object to hold the data. I called it UserLocation. 1: public class UserLocation 2: { 3: public string City...

posted @ Thursday, September 03, 2009 2:01 PM | Feedback (2)

Get Location of the IP Address

I wanted to share with all of you a free service that provides you an approximation of your user’s IP Address. You can read about it here: http://www.hostip.info/use.html. If you are looking for a more sophisticated solution that is maintained more often than the free solution you can also use this service: http://www.maxmind.com As of this writing you can get the response in 2 different forms: XML or plain text. I like the more structure formats so I will be using the XML option. Stay tune… I will post a C# API for retrieving the information. UPDATE:...

posted @ Wednesday, September 02, 2009 3:00 PM | Feedback (3)

Generic CreateRange Extension

I was in need of a CreateRange method, similar to the Enumerable.Range(1, 10), that return an Enumerable of Dates. Doing a search I stumble along this blog post, which contains a generic CreateRange method. I then went ahead and converted the code to use extensions. Here’s the end result: 1: public static IEnumerable<t> CreateRange<t>(this t sender, t end, Func<t, t> func) where t : IComparable 2: { 3: if (sender.CompareTo(end) ==...

posted @ Wednesday, January 21, 2009 9:39 AM | Feedback (0)

ObservableDictionary Object

I was in need of an ObservableDictionary object for .NET 2.0 and there was no CLR object that met my requirements. All I needed was a Dictionary object that would notify me when a value was changed. I created a CodePlex project where you can download the code.   Happy Programming!

posted @ Wednesday, December 03, 2008 2:19 PM | Feedback (0)

Serializing Objects with Enums

Take into consideration the following entity: public class CompositeType { public bool BoolValue { get; set; } public string StringValue { get; set; } public EnumType VehicleType { get; set; } }   public enum EnumType { Car = 0, ...

posted @ Thursday, August 28, 2008 4:11 PM | Feedback (0)

DateTime.ToString(string)

This is more of a "mental" note for me than anything else, but I would like to share it with everyone as well. The DateTime.ToString method has 2 overloads, one with no parameters and the other with a string parameter. I would like to talk about the second one (hence the title of this post). You can pass a custom format pattern as the parameter to show the date anyway you want. Here are some of the possible values: Pattern Description Example yyyy Full Year 2008 yy Year 08 MM Month 05 MMM...

posted @ Thursday, May 22, 2008 3:30 PM | Feedback (1)

Behavior of Default Constructors and Base Classes

A client of mine requires us to use ReSharper. I usually don't like to use any of those tools because if I get used to then and I go crazy when I do not have them, but I think I will give ReSharper a chance at my own dev machine. One of the cool features about ReSharper is that it marks the state of the current class with a green, yellow, or red indicator specifying whether the class is not compileable, compileable with warnings, or compileable without warnings. While working on a class ReSharper was marking it with yellow and specifying that I...

posted @ Wednesday, February 27, 2008 3:15 PM | Feedback (1)

Container.DataItem. What exactly is this?

Recently I had to bind to an array of strings and I wasn't sure how to show the value of the current item. After a little bit of help from the DevTheo and a little bit of thinking I figured out the solution was very simple. All i had to do was bind it like this: <%# Container.DataItem %> So what is this expression exactly? The <%# %> means this is a DataBinding expression and Container.DataItem is an alias for the current item in the datasource. In other words, if you are binding to a collection of objects Container.DataItem is the current...

posted @ Tuesday, November 13, 2007 3:24 PM | Feedback (21)

Traveling Through Time: from Delegates to Anonymous Methods to Lambda Expressions

We are very close to the release (February 2008) of Visual Studio 2008 and .NET 3.5 which will include both C# 3.0 and VB 9.0. Now we can look back in time and see where the .NET framework has taken us. Delegates In .NET 1.x we were introduced to delegates. simply put a delegate is a pointer to a function (thanks Matt Winkler for that one.) So basically you have a function that can be assigned to another function or object. Let's look at the following code: public delegate bool StringCondition(string s);static void Main(string[] args){  string[] names = { "Jonas", "John", "Dave", "Joe", "Alexandra"...

posted @ Tuesday, October 09, 2007 8:29 PM | Feedback (1)

Elite Club

I am very happy to announce that yesterday I have been added to a very elite club: the Microsoft MVP (Microsoft Most Valuable Professional) Club. If you don't believe me check it out for yourself: MVP Profile. I will also like to congratulate a coworker, Brian Peek, for also becoming an MVP. So what's an MVP you might ask? Who better than Microsoft itself to explain it:"Microsoft Most Valuable Professionals (MVPs) are exceptional technical community leaders from around the world who are awarded for voluntarily sharing their high quality, real world expertise in offline and online technical communities. Microsoft MVPs are a highly...

posted @ Monday, July 02, 2007 12:38 PM | Feedback (4)

Full C# Archive