FrameworkUtilities
Recently, I chatted through e-mail with a long time friend's (Joe Heller, who is now engaged [Congratulations!]) co-worker, Brian Wortman of RDS about some programming concepts and workarounds for a few things lacking in the framework. We chatted, swapped opinions, etc. Very smart and cool guy. One of the things we talked about was how he had been working on a project that contained custom attributes to use as parameter method validators to ensure the data coming in fits the bill, saving developers having to write code themselves to check it. I thought it was such a fantastic idea that I went ahead and made my own. Another thing he had mentioned was the problem of Value Types not being able to be Empty (big problem across the board for sure), so I went ahead and wrote an Empty Class to have a standard way to “recognize” empty value type variables.
These two things were related and one uses the other, but also could be used seperately, so I got to thinkin', “Why not create a utilities project with bunches of 'stuff' that could be used throughout all my projects?”. Kind of like the new My Classes in VB.NET Whidbey. So I did...I started a new GDN Workspace called Framework Utilities and also added a couple other (hopefully) useful classes for people to use.
I know I'm usually a VB.NET guy, but this time I decided to do the project in C#. Periodically I do that to keep my skills fresh. Especially for when those “my language is better” arguments come up, I can actually know what I'm talking about because I use both languages.
Current Features
- Method Parameter Validation Attributes
- Attribute for all Value Types and includes range validation and required validation
- Required Attribute to make sure a value is passed in another than null for Reference Types
- If Value Type Attributes are attached to a string, they will make sure the incoming value is Valid
- TryParse Class
- Contains Methods to see if a string value is valid for the particular value type
- Returns the Type requested from a string
- Empty Class
- Standard Methods for Value Types for checking for empty and getting empty values
- Has Database Methods to check for Empty as well
- File Class
- Contains Methods for Retrieving and Writing to files easily (string and byte array)
Method Parameter Validation Attribute Usage
Private Sub CallMethod(<StringParameterValidation(2, 5, True)> ByVal Param1 As String, <RequiredParameterValidation()> ByVal Param2 As XmlDocument, <DateTimeParameterValidation(True)> ByVal Param3 As String)
Try
ParameterValidation.Validate(Param1, Param2, Param3)
'TODO: Code here
MessageBox.Show("Method Called")
Catch Ex As Exception
MessageBox.Show(Ex.Message)
End Try
End Sub
CallMethod("a", Nothing, "3/26/2004")
I did this in the evenings over the last couple days, so it's still rough and the performance needs a lot of work on the Validation Classes. If you have ideas for new features you'd like to see, please post them in the messageboard on the Workspace. Also, I'd love to get some more people in to work on this, tweak what's already there (please oh please any Regex experts...it needs help), test it (I haven't done much testing yet), etc.
Framework Utilities GDN Workspace
Intial Source Code Release v 0.1.0.0
UPDATE: I also wanted to thank Jason Bock for helping me get my head around some stuff with Attributes!