private string CreateCode(AutomationElementPropertyObject obj, string inner, AutomationElementTreeNode parent)
        {
            _tabCount++;
            try
            {
                if (!String.IsNullOrEmpty(inner))
                    inner = String.Format("{0}{{{1}{2}{3}{4}}}", Tab, Environment.NewLine, inner, Environment.NewLine, Tab);

				var comment = String.Format("//UI Detection Details -- ControlType:{0}, Automation ID:{1}, Name:{2}, Framework:{3}", obj.ControlType, obj.AutomationId, obj.Name, obj.FrameworkType());
                var generated = "";
                AutomationElementPropertyObject parentObj = parent == null ? null : new AutomationElementPropertyObject(parent.AutomationElement);
                switch (obj.ControlType)
                {
                    case "ControlType.Window":
                        string fields = String.Join(string.Empty, _fields);
                        inner = String.Format("{0}public class {1} : Screen{2}" +
                            "{{{3}public {4}() : base(\"{5}\") {{ }}{6}{7}{8}{9}", 
                            Tab, 
                            obj.PropertyName(), 
                            Environment.NewLine + Tab,
                            Environment.NewLine + Tab + _tab, 
                            obj.PropertyName(), 
                            obj.Name,
                            Environment.NewLine + Tab + _tab,
                            fields,
                            inner.TrimStart('{', ' '),
                            Environment.NewLine);
                        break;
                    case "ControlType.TitleBar":
                        return inner.RemoveBrackets();

                    case "ControlType.MenuBar":
                        inner = inner.RemoveBrackets();
                        _fields.Add(String.Format("{0}private {1} {2};{3}", Tab, obj.WhiteType(), obj.FieldName(), Environment.NewLine));
                        generated = obj.ApplyDefaultFormatByText(obj.WhiteType(), Tab);
                        break;
                    case "ControlType.MenuItem":
                        _fields.Add(String.Format("{0}private {1} {2};{3}", Tab, obj.WhiteType(), obj.FieldName(), Environment.NewLine));
                        generated = String.Format(
                            "{0}public {1} {2} {{ get {{ return {3} ?? ( {4} = {5}.MenuItem(\"{6}\")); }} }}{7}",
                            Tab,
                            obj.WhiteType(),
                            obj.PropertyName(),
                            obj.FieldName(),
                            obj.FieldName(),
                            parentObj.PropertyName(),
                            obj.Name,
                            Environment.NewLine);
                        break;
                    case "ControlType.Button":
					case "ControlType.Edit":
                    case "ControlType.Text":
                        _fields.Add(String.Format("{0}private {1} {2};{3}", Tab, obj.WhiteType(), obj.FieldName(), Environment.NewLine));
                        generated = obj.ApplyDefaultFormat(obj.WhiteType(), Tab);
                        break;

                    case "ControlType.Pane":
                        inner = inner.RemoveBrackets();
                        //TODO: Scope searches to pane
                        _fields.Add(String.Format("{0}private {1} {2};{3}", Tab, obj.WhiteType(), obj.FieldName(), Environment.NewLine));
		                generated = parentObj == null ? obj.ApplyDefaultFormat(obj.WhiteType(), Tab) : obj.ApplyDefaultFormatWithParent(Tab, parentObj);
                        break;
                    default:
                        generated = String.Format("{0}// Control type '{1}' not supported{2}", Tab, obj.ControlType, Environment.NewLine);
                        break;
                }

                return string.Format("{0}{1}{2}{3}{4}{5}{6}",
                    Environment.NewLine,
                    Tab,
                    comment,
                    Environment.NewLine,
                    generated,
                    inner,
                    Environment.NewLine);
            }
            finally
            {
                _tabCount--;
            }
        }
 public static string ApplyDefaultFormatWithParent(this AutomationElementPropertyObject obj, string type, string tab, AutomationElementPropertyObject parent)
 {
     return String.Format(
                         "{0}public {1} {2} {{ get {{ return {3} ?? ( {4} = {5}.Get<{6}>(\"{7}\")); }} }}{8}",
                         tab,
                         type,
                         obj.PropertyName(),
                         obj.FieldName(),
                         obj.FieldName(),
                         parent.PropertyName(),
                         type,
                         obj.Name,
                         Environment.NewLine);
 }