public void GivenPascalCaseName_ReturnsDashedName()
            {
                const string name   = "InputSpecification";
                var          result = CamelCase.ToDashedName(name);

                result.Should().Be("input-specification");
            }
示例#2
0
    static void Main(string[] args)
    {
        Kangaroo kangaroo = new Kangaroo();

        kangaroo.Run();

        CamelCase camelCase = new CamelCase();

        camelCase.Run();

        StrongPassword strongPassword = new StrongPassword();

        strongPassword.Run();

        GradingStudents gradingStudents = new GradingStudents();

        gradingStudents.Run();

        IceCreamParlor iceCreamParlor = new IceCreamParlor();

        iceCreamParlor.Run();

        SockMerchant sockMerchant = new SockMerchant();

        sockMerchant.Run();

        RepeatedStrings repeatedStrings = new RepeatedStrings();

        repeatedStrings.Run();
    }
示例#3
0
        /// <summary>
        /// Resolves the specified property name.
        /// </summary>
        /// <param name="name">The property name to resolve.</param>
        /// <returns>The resolved property name.</returns>
        public string ResolvePropertyName(NamingStrategy namingStragegy, string name)
        {
            switch (namingStragegy.Kind)
            {
            case NamingStrategyKind.Default:
            {
                return(Default.ResolvePropertyName((DefaultNamingStrategy)namingStragegy, name));
            }

            case NamingStrategyKind.CamelCase:
            {
                return(CamelCase.ResolvePropertyName((CamelCaseNamingStrategy)namingStragegy, name));
            }

            case NamingStrategyKind.SnakeCase:
            {
                return(SnakeCase.ResolvePropertyName((SnakeCaseNamingStrategy)namingStragegy, name));
            }

            default:
            {
                throw XExceptions.NotSupported.EnumerationValueIsNotValid();
            }
            }
        }
        public static void ThisToStringTest(string input, string expected)
        {
            CamelCase cc     = new CamelCase();
            string    result = cc.ThisToString(input);

            Assert.Equal(result, expected);
        }
示例#5
0
 public override ApplicationState Hydrate(IDictionary <string, object> aKeyValuePairs)
 {
     return(new ApplicationState
     {
         Guid = new System.Guid(aKeyValuePairs[CamelCase.MemberNameToCamelCase(nameof(Guid))].ToString()),
         Name = aKeyValuePairs[CamelCase.MemberNameToCamelCase(nameof(Name))].ToString(),
     });
 }
示例#6
0
            static void Main(string[] args)
            {
                Console.WriteLine("CamelCase.Main()");
                //Make sure that the (CamelCase class) is public and static.
                Console.WriteLine(CamelCase.toCamelCase("mary had a liTTle"));

                Console.ReadKey();
            }
示例#7
0
        public void MemberNameToCamelCase_Invalid(string input)
        {
            var ex = Assert.Throws <ArgumentException>(() =>
                                                       CamelCase.MemberNameToCamelCase(input));

            Assert.Equal("value", ex.ParamName);
            Assert.StartsWith($"The value '{input ?? "null"}' is not a valid member name.", ex.Message);
        }
 public override RouteState Hydrate(IDictionary <string, object> aKeyValuePairs)
 {
     return(new RouteState
     {
         Guid = new System.Guid(aKeyValuePairs[CamelCase.MemberNameToCamelCase(nameof(Guid))].ToString()),
         Route = aKeyValuePairs[CamelCase.MemberNameToCamelCase(nameof(Route))].ToString()
     });
 }
示例#9
0
        public void Testcase0()
        {
            string input    = "saveChangesInTheEditor";
            int    expected = 5;
            int    result   = CamelCase.camelcase(input);

            Assert.AreEqual(expected, result);
        }
示例#10
0
        public override CounterState Hydrate(IDictionary <string, object> aKeyValuePairs)
        {
            var counterState = new CounterState()
            {
                Count = Convert.ToInt32(aKeyValuePairs[CamelCase.MemberNameToCamelCase(nameof(Count))].ToString(), CultureInfo.InvariantCulture),
                Guid  = new System.Guid(aKeyValuePairs[CamelCase.MemberNameToCamelCase(nameof(Guid))].ToString()),
            };

            return(counterState);
        }
