CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

John Papa [MVP C#]

.NET Code Samples, Data Access, and Other Musings

December 2006 - Posts

  • Column Expressions, DataRelations, and Computations

    The January issue of MSDN Magazine is now online. In this issue, is my latest Data Points column titled Column Expressions, DataRelations, and Computations.  This month’s topic are from the mailbag and include using expression-based columns, the Compute method, SetOrdinal and DataRelations to traverse data and calculate values to address common business needs.

     

  • Generating a Field and its Property Using Resharper Live Templates

    Someone asked me for this template today, so I figured I would just post it. This is a simple template that I use with Resharper to generate my fields and properties. This only applies when I am not using CodeSmith to automatically generate my business entity classes. But when I have to create fields and properties one at a time, I like to use this template.

     

    private $TYPE$ $VARIABLE1$;

     

    public $TYPE$ $VARIABLE2$

    {

        get { return $VARIABLE1$; }

        set { $VARIABLE1$ = value; }

    }

     

    If you have not created Live Templates for Resharper before, go check it out in the Resharper | Options menu and select Live Templates.

     

    Available In:

    I set this setting to “in C# files where member declaration is allowed” so I can enter them at the class level.

     

    Abbreviation & Name:

    I assigned the abbreviation of “fp” to this template and called it “field property”.

     

    $TYPE$

    I wanted the type to be dynamic so I could enter string, int, or ArrayList (for example). And the type has to be used in both the field and in the property. So I used the same placeholder for both the field and the property. I set the macro to “none” . Its pretty generic and I don’t want it to default to a specific type, so that’s fine here.

     

    $VARIABLE1$

    The first instance of the variable name should be in lowercase. I will type this in myself. I don’t need a macro here but you can set the “suggest a name for variable” macro if  you choose (or some other macro).

     

    $VARIABLE2$

    The second instance of the variable name should be the same as the first, except that the first letter should be uppercase. So I name the placeholders differently and I assign the macro “value of another variable with the first character in uppercase” to this placeholder and I assign $VARIABLE1$ as the variable that it refers to.

     

    Running the Live Template

    Once the live template is created, I type “fp” and hit the TAB key. This automatically generates the stub for the field and the property. It prompts me for the TYPE, which I entered string. Then it prompts me for the VARIABLE, for which I entered firstName. From these 2 entries it fills in the rest of the template and I end up with the following:

     

     

                    private string firstName;

     

                    public string FirstName

                    {

                        get { return firstName; }

                        set { firstName = value; }

                    }

     

     

    Disclaimer / Notes:

    Use this at your own risk/pleasure … I do not warranty them J. Obviously you can change or modify the settings of Live Templates to generate simple or complex code logic.

  • How Hollywood Portrays Us

    Here is a very funny post that my friend Dustin showed me today about how Hollywood and the movies portray “coders” at this link http://www.drivl.com/pages/code .

    Many of these hit home with me as I was reminded of watching movies like Hackers, Matrix, War Games, and others with my friends and family. The fact that my family has no idea what I do has never helped matters.

    I love the part in this post where he references the scrolling code on the screen. Is your code green text on a black background? Is your code all indecipherable 1’s and 0’s without any whitespace whatsoever? Does your code move at the speed of light while making blip sounds? Well, mine doesn’t either. Can you hack into a government facility and decrypt some of the most complex encryption algorithms in existence in under 5 seconds? Well, I can’t either. But it makes for great film!

    “Just give me 5 seconds to backdoor into the CIA’s system and find out where Bin Laden is being held (scrolling green 1’s and 0’s flying by and beeping) … there … I got it!”

    But at least our profession is portrayed in Hollywood … so we must be important J

  • Blogging from Email - Trying Out blogmailr

    Writing a blog is not really that difficult (OK, I’ve been really lazy the past few months on this). But I do find that I am often in my email client whether that is on my desktop, laptop or on my SmartPhone. So when I heard that blogmailr existed, I figured it was worth a shot … especially since it is free. Blogmailr is a tool that allows you to post a blog through email. All you do is:

    1)      Set up an account with blogmailr at www.blogmailr.com

    2)      During the account setup, you have to specify the credentials to log into your blog so it can post to it

    3)      Blogmailr assigns you an email address

    4)      Enter all email addresses that you want to be allowed to submit to the blogmailr enabled blogs

    5)      You send an email to the assigned blogmailr email address and its contents are posted to your blog

    It sounded simple, so I wrote this post with it to try it out and see how it handled formatted text. Above I used some bulleted numbers. Now, I will use some bullets to list some of my favorite authors:

    • J.R.R. Tolkien
    • Terry Brooks
    • C.S. Lewis

    And here is some code that I copied from C# in VS.NET 2005:

    // This is the Problem ID Property

    public int ProblemID

    {

                get { return this.problemID; }

                set { this.problemID = value; }

    }

    If this works out, I may end up using it more than Word or BlogJet!

    Oh … do not tell anyone your assigned email address. Otherwise, they will be able to post to your blog too!

More Posts