Developers Anonymous

Cross posted from http://www.stevenmcd.net/ 

 

Extension methods are something new to the .Net 3.5 framework and an extremely valuable add-on!

Have you ever had a situation where you have been given a sealed class and desperately needed to add a method? Extension methods allow to add your own custom methods to any class! As a small example: imagine to want to add a method to the standard .Net String class. Normally you would never be able to do this.

Lets say we want to add a method to the string class to convert a string to an integer.

Step 1:

Create a Static Class:

namespace ExtensionNamespace
{
public static class Extensions
{
}
}

The reason behind creating a static class is that your functions should always be available without having to instatiate the class in which your methods reside.

Step 2:

Create your static Method:

namespace ExtensionNamespace
{
public static class Extensions
{
public static int ToInt(this string stringName)
{
//declare integer
int _intToReturn = -1;

//convert string to Integer
_intToReturn = Int32.Parse(stringName);

//return integer
return _intToReturn;
}
}
}

The access identifier on the method should always be public and static for the same reasons mentioned above. You need to then specify your return type for this method which in this case would be an "int". The "ToInt" is the my name for this method. when specifying the input parameters for the method you are also specifying which class this method will be extending. Here we are extending the String class. You must *always* prefix the first parameter with the word "this".

Once thats done its up to you to write the code for your method. obviously the code I have written above is extremely basic and so does not follow best practice so pay no attention to it. It is the structure of the method that you should focus on.

Step 3:

Implementing your extension:

When you want to use this extension, simply include the namespace in the code file you're using. So in this case, at the top of your code page, specify the following using statement:

"using ExtensionNamespace;"

Then we simply declare a string for use and view its methods and viola! There it is!
ExtJPG.jpg

 

Cross posted from http://www.stevenmcd.net/

Since starting my journey into seeing what LiNQ can do I have been amazed. It is truly amazing and this will definitely shorten development time on so many different projects! Here's what I did tonight and you decide for yourself whether LiNQ is going to be useful or not. I first created my database tables and set the relationship between the tables. Once you have done this, from your database server tab in Visual Studio, you simply drag and drop both tables into the LiNQ to SQL designer in Visual studio. This is what it looked like :

 

 

 

 

 

 

 

 

Once I had saved the dbml file I made a very simple ASP.Net Page for my Task Entry. I included a RadionButtonList to list all of the users in the database. Unfortunately you cannot bind directly to a linq table but I believe this is for security purposes. Once I can find the reason I will definitely post it because personally I feel one should be allowed to bind directly to a linq table. Once the page had been completed it looks like this:

 

 

 

 

 

 

 

 

Now as I previously stated, you cannot behind directly onto the linq table so you have to retrieve all the users and loop through them and add them individually to the RadioButtonList. Here is how I did it. This is by no means the perfect way of doing it but if you do know of a better way please let me know! This is the only way we learn is by learning from eachother!

 

 

 

 

 

 

 

 

 

 

 

 

TaskDataContext is the name that I gave to my LiNQ to SQL dbml class. You have to declare this to do any work on the database. This is basically your connection to your Database. Once we have our connection we want to retrieve all our users. I have declared a variable called _UserList to hold the list of users. The "var" keyword is new to Framework 3. The "var" keyword represents the "Implicitly Typed Local Variables" feature. The way this works is that when you declare the variable you don't need to specify the type *BUT* the variable *MUST* be initialized on declaration. The compiler will interpret the value and assign its data type accordingly. Once the information is retrieved from the database that _UserList variable is assigned to a List<USER> variable containing a generic collection of USER classes. I think the rest of the code is self explanatory. I loop through the collection creating a new list item for each USER in the _UserList collection and add those items to the RadioButtonList. Now comes the magic. Adding the Task to the database. This is the part of LiNQ that has absolutely amazed me thus far. We write the code for the "Add Task" button:

 

 

 

 

 

 

 

 

 

 

This is it! No SQL code typed whatsoever! No Insert SPROC needed. No Inline SQL needed, nothing! We simply declare our TasksDataContext and then declare a new task. We set the properties needed by the class and add the new TASK class to our TaskContext and then call the SubmitChanges() Method. Lets have a look whats in the database shall we?

 

 

 

 