示例#11
0
        public override string ConvertName(string name)
        {
            // We need to camelCase everything but this one property or the host won't honor it.
            if (string.Equals("IsCodeless", name, System.StringComparison.OrdinalIgnoreCase))
            {
                return("IsCodeless");
            }

            return(CamelCase.ConvertName(name));
        }
        public override WeatherForecastsState Hydrate(IDictionary <string, object> aKeyValuePairs)
        {
            var newWeatherForecastsState = new WeatherForecastsState
            {
                _WeatherForecasts = Json.Deserialize <List <WeatherForecastDto> >(
                    aKeyValuePairs[CamelCase.MemberNameToCamelCase(nameof(WeatherForecasts))].ToString()),
                Guid = new System.Guid((string)aKeyValuePairs[CamelCase.MemberNameToCamelCase(nameof(Guid))]),
            };

            return(newWeatherForecastsState);
        }
示例#13
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            Console.WriteLine(Sorts.StringSort("cat"));
            Console.WriteLine(CamelCase.ConvertToCamel("The Cat! In The Hat"));
            Console.WriteLine(Prime.IsPrime(10));
            Console.WriteLine(Prime.IsPrime(11));
            Console.WriteLine(Prime.IsPrime(14));
            Console.WriteLine(Prime.IsPrime(17));
            Console.WriteLine(Prime.SumOfPrimes(10));
        }
示例#14
0
        public override WeatherForecastsState Hydrate(IDictionary <string, object> aKeyValuePairs)
        {
            string json = aKeyValuePairs[CamelCase.MemberNameToCamelCase(nameof(WeatherForecasts))].ToString();
            var    newWeatherForecastsState = new WeatherForecastsState()
            {
                _WeatherForecasts = JsonSerializer.Parse <List <WeatherForecastDto> >(json, new JsonSerializerOptions {
                    PropertyNamingPolicy = JsonNamingPolicy.CamelCase
                }),
                Guid = new System.Guid(aKeyValuePairs[CamelCase.MemberNameToCamelCase(nameof(Guid))].ToString()),
            };

            return(newWeatherForecastsState);
        }
示例#15
0
        public override __FeatureName__State Hydrate(IDictionary <string, object> aKeyValuePairs)
        {
            string json = aKeyValuePairs[CamelCase.MemberNameToCamelCase(nameof(__FeatureName__s))].ToString();
            var    __FeatureName__State = new __FeatureName__State()
            {
                ___FeatureName__s = JsonSerializer.Deserialize <Dictionary <Guid, __FeatureName__Dto> >
                                    (
                    json, new JsonSerializerOptions {
                    PropertyNamingPolicy = JsonNamingPolicy.CamelCase
                }
                                    ),
                Guid = new System.Guid(aKeyValuePairs[CamelCase.MemberNameToCamelCase(nameof(Guid))].ToString()),
            };

            return(__FeatureName__State);
        }
示例#16
0
        public void CamelCase_ToCamelCase_RandomTests()
        {
            var    random = new Random();
            string randomStr;

            for (int i = 0; i < 10; i++)
            {
                randomStr =
                    String.Join("", Enumerable.Range(0, 10).Select(o => (char)random.Next('a', 'z')))
                    + "_"
                    + String.Join("", Enumerable.Range(0, 10).Select(o => (char)random.Next('a', 'z')))
                    + "-"
                    + String.Join("", Enumerable.Range(0, 10).Select(o => (char)random.Next('a', 'z')));

                Assert.AreEqual(Solution(randomStr), CamelCase.ToCamelCase(randomStr));
            }
        }
示例#17
0
 public override string ConvertName(string name)
 {
     if (name == "Validity")
     {
         return("VALIDITY");
     }
     else if (name == "Offset")
     {
         return("OFFSET");
     }
     else if (name == "TypeId")
     {
         return("TYPE_ID");
     }
     else if (name == "Data")
     {
         return("DATA");
     }
     else
     {
         return(CamelCase.ConvertName(name));
     }
 }
