Click here to Skip to main content
13,798,414 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


5 bookmarked
Posted 13 Jan 2010
Licenced CPOL

.Net - Use The Framework

Rate this:
Please Sign up or sign in to vote.
Don't reinvent the wheel - use the one that's already on the cart.
I've found that there are many parts of the .Net framework that can be used "on the sly". For instance, there was a "Quick Answer" question posted today that presented this problem:

Given a string of configuration settings, like this (with more items than I'm showing here):

string text = "screen_fadetimeout=\"0\" font=\"Courier New\" fontsize=\"11\"

The user asked how to parse the string so he could change the settings in the string. Most of you may have already recognized this string for what it probably is - something from a XML file. There were a couple of responses to this question that suggested using the string.Split() method, or even Regex (wholly inappropriate IMHO), but there is an easier way, and the framework comes to the rescue.

Simply make the string into an acceptable XML format by added a name and the necessary brackets so that it takes on the look of an actual XML element, and then it's a simple matter to process the element instead of its string counterpart, like so:

// our original string
string text = "screen_fadetimeout=\"0\" font=\"Courier New\" fontsize=\"11\"";
// add our XML endcaps
text = string.Format("<TEST {0} />", text);
//Parse the string into an XML element
XElement element = XElement.Parse(text);
// change the value(s) we want to change
element.Attribute("screen_fadetimeout").Value = "5";
// and return our string to its original configuration
text = element.ToString().Replace("<TEST","").Replace("/>","").Trim();

My tip is to use the framework where possible instead of reinventing the wheel or doing things the hard way.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

John Simmons / outlaw programmer
Software Developer (Senior) Paddedwall Software
United States United States
I've been paid as a programmer since 1982 with experience in Pascal, and C++ (both self-taught), and began writing Windows programs in 1991 using Visual C++ and MFC. In the 2nd half of 2007, I started writing C# Windows Forms and ASP.Net applications, and have since done WPF, Silverlight, WCF, web services, and Windows services.

My weakest point is that my moments of clarity are too brief to hold a meaningful conversation that requires more than 30 seconds to complete. Thankfully, grunts of agreement are all that is required to conduct most discussions without committing to any particular belief system.

You may also be interested in...

Comments and Discussions

GeneralMy vote of 5 Pin
Tarek Elqusi31-Jan-13 14:09
professionalTarek Elqusi31-Jan-13 14:09 
QuestionMy 4: In general I agree... Pin
Andreas Gieriet3-Jun-12 22:44
professionalAndreas Gieriet3-Jun-12 22:44 
GeneralWhy you think Rexex is inappropiate? - I'm no fan of it - ju... Pin
johannesnestler24-Feb-12 1:54
memberjohannesnestler24-Feb-12 1:54 
GeneralReason for my vote of 5 nice one Pin
Nikhil_S23-Feb-12 19:11
professionalNikhil_S23-Feb-12 19:11 
GeneralReason for my vote of 5 considerable advice Pin
Pranit Kothari8-Jan-12 5:23
memberPranit Kothari8-Jan-12 5:23 
GeneralReason for my vote of 5 My 5! Pretty Logical. This also gave... Pin
RaisKazi1-Nov-11 21:51
memberRaisKazi1-Nov-11 21:51 
GeneralReason for my vote of 5 Learning the Framework is more effic... Pin
Eddy Vluggen16-Sep-11 7:58
professionalEddy Vluggen16-Sep-11 7:58 
GeneralI agree Pin
PIEBALDconsult27-Jan-12 9:28
protectorPIEBALDconsult27-Jan-12 9:28 
GeneralSo right! Pin
johannesnestler25-May-10 6:01
memberjohannesnestler25-May-10 6:01 
GeneralRe: So right! Pin
John Simmons / outlaw programmer26-May-10 12:27
professionalJohn Simmons / outlaw programmer26-May-10 12:27 
GeneralMy vote of 2 Pin
TheGreatAndPowerfulOz6-Apr-10 13:45
memberTheGreatAndPowerfulOz6-Apr-10 13:45 
GeneralRe: My vote of 2 Pin
John Simmons / outlaw programmer7-Apr-10 0:34
professionalJohn Simmons / outlaw programmer7-Apr-10 0:34 
Generala better way Pin
TheGreatAndPowerfulOz6-Apr-10 13:44
memberTheGreatAndPowerfulOz6-Apr-10 13:44 
GeneralRe: a better way Pin
John Simmons / outlaw programmer7-Apr-10 0:32
professionalJohn Simmons / outlaw programmer7-Apr-10 0:32 
GeneralRe: a better way Pin
TheGreatAndPowerfulOz7-Apr-10 7:06
memberTheGreatAndPowerfulOz7-Apr-10 7:06 
GeneralRe: a better way Pin
John Simmons / outlaw programmer8-Apr-10 0:27
professionalJohn Simmons / outlaw programmer8-Apr-10 0:27 
GeneralRe: a better way Pin
TheGreatAndPowerfulOz22-Apr-10 5:09
memberTheGreatAndPowerfulOz22-Apr-10 5:09 
GeneralGood tip but... Pin
kornman0013-Jan-10 4:27
memberkornman0013-Jan-10 4:27 
GeneralRe: Good tip but... Pin
John Simmons / outlaw programmer13-Jan-10 4:45
professionalJohn Simmons / outlaw programmer13-Jan-10 4:45 
GeneralRe: Good tip but... Pin
kornman0013-Jan-10 6:13
memberkornman0013-Jan-10 6:13 
GeneralRe: Good tip but... Pin
Luc Pattyn17-Jan-10 4:45
professionalLuc Pattyn17-Jan-10 4:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web06 | 2.8.181207.3 | Last Updated 22 May 2010
Article Copyright 2010 by John Simmons / outlaw programmer
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid