C# Property generator

When creating C# properties, usually it is a good idea to declare members to each property and declare them private, to help control the state of the class internally.

Often creating these members and properties can be a tedious process. The following class generates a simple set of Properties from a file which contains a set of members.  It also creates a simple comment above the properties to help make our code meet coding design standards.

    /// <summary>
    /// Utility class for generating C# Properties.
    /// </summary>
    public class PropertyGenerator
    {
        /// <summary>
        /// Generates C# Properties based on member declarations.
        /// Removes preceeding underscores and properises property names.
        /// </summary>
        public static string GetPropertiesForMembers(string[] members)
        {
            StringBuilder properties = new StringBuilder();

            
            foreach(string member in members)
            {
                // Remove semi-colon.
                string[] parts = member.Replace(';', ' ').Trim().Split(' ');

                // Scope (private, protected etc)
                string memberScope = parts[0];

                // Type (class, simple type)
                string memberType = parts[1];

                // Name of member.
                string memberName = parts[2];

                // Begin by setting our property name to the member name.
                string propertyName = memberName;

                // Remove first underscore if exists.
                if (propertyName.StartsWith("_"))
                {
                    propertyName = propertyName.Substring(1);
                }

                // Properise property name by making the first letter capital.
                propertyName = propertyName[0].ToString().ToUpper() + propertyName.Substring(1); 

                // Generate the property string and add to the StringBuilder.
                AddProperty(memberType, propertyName, memberName, properties);
            }

            // Return the string in the StringBuilder.
            return properties.ToString();
        }

        /// <summary>
        /// Helper method (blueprint) to generate a property from a member.
        /// </summary>
        /// <param name="propertyType"></param>
        /// <param name="propertyName"></param>
        /// <param name="memberName"></param>
        /// <param name="properties"></param>
        private static void AddProperty(string propertyType, string propertyName, string memberName, StringBuilder properties)
        {
            properties.AppendFormat("/// <summary>\n/// Gets or sets {1}\n/// </summary>\n[DataMember()]\npublic {0} {1}\n{{\n\tget\n\t{{\n\t\treturn {2};\n\t}}\n\tset\n\t{{\n\t\t{2} = value;\n\t\tSetEntityStateChanged(\"{1}\");\n\t}}\n}}\n\n", propertyType, propertyName, memberName);
        }
    }

( http://staugustine.org.au )
( http://www.staugustine.org.au )

Accounting Software: GNU Cash Reviewed

Using Personal accounting software GnuCash.

I have previously used MYOB accounting and find the User interface is satisfactory, with a full set of accounting features, with intuitive workflows. The licensing model is very good too, allowing a “trial” period, and charging per file, instead of machine etc.

In MYOB, the output file is recognised by Chartered Accountants which will help at tax time.

Edit

Download details

90Mb file download. Fast mirrors. Windows 7. Version: 2.4.0

Edit

Why GnuCash?

  • Free (as in beer)
  • (reasonably) Trustworthy authors (sensitive data)
  • Project still active
  • Appears well documented

Edit

First load

  • Annoying quick-tips
  • Apparently useful options:
    1. New file
    2. Import QIF (Quickbooks file, can be retrieved from internet banking)
    3. Create tutorial

Edit

Tutorial

  • Not a walkthrough: after it opens I am left wondering where to start.

After finding and clicking new file, I am given a dialog which is quite helpful to create accounts.

After renaming (I left as-is), I am given a save as dialog.

I can save in the following formats:

  • Xml
  • Various SQL Databases (SqlList, mysql, postgres)

I would prefer my account to be a single file for backup/migration purposes, so at this point I will go with XML. I am a bit worried about the potential file size, and the fact it appears not to be encrypted. Also I don’t believe Accountants will want an arbitrary XML file (even if I gave them an XSD to define and validate the XML. 🙂

I selected common accounts, mortgage loan and home owner expenses.

Edit

File security

Turns out file security is up to us, click here:

Q: “Can you please add a password feature?” A: The core developers – which includes those with long-term experience with well-known names/brands in computer security – believe that each app should do one thing well, and leave other concerns to other apps. Especially “tricky”, critical concerns like data security. In this case, GnuCash would do a poor job of being a good security application. You’re encouraged to use an encrypted file system to store your critical data files — GnuCash and others.

While security should be managed by users, a financial suite should have some forms of security by default. This is the deal-breaker at this point. This is my financial data, not application settings.

Entity Framework 4

ADO .NET (4.0) Entity Framework

Source: MSDN

Creates a set of classes based on a Database schema, including the default CRUD operations in the objects.

MVVM Light

MVVM Light

Source: CodePlex

MVVM Light is a light-weight MVVM framework implementation for Silverlight (3 and 4), WPF and Windows Phone 7. It is designed to be simple, to upstart projects quickly.

I would recommend this framework for small-sized projects (e.g. SharePoint Silverlight Apps) to utilise a solid, easily testable product.

For larger systems, this framework may be too simple, and not cater for all architecture requirements (e.g. Scalability, maintainability (E.g. Referencing all viewmodels in a single locator may be too large)).