Click here to Skip to main content
15,884,298 members
Articles / Programming Languages / Visual Basic

Declarative Codesnippet Automation with T4 Templates

Rate me:
Please Sign up or sign in to vote.
4.77/5 (15 votes)
20 Apr 2011CPOL15 min read 56.4K   1.4K   36  
This article describes a technique for automating codesnippets which are associated with a class via attributes. This results in a declarative approach to the generation of boiler-plate code.





using System.ComponentModel;
using Visiblox.Charts;
using System.Windows;
using System;

namespace SilverTrack.ViewModel
{
  public partial class TelemetryChannelViewModel  
  {
	
    #region INotifyPropertyChanged Members

    /// <summary>
    /// Occurs when a property changes
    /// </summary>
    public event PropertyChangedEventHandler  PropertyChanged;

    /// <summary>
    /// Raises a PropertyChanged event
    /// </summary>
    protected void OnPropertyChanged(string property)
    {
	    if (PropertyChanged != null)
	    {
		    PropertyChanged(this, new PropertyChangedEventArgs(property));
	    }
    }

    #endregion
    

    /// <summary>
    /// Field which backs the SelectedSecondaryIndex property
    /// </summary>
    private int _selectedSecondaryIndex = 1;

    public static readonly string SelectedSecondaryIndexProperty = "SelectedSecondaryIndex";
				
    /// <summary>
    /// The Index of the selected series in the secondary combo box.
    /// </summary>
    public int SelectedSecondaryIndex
    {
	    get { return _selectedSecondaryIndex; }
	    set
	    {
		    if (_selectedSecondaryIndex == value)
			    return;
			
		    _selectedSecondaryIndex = value;
        
        OnSelectedSecondaryIndexChanged(value);
		
		    OnPropertyChanged(SelectedSecondaryIndexProperty);
	    }
    }
    
    /// <summary>
    /// Invoked when the value of SelectedSecondaryIndex changes
    /// </summary>
    partial void OnSelectedSecondaryIndexChanged(int value);
    

    /// <summary>
    /// Field which backs the SelectedPrimaryIndex property
    /// </summary>
    private int _selectedPrimaryIndex = 1;

    public static readonly string SelectedPrimaryIndexProperty = "SelectedPrimaryIndex";
				
    /// <summary>
    /// The Index of the selected series in the primary combo box.
    /// </summary>
    public int SelectedPrimaryIndex
    {
	    get { return _selectedPrimaryIndex; }
	    set
	    {
		    if (_selectedPrimaryIndex == value)
			    return;
			
		    _selectedPrimaryIndex = value;
        
        OnSelectedPrimaryIndexChanged(value);
		
		    OnPropertyChanged(SelectedPrimaryIndexProperty);
	    }
    }
    
    /// <summary>
    /// Invoked when the value of SelectedPrimaryIndex changes
    /// </summary>
    partial void OnSelectedPrimaryIndexChanged(int value);
    

    /// <summary>
    /// Field which backs the Behaviour property
    /// </summary>
    private BehaviourManager _behaviour = null;

    public static readonly string BehaviourProperty = "Behaviour";
				
    /// <summary>
    /// The Behaviour Manager which contains the trackball and the XAxisZoomBehaviour.
    /// </summary>
    public BehaviourManager Behaviour
    {
	    get { return _behaviour; }
	    set
	    {
		    if (_behaviour == value)
			    return;
			
		    _behaviour = value;
        
        OnBehaviourChanged(value);
		
		    OnPropertyChanged(BehaviourProperty);
	    }
    }
    
    /// <summary>
    /// Invoked when the value of Behaviour changes
    /// </summary>
    partial void OnBehaviourChanged(BehaviourManager value);
    

    /// <summary>
    /// Field which backs the XAxisVisible property
    /// </summary>
    private bool _xAxisVisibile = false;

    public static readonly string XAxisVisibleProperty = "XAxisVisible";
				
    /// <summary>
    /// Whether this chart's X-Axis is visible.
    /// </summary>
    public bool XAxisVisible
    {
	    get { return _xAxisVisibile; }
	    set
	    {
		    if (_xAxisVisibile == value)
			    return;
			
		    _xAxisVisibile = value;
        
        OnXAxisVisibleChanged(value);
		
		    OnPropertyChanged(XAxisVisibleProperty);
	    }
    }
    
    /// <summary>
    /// Invoked when the value of XAxisVisible changes
    /// </summary>
    partial void OnXAxisVisibleChanged(bool value);
    

    /// <summary>
    /// Field which backs the LivePrimaryChartDataSeries property
    /// </summary>
    private DataSeries<DateTime, double> _livePrimaryData = null;

    public static readonly string LivePrimaryChartDataSeriesProperty = "LivePrimaryChartDataSeries";
				
    /// <summary>
    /// The Live Updating DataSeries that is always displayed on the chart's primary y-axis.
    /// </summary>
    public DataSeries<DateTime, double> LivePrimaryChartDataSeries
    {
	    get { return _livePrimaryData; }
	    set
	    {
		    if (_livePrimaryData == value)
			    return;
			
		    _livePrimaryData = value;
        
        OnLivePrimaryChartDataSeriesChanged(value);
		
		    OnPropertyChanged(LivePrimaryChartDataSeriesProperty);
	    }
    }
    
    /// <summary>
    /// Invoked when the value of LivePrimaryChartDataSeries changes
    /// </summary>
    partial void OnLivePrimaryChartDataSeriesChanged(DataSeries<DateTime, double> value);
    

    /// <summary>
    /// Field which backs the LiveSecondaryChartDataSeries property
    /// </summary>
    private DataSeries<DateTime, double> _liveSecondaryData = null;

    public static readonly string LiveSecondaryChartDataSeriesProperty = "LiveSecondaryChartDataSeries";
				
    /// <summary>
    /// The Live Updating DataSeries that is always displayed on the chart's secondary y-axis.
    /// </summary>
    public DataSeries<DateTime, double> LiveSecondaryChartDataSeries
    {
	    get { return _liveSecondaryData; }
	    set
	    {
		    if (_liveSecondaryData == value)
			    return;
			
		    _liveSecondaryData = value;
        
        OnLiveSecondaryChartDataSeriesChanged(value);
		
		    OnPropertyChanged(LiveSecondaryChartDataSeriesProperty);
	    }
    }
    
    /// <summary>
    /// Invoked when the value of LiveSecondaryChartDataSeries changes
    /// </summary>
    partial void OnLiveSecondaryChartDataSeriesChanged(DataSeries<DateTime, double> value);
    	}
}
	

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect Scott Logic
United Kingdom United Kingdom
I am CTO at ShinobiControls, a team of iOS developers who are carefully crafting iOS charts, grids and controls for making your applications awesome.

I am a Technical Architect for Visiblox which have developed the world's fastest WPF / Silverlight and WP7 charts.

I am also a Technical Evangelist at Scott Logic, a provider of bespoke financial software and consultancy for the retail and investment banking, stockbroking, asset management and hedge fund communities.

Visit my blog - Colin Eberhardt's Adventures in .NET.

Follow me on Twitter - @ColinEberhardt

-

Comments and Discussions