And there we go. And I'll say it again, NO SQL CODE NEEDED FOR THE INSERT!!!!! I realize this makes me seem incredibly lazy which I am.  Please feel free to correct anything I might've done wrong in your opinion or something I could've done better. Next Article will cover Updating and Deleting using LiNQ.

 

Cross Posted from http://www.StevenMcD.Net/

Blogged with Flock

 Today I discovered 2 tools that I can't believe that I've missed up and till now. So for all you web developers out there who use Firefox check my entry here: http://stevenmcd.net/wordpress/?p=26

I can assure you that this will change the way you optimize your web apps!

I have received numerous emails asking me why I'm not blogging here so often anymore. I recently set my own site so that I can begin trading off my own name. BUT I'm still going to cross post my important article here at DotNet.org.za because I firmly believe that this is where us South African developers should discuss .Net topics. Besides that, there is such a wealth of knowledge in the blogs contained here that I am going to try my best to live up to the standards set by the likes of Armand, Ernst, Willy Peter and so on.

So by all means check out http://www.stevenmcd.net

 

So here's the deal. I'm a developer at an insurance company. We are two full time developers, one full time report writer and then our manager develops whenever he has the time. Now we trying to get a new policy in place whereby users are not just allowed to call us directly. They have to make use of a system called SysAid. Now for those of you that don't what sysAid is, basically its a small app on which users can log help requests that then gets sent to us. Now that we starting to enforce the use of SysAid a lot of the users are no longer happy........

read more at: http://stevenmcd.net/wordpress/?p=14



REDMOND, Wash. — July 5, 2007 —Microsoft Corp. today announced that it will expand its global Xbox 360™ warranty coverage. Any Xbox 360 customer who experiences a general hardware failure indicated by three flashing red lights will now be covered by a three year warranty from date of purchase.  All other existing Xbox 360 warranty policies remain in place.
This is such great news!!!!! Read the full story at: http://www.xbox.com/en-US/support/systemsetup/xbox360/resources/warrantyupdate.htm

Thats right! After looking at the eNaTIS website trying to figure out why someone would want to deface already ugly looking sight, I looked at the source of the page and what do I see?

meta content="Joomla! - Copyright (C) 2005 - 2006 Open Source Matters. All rights reserved." name="Generator"

So our new Traffic Website is powered by a *FREE* *OPEN SOURCE* Content Management System?! Thats right folks! This *FREE* *OPEN SOURCE* implementation of Joomla! for the traffic department cost us, the taxpayers R408-million!

read more at http://stevenmcd.net/wordpress/?p=12

Thats right! I just got engaged to the most amazing woman I've ever met. I mean DUH! Thats why I'm planning on marrying her. :)

"well once again time has eluded me. <insert general excuse about too much work here>. So I’ve now decided to get Certified so now I just need to get hold of all the books that I need for studying and then of course the time to study.

I’m also using a Trial version of an application called “Ecto” to write this post........"

Read more at http://stevenmcd.net/wordpress/?p=9

Long time no blog.

 I have just started a new job at African Independent Insurance Brokers in Springs thus I have been a little quiet as I'm still learning about everything here. I now only work 1.3km from home where I used to work 72km from home. Its a massive difference but a pleasant one to say the least! I must however thank all the guys at Signify Software for everything! Its an amazing company to work for but nothing can compensate for the time spent on the road.

 
Anyone looking for a job as ASP.Net / C# developer in and around the Centurion area please email me at StevenMcD at gmail dot com. Signify are looking for some experienced (1-2years) developers and I can say from experience thats its a great company to work for! I truely hope to work for them again in the future!

 
As for other happenings, I'm looking forward to Armand's discussion on LiNQ and ORCAS tomorrow night in rivonia. RSVP you place at http://sadeveloper.net/forums/thread/3820.aspx by the end of today!
 

I might be a little late in "joining the revolution" but I'm finally up on Facebook. If I had've received one more invite I would've gone crazy. It amazing though, the more I use it the more awesome it becomes! I even hooked up with a mate I've been trying to track down for years!