示例#18
0
 public void MemberNameToCamelCase_Valid(string input, string expectedOutput)
 {
     Assert.Equal(expectedOutput, CamelCase.MemberNameToCamelCase(input));
 }
 public override string ConvertName(string name)
 {
     if (name.Length > 1)
     {
         name = CamelCase.ConvertName(name);
         return(char.ToLowerInvariant(name[0]) + name[1..]);
示例#20
0
 public CamelCaseTest()
 {
     camelCase = new CamelCase();
 }
 public void convertToCamelTest6()
 {
     Assert.AreEqual("4321", CamelCase.convertToCamel("4321"));
 }
 public void convertToCamelTest5()
 {
     Assert.AreEqual("manySpaces", CamelCase.convertToCamel("many         spaces"));
 }
 public void convertToCamelTest4()
 {
     Assert.AreEqual("imAJerkTest", CamelCase.convertToCamel("    I'm a jerk test."));
 }
 public void convertToCamelTest3()
 {
     Assert.AreEqual("iAmWorkingNow", CamelCase.convertToCamel("I AM WORKING NOW"));
 }
 public void convertToCamelTest2()
 {
     Assert.AreEqual("testTestTest", CamelCase.convertToCamel("test Test tEsT"));
 }
示例#26
0
 public void TestCamelCase()
 {
     Assert.AreEqual(5, CamelCase.camelcase("saveChangesInTheEditor"));
 }
示例#27
0
        /// <summary>
        /// Creates a CodeDOM method to compare two rows of a document for the purpose of sorting.
        /// </summary>
        /// <param name="templateNode">Contains the specification for the template.</param>
        public SortCompareMethod(DataTransform.ApplyTemplateNode applyTemplateNode)
        {
            // The sort works very efficiently by examining the tiles using the column ordinals as indices into the row.  The View
            // class defines these ordinals as public constants.
            DataTransform dataTransform = applyTemplateNode.TopLevelNode as DataTransform;

            //			#region IComparer<ViewerRow> Members
            this.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start, "IComparer<ViewerRow> Members"));

            //		// <summary>
            //		// Compares a row with another row using the column values to determine the order.
            //		// </summary>
            //		// <param name="x">The first row to be compared.</param>
            //		// <param name="y">The second row to be compared.</param>
            //		// <returns>A 32-bit signed integer that indicates the relative order of the objects being compared.</returns>
            //		public virtual int Compare(MarkThree.Forms.ViewerRow x, MarkThree.Forms.ViewerRow y)
            //		{
            this.Comments.Add(new CodeCommentStatement(@"<summary>"));
            this.Comments.Add(new CodeCommentStatement(@"Compares a row with another row using the column values to determine the order."));
            this.Comments.Add(new CodeCommentStatement(@"</summary>"));
            this.Comments.Add(new CodeCommentStatement(@"<param name=""x"">The first row to be compared.</param>"));
            this.Comments.Add(new CodeCommentStatement(@"<param name=""y"">The second row to be compared.</param>"));
            this.Comments.Add(new CodeCommentStatement(@"<returns>A 32-bit signed integer that indicates the relative order of the objects being compared.</returns>"));
            this.Attributes = MemberAttributes.Public;
            this.ReturnType = new CodeTypeReference(typeof(int));
            this.Name       = "Compare";
            this.Parameters.Add(new CodeParameterDeclarationExpression(typeof(ViewerRow), "x"));
            this.Parameters.Add(new CodeParameterDeclarationExpression(typeof(ViewerRow), "y"));

            //			// The order of the comparison determines whether the rows are sorted in ascending order or descending.  If the values
            //			// compared in one set of tiles is equal, then the next set of tiles in the sort order will be compared.
            //			MarkThree.Forms.ViewerTile xTile0 = ((MarkThree.Forms.ViewerTile)(x.Tile[PrototypeView.symbolIndex]));
            //			MarkThree.Forms.ViewerTile yTile0 = ((MarkThree.Forms.ViewerTile)(y.Tile[PrototypeView.symbolIndex]));
            //			int compare0 = xTile0.CompareTo(yTile0);
            //			if ((compare0 != 0))
            //			{
            //				return compare0;
            //			}
            //			return ((IComparable)y.Data[PrototypeView.sourceOrderQuantityIndex]).CompareTo(x.Data[PrototypeView.sourceOrderQuantityIndex]);
            this.Statements.Add(new CodeCommentStatement("The order of the comparison determines whether the rows are sorted in ascending order or descending.  If the values"));
            this.Statements.Add(new CodeCommentStatement("compared in one set of tiles is equal, then the next set of tiles in the sort order will be compared."));
            for (int index = 0; index < applyTemplateNode.Sorts.Count; index++)
            {
                DataTransform.SortNode sortNode = applyTemplateNode.Sorts[index];
                string columnReference          = string.Format("{0}Index", CamelCase.Convert(sortNode.Column.ColumnId));
                string operand1 = sortNode.Direction == SortOrder.Ascending ? "x" : "y";
                string operand2 = sortNode.Direction == SortOrder.Ascending ? "y" : "x";
                if (index != applyTemplateNode.Sorts.Count - 1)
                {
                    string compareVariableName = string.Format("compare{0}", index);
                    this.Statements.Add(new CodeVariableDeclarationStatement(typeof(int), compareVariableName, new CodeMethodInvokeExpression(new CodeCastExpression(typeof(IComparable),
                                                                                                                                                                     new CodeIndexerExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(operand1), "Data"),
                                                                                                                                                                                               new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(dataTransform.DataTransformId), columnReference))), "CompareTo",
                                                                                                                                              new CodeIndexerExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(operand2), "Data"),
                                                                                                                                                                        new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(dataTransform.DataTransformId), columnReference)))));
                    this.Statements.Add(new CodeConditionStatement(new CodeBinaryOperatorExpression(new CodeVariableReferenceExpression(compareVariableName), CodeBinaryOperatorType.IdentityInequality, new CodePrimitiveExpression(0)), new CodeMethodReturnStatement(new CodeVariableReferenceExpression(compareVariableName))));
                }
                else
                {
                    this.Statements.Add(new CodeMethodReturnStatement(new CodeMethodInvokeExpression(new CodeCastExpression(typeof(IComparable),
                                                                                                                            new CodeIndexerExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(operand1), "Data"),
                                                                                                                                                      new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(dataTransform.DataTransformId), columnReference))), "CompareTo",
                                                                                                     new CodeIndexerExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(operand2), "Data"),
                                                                                                                               new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(dataTransform.DataTransformId), columnReference)))));
                }
            }

            //		#endregion
            this.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, string.Empty));
        }
        /// <summary>
        /// Creates the method that is the starting point for the document creation.
        /// </summary>
        /// <param name="dataTransform">Describes how to create a document from an abstract data model.</param>
        public DataTransformInitializeViewMethod(DataTransform dataTransform)
        {
            //			/// <summary>
            //			/// Builds the styles used to display data in the document.
            //			/// </summary>
            //			public override void InitializeView(List<ViewerCommand> viewerCommands)
            //			{
            this.Comments.Add(new CodeCommentStatement("<summary>", true));
            this.Comments.Add(new CodeCommentStatement("Builds the styles used to display data in the document.", true));
            this.Comments.Add(new CodeCommentStatement("</summary>", true));
            this.Attributes = MemberAttributes.Public | MemberAttributes.Override;
            this.ReturnType = new CodeTypeReference(typeof(void));
            this.Name       = "InitializeView";

            //			// Split the screen into quadrants.
            //			this.documentViewer.ViewerCommandQueue.Enqueue(new MarkThree.Forms.ViewerCommand(new MarkThree.Forms.ViewerSplit(new System.Drawing.SizeF(54F, 55F)), new MarkThree.Forms.ViewerCommandDelegate(this.documentViewer.SetSplit)));
            SizeF splitSize = dataTransform.SplitSize;

            if (splitSize != SizeF.Empty)
            {
                this.Statements.Add(new CodeCommentStatement("Split the screen into quadrants."));
                this.Statements.Add(new CodeMethodInvokeExpression(new CodeFieldReferenceExpression(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "documentViewer"), "ViewerCommandQueue"), "Enqueue",
                                                                   new CodeObjectCreateExpression(typeof(ViewerCommand), new CodeObjectCreateExpression(typeof(ViewerSplit), new CodeObjectCreateExpression(typeof(SizeF), new CodePrimitiveExpression(splitSize.Width), new CodePrimitiveExpression(splitSize.Height))),
                                                                                                  new CodeObjectCreateExpression(typeof(ViewerCommandDelegate), new CodeMethodReferenceExpression(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "documentViewer"), "SetSplit")))));
            }

            //			// Set the magnification factor.
            //			this.documentViewer.ViewerCommandQueue.Enqueue(new MarkThree.Forms.ViewerCommand(new MarkThree.Forms.ViewerScale(1.25F), new MarkThree.Forms.ViewerCommandDelegate(this.documentViewer.SetScale)));
            float scaleFactor = dataTransform.ScaleFactor;

            if (scaleFactor != DefaultDocument.ScaleFactor)
            {
                this.Statements.Add(new CodeCommentStatement("Set the magnification factor."));
                this.Statements.Add(new CodeMethodInvokeExpression(new CodeFieldReferenceExpression(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "documentViewer"), "ViewerCommandQueue"), "Enqueue",
                                                                   new CodeObjectCreateExpression(typeof(ViewerCommand), new CodeObjectCreateExpression(typeof(ViewerScale), new CodePrimitiveExpression(scaleFactor)),
                                                                                                  new CodeObjectCreateExpression(typeof(ViewerCommandDelegate), new CodeMethodReferenceExpression(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "documentViewer"), "SetScale")))));
            }

            // This will generate each of the styles in turn and add them to the range of styles that is sent to the viewer.
            // The viewer will then use these styles to match up the incoming tiles to instructions to present them in the
            // document.
            foreach (DataTransform.StyleNode styleNode in dataTransform.Styles)
            {
                //					// Header Style
                //					MarkThree.Forms.ViewerStyle headerStyle = this.documentViewer.GetStyle("Default");
                //					if (("Default" != headerStyle.ParentId))
                //					{
                //						headerStyle.ParentId = "Default";
                //						headerStyle.IsModified = true;
                //					}
                //					headerStyle.Attributes.Add(new MarkThree.Forms.ViewerBottomBorder(System.Drawing.Color.DarkGray, 1F));
                //					headerStyle.Attributes.Add(new MarkThree.Forms.ViewerRightBorder(System.Drawing.Color.DarkGray, 1F));
                //					headerStyle.Attributes.Add(new MarkThree.Forms.ViewerInteriorBrush(System.Drawing.Color.FromKnownColor(System.Drawing.KnownColor.Control)));
                //					headerStyle.Attributes.Add(new MarkThree.Forms.ViewerImage(this.documentViewer.Variables["GreenCheckImage"]));
                this.Statements.Add(new CodeCommentStatement(string.Format("{0} Style", styleNode.StyleId)));
                string variableName = string.Format("{0}Style", CamelCase.Convert(styleNode.StyleId));
                this.Statements.Add(new CodeVariableDeclarationStatement(typeof(ViewerStyle), variableName, new CodeMethodInvokeExpression(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "documentViewer"), "GetStyle", new CodePrimitiveExpression(styleNode.StyleId))));
                if (styleNode.ParentStyle != null)
                {
                    CodeStatement[] trueStatements0 = new CodeStatement[2];
                    trueStatements0[0] = new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(variableName), "ParentId"), new CodePrimitiveExpression(styleNode.ParentStyle.StyleId));
                    trueStatements0[1] = new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(variableName), "IsModified"), new CodePrimitiveExpression(true));
                    this.Statements.Add(new CodeConditionStatement(new CodeBinaryOperatorExpression(new CodePrimitiveExpression(styleNode.ParentStyle.StyleId), CodeBinaryOperatorType.IdentityInequality, new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(variableName), "ParentId")), trueStatements0));
                }
                if (styleNode.HasAnimation)
                {
                    if (styleNode.Animation.Effect == Effect.Fade)
                    {
                        this.Statements.Add(new CodeMethodInvokeExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(variableName), "Attributes"), "Add", new CodeObjectCreateExpression(typeof(ViewerFadeAnimation), CodeSnippet.Convert(styleNode.Animation.Up), CodeSnippet.Convert(styleNode.Animation.Down), CodeSnippet.Convert(styleNode.Animation.Same), new CodePrimitiveExpression(styleNode.Animation.Steps))));
                    }
                    if (styleNode.Animation.Effect == Effect.Flash)
                    {
                        this.Statements.Add(new CodeMethodInvokeExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(variableName), "Attributes"), "Add", new CodeObjectCreateExpression(typeof(ViewerFlashAnimation), CodeSnippet.Convert(styleNode.Animation.Foreground), CodeSnippet.Convert(styleNode.Animation.Background), new CodePrimitiveExpression(styleNode.Animation.On), new CodePrimitiveExpression(styleNode.Animation.Off), new CodePrimitiveExpression(styleNode.Animation.Repeat))));
                    }
                }
                if (styleNode.HasBottomBorder)
                {
                    this.Statements.Add(new CodeMethodInvokeExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(variableName), "Attributes"), "Add", new CodeObjectCreateExpression(typeof(ViewerBottomBorder), CodeSnippet.Convert(styleNode.BottomBorder.Color), new CodePrimitiveExpression(styleNode.BottomBorder.Width))));
                }
                if (styleNode.HasLeftBorder)
                {
                    this.Statements.Add(new CodeMethodInvokeExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(variableName), "Attributes"), "Add", new CodeObjectCreateExpression(typeof(ViewerLeftBorder), CodeSnippet.Convert(styleNode.LeftBorder.Color), new CodePrimitiveExpression(styleNode.LeftBorder.Width))));
                }
                if (styleNode.HasRightBorder)
                {
                    this.Statements.Add(new CodeMethodInvokeExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(variableName), "Attributes"), "Add", new CodeObjectCreateExpression(typeof(ViewerRightBorder), CodeSnippet.Convert(styleNode.RightBorder.Color), new CodePrimitiveExpression(styleNode.RightBorder.Width))));
                }
                if (styleNode.HasTopBorder)
                {
                    this.Statements.Add(new CodeMethodInvokeExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(variableName), "Attributes"), "Add", new CodeObjectCreateExpression(typeof(ViewerTopBorder), CodeSnippet.Convert(styleNode.TopBorder.Color), new CodePrimitiveExpression(styleNode.TopBorder.Width))));
                }
                if (styleNode.HasFont)
                {
                    if (styleNode.Font.Style == FontStyle.Regular)
                    {
                        this.Statements.Add(new CodeMethodInvokeExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(variableName), "Attributes"), "Add", new CodeObjectCreateExpression(typeof(ViewerFont), CodeSnippet.Convert(styleNode.Font.FontFamily), new CodePrimitiveExpression(styleNode.Font.Size))));
                    }
                    else
                    {
                        this.Statements.Add(new CodeMethodInvokeExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(variableName), "Attributes"), "Add", new CodeObjectCreateExpression(typeof(ViewerFont), CodeSnippet.Convert(styleNode.Font.FontFamily), new CodePrimitiveExpression(styleNode.Font.Size), CodeSnippet.Convert(styleNode.Font.Style))));
                    }
                }
                if (styleNode.HasFontBrush)
                {
                    this.Statements.Add(new CodeMethodInvokeExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(variableName), "Attributes"), "Add", new CodeObjectCreateExpression(typeof(ViewerFontBrush), CodeSnippet.Convert(styleNode.ForeColor))));
                }
                if (styleNode.HasStringFormat)
                {
                    this.Statements.Add(new CodeMethodInvokeExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(variableName), "Attributes"), "Add", new CodeObjectCreateExpression(typeof(ViewerStringFormat), CodeSnippet.Convert(styleNode.StringFormat.Alignment), CodeSnippet.Convert(styleNode.StringFormat.LineAlignment))));
                }
                if (styleNode.HasNumberFormat)
                {
                    this.Statements.Add(new CodeMethodInvokeExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(variableName), "Attributes"), "Add", new CodeObjectCreateExpression(typeof(ViewerNumberFormat), new CodePrimitiveExpression(styleNode.NumberFormat))));
                }
                if (styleNode.HasInterior)
                {
                    this.Statements.Add(new CodeMethodInvokeExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(variableName), "Attributes"), "Add", new CodeObjectCreateExpression(typeof(ViewerInteriorBrush), CodeSnippet.Convert(styleNode.BackColor))));
                }
                if (styleNode.HasImage)
                {
                    this.Statements.Add(new CodeMethodInvokeExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(variableName), "Attributes"), "Add", new CodeObjectCreateExpression(typeof(ViewerImage), new CodeCastExpression(typeof(Image), new CodeIndexerExpression(new CodeFieldReferenceExpression(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "documentViewer"), "Variables"), new CodePrimitiveExpression(styleNode.Image))))));
                }
            }
        }
