Posts tagged c#

LINQ Audit Trail v2 – DoddleAudit

This looked like a link that was fairly re-post worthy. This is practically a must for any .NET + LINQ + MSSQL developer out there. Very neat way of doing audit trails in MSSQL with LINQ and C#.

A couple months ago I wrote a basic set of extension methods to handle automatic auditing in LINQ to SQL. Well I have received a large number of emails regarding this particular project so I have decided to focus on cleaning up my v2 API and releasing it on CodePlex. There was a lot of room for improvement from version 1 and today I am going to post the all new LINQ Audit Trail code. This new version is significantly enhanced in the previous version.

via LINQ Audit Trail v2 – DoddleAudit.

Helpful Extension Methods to the System.String Class in C#

I’ve been doing a decent amount of string manipulation lately and decided to combine that with my newfound knowledge about .NET extension methods. If you don’t know what extension methods are, they’re basically a way to extend a class without needing the source code to that particular class–hence why I can extend the System.String type by simply writing another class. The key is with the parameters of your methods. Here’s the basic gist of it:

public static {Your Return Type} {Your Method Name} ( this {Type/Class you want to extend} {Parameter Name} )
{
     /* Your method body */
}

 

So the key here is the “this” keyword before the type identifier in the parameter list of the method.

I’ve wrapped all of my extension methods into a single class simply called “ExtensionMethods” and added it to my project. The namespace doesn’t matter, so I haven’t included it in this example. You can either use the global namespace (though I don’t recommend it) or just create your own namespace called whatever you want.

Without further adue, here’s the code:

public static class ExtensionMethods
{
    /// <summary>
    /// Includes the trailing path delimiter.
    /// </summary>
    /// <param name="InputPath">The input path.</param>
    /// <returns>The input path including a trailing path delimiter if it doesn't have one</returns>
    public static string IncludeTrailingPathDelimiter(this string InputPath)
    {
        if (!InputPath.EndsWith(Path.DirectorySeparatorChar.ToString()) &&
            !InputPath.EndsWith(Path.AltDirectorySeparatorChar.ToString()))
            return InputPath + Path.DirectorySeparatorChar;
        return InputPath;
    }

    /// <summary>
    /// Asserts the trailing path delimiter.
    /// </summary>
    /// <param name="InputPath">The input path.</param>
    public static void AssertTrailingPathDelimiter(this string InputPath)
    {
        InputPath = InputPath.IncludeTrailingPathDelimiter();
    }

    /// <summary>
    /// Trims the extension from a file name.
    /// </summary>
    /// <param name="InputFile">The input file.</param>
    public static void TrimExtension(this string InputFile)
    {
        int start, count;
        if ((start = InputFile.LastIndexOf(".")) > 0)
        {
            count = InputFile.Length – start;
            InputFile = InputFile.Remove(start, count);
        }
    }

    /// <summary>
    /// Gets a file extension of a filename.
    /// </summary>
    /// <param name="InputFile">The input file.</param>
    /// <returns>The file extension</returns>
    public static string FileExtension(this string InputFile)
    {
        int start, count;
        if ((start = InputFile.LastIndexOf(".")) > 0)
        {
            count = InputFile.Length – start;
            return InputFile.Substring(start, count);
        }
        return string.Empty;
    }

}

 

Now whenever you use a System.String object, you’ll be able to simply call these methods as if they were part of the System.String class. IE: string MyFileExtension = MyFilePath.FileExtension();

I’m sure I’ll add on to this as I go along.

Templatize Tool

I recently wrote up a template engine tool called Templatize. It started as a tool for my girlfriend so she could quickly generate HTML pages from CSV rows for use on eBay, but then quickly grew into a more robust template tool.

Basically it takes a set of input data, containing multiple entities (rows), each with multiple properties (columns), formatted from some type of delimited text file. Then it takes in a master template file and spits out multiple “data-injected” versions of that template.

View the full page here.

KnowIT RC2.1 Released

I’ve completed the modifications and package builds for KnowIT releast candidate 2.1. They are available from the KnowIT Google Code site. Dare I say, this is one of the best peices of software I have written in a long time. And the best part is, its open source!

Check out the Screenshots.

KnowIT works with Windows ONLY. There is currently not a Linux/UNIX scanner available for KnowIT, and the database back-end is a Microsoft product (MSSQL 2005). However, I did add ODBC support this time around, so it may work on other database types as well. If anybody gets it to work on MySQL or Oracle, let me know.

VGL Math – 2D/3D Video Game Math Library

I decided to get bold and start another open source project. This time it is related to the math involved in developing 2D and 3D video games. The project is hosted at http://code.google.com/p/vglmath. I decided to deem it a “VGL community project”; VGL being the company I founded a few months ago.

I’m looking for any pointers, contributors, or experts to make improvements or recommendations to the code. So please check it out. If you’re interested in contributing, please send me an email at cale@caledunlap.com so I can add your Google account to the members list.

And if you haven’t already, check out http://www.venomgamelabs.com!

Now for your entertainment for the evening:

Get Adobe Flash playerPlugin by wpburn.com wordpress themes