Just my opinion but feel facebook is better than MySpace but that's just my Opinion. It uses less bandwidth and it's a look faster. Check it out at http://www.facebook.com

Microsoft has just released a CLR Profiler! Download it here. Thank you to Diago for bringing it to my attention on Sadeveloper.Net. I'm going to download it tonight and play around with it.

Here are 16 actual error messages reportedly seen on the computer screens in Japan, where some are written in Haiku. Aren't these better than "your computer has performed an illegal operation"? Enjoy!



The Web site you seek
cannot be located,
but countless more exist.


*       *


Chaos reigns within.
Reflect, repent, and reboot.
Order shall return.


*       *


Program aborting:
Close all that you have worked on.
You ask far too much.


*       *


Windows NT crashed.
I am the Blue Screen of Death.
No one hears your screams.


*       *


Yesterday it worked.
Today it is not working.
Software is like that.


*       *


Your file was so big.
It might be very useful.
But now it is gone.


*       *


Stay the patient course.
Of little worth is your ire.
The network is down.


*       *


A crash reduces your expensive
computer to a simple stone.


*       *


Three things are certain:
Death, taxes and lost data.
Guess which has occurred?


*       *


You step in the stream,
but the water has moved on.
This page is not here.


*       *


Out of memory.
We wish to hold the whole sky,
But we never will.


*       *


Having been erased,
The document you're seeking
must now be retyped.


*       *


Serious error.
All shortcuts have disappeared.


*       *


Screen......Mind..........
Both are blank.

Now I am completely stumped. This has nothing to do with Development or Technology but everything to do with boyfriends defending their girlfriends.

My gf and I have been talking about getting engaged and she told some friends at work when a guy in his 30's heard this. He asked her whether we getting married and she informed him that we talking about getting engaged. He said it was a good thing since she needed time to lose all that extra weight. Now anybody who knows my gf will know this, if she loses anymore weight she would probably die. She is easily the most slender woman I know. Not so bad that there are ribs sticking out anywhere, but if you look up the word slender in the dictionary there'd be a photo of her there.

So obviously I was furious because this wasn't said in a joking manner and she was really upset. SO I decided to call this idiot and teach somethings his mother and father obviously never did. I'm not a confrontational guy but he had really pushed it. You NEVER say anything like that to a woman and besides she is MY girlfriend and she is perfect, it has nothing to do with him. So I called and he answered and I asked if it was Peter speaking. I introduced myself (not mentioning I was the boyfriend, just a normal courteous introduction) and he immediately asked why I wanted to speak to him or whether I wanted to speak to another Peter (since he is new there). Now before I kindly teach this SOB a few lessons I decide it would be wise to first check that I'm speaking to the correct Peter.

So I asked for my gf and she answered and promptly told me that she hates me and puts down the phone. So now I'm angry with some 30 year-old d***head who lives with his mother who never taught him any manners and I'm in the dogbox with my better-half. This begs the question, should we even bother sticking up for our girlfriends' anymore? It's ridiculous! WTF am I supposed to do now? I thought ladies liked it when somebody stood up for them when they were too scared to do so. Am I mistaken? Has the ideology of chivalry completely died? We've been dating for almost 3 years and she's never had to open a door in my presence (in the house or getting into the car or out), I have done everything my mother taught me including to stick up for the one I love. Is this so wrong?

So now that I have my ADSL up and running, I have decided to run off a 1gig unshaped service from www.webafrica.co.za and so far so good. That was until last night when I hosted a Gears of War server on xbox live for a few local guys. To cut a long story short, after 2 and half hours of play I had used 285MB of bandwidth.

So this morning I started looking for something that could save me money because there's no way my cap is going to last at this rate. Now a 1gig prepaid is R125 for unshaped bandwidth but 10gig local bandwidth is only R70. BUT to connect xbox live I need international bandwidth. There is a solution! You can split your local and international bandwidth using this amazing little programme called Route Sentry. Now I can log onto xbox live using my international bandwidth but when I host / play a local match then it automatically uses my local bandwidth.

Unforunately I cannot seem to find what the programmers name is but to you ant1body, I am eternally grateful! Check out his site here for more tools that he has written!

More Posts Next page »