コード例 #1
0
        public void TestIfElseIfCorrection()
        {
            CSharpFormattingOptions policy = FormattingOptionsFactory.CreateKRStyle();

            Test(policy, @"class Test
{
	void TestMethod()
	{
		int i = 0;
		if (i == 0) {
		} else
			if (i == 1) {
		} else
if (i == 2) {
		} else                     if (i == 2)	
		Foo();
		else {
		}
	}
}", @"class Test
{
	void TestMethod()
	{
		int i = 0;
		if (i == 0) {
		} else if (i == 1) {
		} else if (i == 2) {
		} else if (i == 2)
			Foo();
		else {
		}
	}
}");
        }
コード例 #2
0
        private static CSharpFormattingOptions CreateOptionSet(FormattingOptionSet defaultOptionSet)
        {
            switch (defaultOptionSet)
            {
            case FormattingOptionSet.Orcomp:
                return(CreateOrcompOptions());

            case FormattingOptionSet.KRStyle:
                return(FormattingOptionsFactory.CreateKRStyle());

            case FormattingOptionSet.Mono:
                return(FormattingOptionsFactory.CreateMono());

            case FormattingOptionSet.SharpDevelop:
                return(FormattingOptionsFactory.CreateSharpDevelop());

            case FormattingOptionSet.VisualStudio:
                return(FormattingOptionsFactory.CreateAllman());

            case FormattingOptionSet.GNU:
                return(FormattingOptionsFactory.CreateGNU());

            case FormattingOptionSet.Whitesmiths:
                return(FormattingOptionsFactory.CreateWhitesmiths());

            default:
                return(FormattingOptionsFactory.CreateAllman());
            }
        }
コード例 #3
0
        private string renderTemplate(string template, Dictionary <string, object> dict)
        {
            var ret = Nustache.Core.Render.StringToString(template, dict);

            var root  = (new CSharpParser()).Parse(ret);
            var style = FormattingOptionsFactory.CreateKRStyle();

            return(cleanUpSpacing(root.ToString()));
        }
コード例 #4
0
        private static CSharpFormattingOptions CreateFormattingOptions()
        {
            var result = FormattingOptionsFactory.CreateKRStyle();

            result.NamespaceBraceStyle         = BraceStyle.EndOfLine;
            result.ClassBraceStyle             = BraceStyle.EndOfLine;
            result.EnumBraceStyle              = BraceStyle.EndOfLine;
            result.InterfaceBraceStyle         = BraceStyle.EndOfLine;
            result.ConstructorBraceStyle       = BraceStyle.EndOfLine;
            result.MethodBraceStyle            = BraceStyle.EndOfLine;
            result.PropertyBraceStyle          = BraceStyle.EndOfLine;
            result.BlankLinesBetweenMembers    = 1;
            result.AllowPropertyGetBlockInline = true;
            result.AllowPropertySetBlockInline = true;
            result.BlankLinesAfterUsings       = 1;
            return(result);
        }
コード例 #5
0
        public void TestIfElseNewLine()
        {
            CSharpFormattingOptions policy = FormattingOptionsFactory.CreateKRStyle();

            policy.ElseIfNewLinePlacement = NewLinePlacement.NewLine;
            Test(policy, @"class Test
{
	void TestMethod()
	{
		int i = 0;
		if (i == 0) {
		} else
			if (i == 1) {
		} else
if (i == 2) {
		} else                     if (i == 2)	
		Foo();
		else {
		}
	}
}", @"class Test
{
	void TestMethod()
	{
		int i = 0;
		if (i == 0) {
		} else
		if (i == 1) {
		} else
		if (i == 2) {
		} else
		if (i == 2)
			Foo();
		else {
		}
	}
}");
        }
コード例 #6
0
        private void GenerateCSharpFile(string projectName, string outputDirectory, bool xmlDocFood, bool generetaNUnit, FormatStyleEnum formatIndex, string formatFile, bool sortUsing, int templateIndex)
        {
            // To DO
            // For each file
            // http://msdn.microsoft.com/en-us/library/ee844259.aspx
            //TemplateStandard page = new TemplateStandard(xmlDocFood, sortUsing);
            //String pageContent = page.TransformText();
            //System.IO.File.WriteAllText("outputPage.cs", pageContent);

            // Format this new C# source file
            CSharpFormattingOptions format;

            switch (formatIndex)
            {
            case FormatStyleEnum.Empty:
                // Nothing to do!
                // format = FormattingOptionsFactory.CreateEmpty();
                break;

            case FormatStyleEnum.Mono:
                format = FormattingOptionsFactory.CreateMono();
                break;

            case FormatStyleEnum.KR_style:
                format = FormattingOptionsFactory.CreateKRStyle();
                break;

            case FormatStyleEnum.Allman_Visual_Studio:
                format = FormattingOptionsFactory.CreateAllman();
                break;

            case FormatStyleEnum.Whitesmiths:
                format = FormattingOptionsFactory.CreateWhitesmiths();
                break;

            case FormatStyleEnum.GNU:
                format = FormattingOptionsFactory.CreateGNU();
                break;

            case FormatStyleEnum.Custom:
                format = (CSharpFormattingOptions)CSharpFormattingOptionsUI.Load(formatFile);
                break;

            default:
                // unknow value!
                // TO DO : Throw an error
                break;
            }

            // Genereta NUnit test class
            if (generetaNUnit == true)
            {
                // Generate the project
                NStub.CSharp.CSharpProjectGenerator gen = new NStub.CSharp.CSharpProjectGenerator(String.Format("{0}_unitary_tests", projectName), outputDirectory);
                // gen.ReferencedAssemblies

                gen.GenerateProjectFile();

                /*
                 * // Generate the test case file
                 * foreach(string origFile in )
                 * {
                 *  CSharpCodeGenerator unitFile = new CSharpCodeGenerator(origFile, origFile);
                 *  unitFile.GenerateCode();
                 * }
                 */
            }
        }