示例#29
0
        /// <summary>
        /// Generates the class that transforms a data model into a human read-able document.
        /// </summary>
        /// <param name="dataTransform">Describes how to transform abstract data into a document.</param>
        public DataTransformClass(DataTransform dataTransform)
        {
            //	/// <summary>
            //	/// Transforms a data model into a document.
            //	/// </summary>
            //	public class PrototypeView : DocumentView
            //	{
            this.Comments.Add(new CodeCommentStatement("<summary>", true));
            this.Comments.Add(new CodeCommentStatement("Transforms a data model into a document.", true));
            this.Comments.Add(new CodeCommentStatement("</summary>", true));
            this.Name = dataTransform.DataTransformId;
            this.BaseTypes.Add("DocumentView");

            // The Column Index (Absolute Order) Constants
            //		// Constant Column Indices
            //		internal const int workingStatusImageIndex = 0;
            //		internal const int submittedStatusImageIndex = 1;
            //		internal const int recordIdIndex = 2;
            bool isFirstColumnIndexConstant = true;

            for (int columnIndex = 0; columnIndex < dataTransform.Columns.Count; columnIndex++)
            {
                DataTransform.ColumnNode columnNode = dataTransform.Columns[columnIndex];
                string          constantName        = CamelCase.Convert(columnNode.ColumnId) + "Index";
                CodeMemberField codeMemberField     = new CodeMemberField(typeof(Int32), constantName);
                if (isFirstColumnIndexConstant)
                {
                    isFirstColumnIndexConstant = false;
                    codeMemberField.Comments.Add(new CodeCommentStatement("Constant Column Indices (Column Order)"));
                }
                codeMemberField.Attributes     = MemberAttributes.Const | MemberAttributes.Assembly;
                codeMemberField.InitExpression = new CodePrimitiveExpression(columnIndex);
                this.Members.Add(codeMemberField);
            }

            // The Column Ordinal (Viewer Order) Constants
            //		// Constant Column Indices
            //		internal const int workingStatusImageOrdinal = 0;
            //		internal const int submittedStatusImageOrdinal = 1;
            //		internal const int recordIdOrdinal = 2;
            bool isFirstColumnOrdinalConstant = true;

            for (int columnOrdinal = 0; columnOrdinal < dataTransform.View.Count; columnOrdinal++)
            {
                DataTransform.ColumnNode columnNode = dataTransform.View[columnOrdinal].Column;
                string          constantName        = CamelCase.Convert(columnNode.ColumnId) + "Ordinal";
                CodeMemberField codeMemberField     = new CodeMemberField(typeof(Int32), constantName);
                if (isFirstColumnOrdinalConstant)
                {
                    isFirstColumnOrdinalConstant = false;
                    codeMemberField.Comments.Add(new CodeCommentStatement("Constant Column Ordinals (Viewer Order)"));
                }
                codeMemberField.Attributes     = MemberAttributes.Const | MemberAttributes.Assembly;
                codeMemberField.InitExpression = new CodePrimitiveExpression(columnOrdinal);
                this.Members.Add(codeMemberField);
            }

            // The Row Height Constants.
            //		// Constant Row Heights
            //		private const float headerRowHeight = 40F;
            //		private const float workingOrderRowHeight = 20F;
            //		private const float sourceOrderRowHeight = 20F;
            //		private const float destinationOrderRowHeight = 20F;
            //		private const float executionRowHeight = 20F;
            bool isFirstRowHeightConstant = true;

            foreach (DataTransform.TemplateNode templateNode in dataTransform.Templates)
            {
                foreach (DataTransform.RowNode rowNode in templateNode.Rows)
                {
                    string          constantName    = CamelCase.Convert(rowNode.RowId) + "Height";
                    CodeMemberField codeMemberField = new CodeMemberField(typeof(Single), constantName);
                    if (isFirstRowHeightConstant)
                    {
                        isFirstRowHeightConstant = false;
                        codeMemberField.Comments.Add(new CodeCommentStatement("Constant Row Heights"));
                    }
                    codeMemberField.Attributes     = MemberAttributes.Const | MemberAttributes.Private;
                    codeMemberField.InitExpression = new CodePrimitiveExpression(rowNode.Height);
                    this.Members.Add(codeMemberField);
                }
            }

            // The Row Width Constants.
            //		// Constant Row Widths
            //		private const float headerRowHeight = 745F;
            //		private const float workingOrderRowHeight = 745F;
            //		private const float sourceOrderRowHeight = 745F;
            //		private const float destinationOrderRowHeight = 745F;
            //		private const float executionRowHeight = 745F;
            bool isFirstRowWidthConstant = true;

            foreach (DataTransform.TemplateNode templateNode in dataTransform.Templates)
            {
                foreach (DataTransform.RowNode rowNode in templateNode.Rows)
                {
                    string          constantName    = CamelCase.Convert(rowNode.RowId) + "Width";
                    CodeMemberField codeMemberField = new CodeMemberField(typeof(Single), constantName);
                    if (isFirstRowWidthConstant)
                    {
                        isFirstRowWidthConstant = false;
                        codeMemberField.Comments.Add(new CodeCommentStatement("Constant Row Widths"));
                    }
                    codeMemberField.Attributes = MemberAttributes.Const | MemberAttributes.Private;
                    float rowWidth = 0.0f;
                    foreach (DataTransform.ColumnReferenceNode columnReferenceNode in dataTransform.View)
                    {
                        rowWidth += columnReferenceNode.Column.Width;
                    }
                    codeMemberField.InitExpression = new CodePrimitiveExpression(rowWidth);
                    this.Members.Add(codeMemberField);
                }
            }

            // The Column Width Constants.
            //		// Constant Column Widths
            //		private const float askPriceWidth = 53F;
            //		private const float availableQuantityWidth = 56F;
            //		private const float bidPriceWidth = 53F;
            //		private const float destinationOrderQuantityWidth = 56F;
            bool isFirstColumnWidthConstant = true;

            foreach (DataTransform.ColumnNode columnNode in dataTransform.Columns)
            {
                string          constantName    = CamelCase.Convert(columnNode.ColumnId) + "Width";
                CodeMemberField codeMemberField = new CodeMemberField(typeof(Single), constantName);
                if (isFirstColumnWidthConstant)
                {
                    isFirstColumnWidthConstant = false;
                    codeMemberField.Comments.Add(new CodeCommentStatement("Constant Column Widths"));
                }
                codeMemberField.Attributes     = MemberAttributes.Const | MemberAttributes.Private;
                codeMemberField.InitExpression = new CodePrimitiveExpression(columnNode.Width);
                this.Members.Add(codeMemberField);
            }

            // The Comparers
            //		// Comparers
            //		private System.Collections.Generic.IComparer<MarkThree.Forms.ViewerRow> workingOrderRowComparer;
            //		private System.Collections.Generic.IComparer<MarkThree.Forms.ViewerRow> sourceOrderRowComparer;
            //		private System.Collections.Generic.IComparer<MarkThree.Forms.ViewerRow> destinationOrderRowComparer;
            bool isFirstComparer = true;

            foreach (DataTransform.TemplateNode templateNode in dataTransform.Templates)
            {
                foreach (DataTransform.RowNode rowNode in templateNode.Rows)
                {
                    foreach (DataTransform.ApplyTemplateNode applyTemplateNode in rowNode.ApplyTemplates)
                    {
                        if (applyTemplateNode.Sorts.Count != 0)
                        {
                            string          comparerName    = CamelCase.Convert(applyTemplateNode.Select) + "RowComparer";
                            CodeMemberField codeMemberField = new CodeMemberField(typeof(IComparer <ViewerRow>), comparerName);
                            if (isFirstComparer)
                            {
                                isFirstComparer = false;
                                codeMemberField.Comments.Add(new CodeCommentStatement("Comparers"));
                            }
                            codeMemberField.Attributes = MemberAttributes.Private;
                            this.Members.Add(codeMemberField);
                        }
                    }
                }
            }


            // Add the constructor to the namespace.
            this.Members.Add(new DataTransformConstructor(dataTransform));

            // Add the Build method used to construct the styles.
            this.Members.Add(new DataTransformInitializeViewMethod(dataTransform));

            // Add the Build method used to construct the document.
            this.Members.Add(new DataTransformBuildViewMethod(dataTransform));

            // Add the code for all the template handlers.
            foreach (DataTransform.TemplateNode templateNode in dataTransform.Templates)
            {
                this.Members.Add(new DataTransformTemplateMethod(templateNode));
            }
        }
 public void convertToCamelTest1()
 {
     Assert.AreEqual("maryHadA", CamelCase.convertToCamel("Mary had A"));
 }