Flit in Depth

Flit typically runs as a stage within a T4 code generation process. It has three components, a Parser, an Object Model, and a t4 template for Code generation.

An example:

Flit can turn this:

digraph g{
	Story[label="Story(string title)"]
	Condition[label="Condition(string text, Action action)"]
	Operation[label="Operation(string text, Action action)"]
	Outcome[label="Outcome(string text, Action action)"]
	Story -> Condition [label="Given"]
	Condition -> Condition [label="And"]
	Condition -> Operation [label="When"]
	Operation -> Operation [label="And"]
	Operation -> Outcome [label="Then"]
	Outcome -> Outcome [label="And"]
}


into this:

Class Diagram

GivenWhenThen.png

Code

You'll have to download the source if you want to see what a typical FluentStateBase looks like, although you're welcome to modify it (and the template) to suit your exact needs.

namespace Flit.Samples.GivenWhenThen
{
	public partial class Story : FluentStateBase
	{
		
		public Story(string title){
			this.Title = title;
		}
		
		#region Data
		public string Title {get;set;}
		#endregion
		
	
		#region Actions
		
		partial void OnGiven(string text, Action action);
		public Condition Given(string text, Action action) 
		{
			Condition __newFragment = new Condition(text, action);
			Children.Add(__newFragment);
			__newFragment.Parent=this;
			OnGiven(text, action);
			return __newFragment;
		}
		
		#endregion

		#region VisitCallback
		
		public override void VisitCallback(IFragmentVisitor v)
		{
			v.Visit(this);
		}
		
		#endregion
	}
	public partial class Condition : FluentStateBase
	{
		
		public Condition(string text, Action action){
			this.Text = text;
			this.Action = action;
		}
		
		#region Data
		public string Text {get;set;}
		public Action Action {get;set;}
		#endregion
		
	
		#region Actions
		
		partial void OnAnd(string text, Action action);
		public Condition And(string text, Action action) 
		{
			Condition __newFragment = new Condition(text, action);
			Children.Add(__newFragment);
			__newFragment.Parent=this;
			OnAnd(text, action);
			return __newFragment;
		}
		
		
		partial void OnWhen(string text, Action action);
		public Operation When(string text, Action action) 
		{
			Operation __newFragment = new Operation(text, action);
			Children.Add(__newFragment);
			__newFragment.Parent=this;
			OnWhen(text, action);
			return __newFragment;
		}
		
		#endregion

		#region VisitCallback
		
		public override void VisitCallback(IFragmentVisitor v)
		{
			v.Visit(this);
		}
		
		#endregion
	}
	public partial class Operation : FluentStateBase
	{
		
		public Operation(string text, Action action){
			this.Text = text;
			this.Action = action;
		}
		
		#region Data
		public string Text {get;set;}
		public Action Action {get;set;}
		#endregion
		
	
		#region Actions
		
		partial void OnAnd(string text, Action action);
		public Operation And(string text, Action action) 
		{
			Operation __newFragment = new Operation(text, action);
			Children.Add(__newFragment);
			__newFragment.Parent=this;
			OnAnd(text, action);
			return __newFragment;
		}
		
		
		partial void OnThen(string text, Action action);
		public Outcome Then(string text, Action action) 
		{
			Outcome __newFragment = new Outcome(text, action);
			Children.Add(__newFragment);
			__newFragment.Parent=this;
			OnThen(text, action);
			return __newFragment;
		}
		
		#endregion

		#region VisitCallback
		
		public override void VisitCallback(IFragmentVisitor v)
		{
			v.Visit(this);
		}
		
		#endregion
	}
	public partial class Outcome : FluentStateBase
	{
		
		public Outcome(string text, Action action){
			this.Text = text;
			this.Action = action;
		}
		
		#region Data
		public string Text {get;set;}
		public Action Action {get;set;}
		#endregion
		
	
		#region Actions
		
		partial void OnAnd(string text, Action action);
		public Outcome And(string text, Action action) 
		{
			Outcome __newFragment = new Outcome(text, action);
			Children.Add(__newFragment);
			__newFragment.Parent=this;
			OnAnd(text, action);
			return __newFragment;
		}
		
		#endregion

		#region VisitCallback
		
		public override void VisitCallback(IFragmentVisitor v)
		{
			v.Visit(this);
		}
		
		#endregion
	}

	public interface IFragmentVisitor
	{
		void Visit(Story fragment);
		void Visit(Condition fragment);
		void Visit(Operation fragment);
		void Visit(Outcome fragment);
	}
}



Last edited Oct 18, 2009 at 7:42 PM by robfe, version 4

Comments

No comments yet.