Got Partial Methods?

Jan 28, 2011 at 2:17 PM
Edited Jan 28, 2011 at 2:38 PM

This looks like a useful tool.  I've been looking for something which allows for more control over generated code than XSD and SVCUTIL currently allow.  

One feature I am specifically looking for is support for partial methods in the generated property setters.  This would extremely useful for when we have calculated properties which also participate in binding.  For example, I may have declared FirstName and LastName, and have a calculated property in my partial class called FullName which concatenates the two.  The major issue is that FullName is not wired up to know when FirstName and LastName change and therefore does not have any trigger to fire its own NotifyChange event.  If the generated code declared partial methods "onFirstNameChanged", "onLastNameChanged" which were then invoked in the property setters, the partial class can wire up to the partial methods and be aware of when these values change.  

What are your thoughts on this feature request?  

    class Program
    {
        static void Main(string[] args)
        {
            Customer cust = new Customer();
            cust.FirstName = "Road";
            cust.LastName = "Warrior";
            Console.WriteLine(cust.FullName);
        }
    }

    public partial class Customer
    {
        //Partial Method Declarations
        partial void onFirstNameChanged();
        partial void onLastNameChanged();

        string _firstName;
        public string FirstName
        {
            get { return _firstName; }
            set
            {
                _firstName = value;
                onFirstNameChanged();
            }
        }

        string _lastName;
        public string LastName
        {
            get { return _lastName; }
            set
            {
                _lastName = value;
                onLastNameChanged();
            }
        }

    }

    public partial class Customer
    {
        // Implementation of Partial Method 
        partial void onFirstNameChanged()
        {
            CalulateFullName();
        }

        // Implementation of Partial Method 
        partial void onLastNameChanged()
        {
            CalulateFullName();
        }

        private void CalulateFullName()
        {
            _fullName = string.Concat(FirstName, " ", LastName);

            //Fire NotifyChange Event HERE

        }

        string _fullName;
        public string FullName
        {
            get
            {
                return _fullName;
            }
        }

    }