コード例 #1
0
        /// <summary>
        /// Generate one mock entity method from one imported declaration.
        /// </summary>
        /// <param name="scope">"upper" or "lower".</param>
        /// <param name="kind">"entity" or "response".</param>
        /// <param name="block">Entity meta block for either of the above.</param>
        /// <returns>List of output lines for this block.</returns>
        private List <string> GenerateBlock(string scope, string kind, EntityMetaBlock block)
        {
            List <string> output = new List <string>();
            string        line   = string.Empty;

            line = @"/// <summary>";
            output.Add(line);
            line = @"/// Mock " + scope.ToLower() + " " + DescriptionFromCamelCase(block.ShortName) + ".";
            output.Add(line);
            line = @"/// </summary>";
            output.Add(line);
            line = @"/// <param name=""seed"">Seed number to seed all properties with.</param>";
            output.Add(line);
            line = @"/// <returns>Mock " + scope.ToLower() + " " + DescriptionFromCamelCase(block.ShortName) + ".</returns>";
            output.Add(line);
            line = @"public " + block.Name + " GetMock" + ProperCase(scope) + block.ShortName + "(int seed)";
            output.Add(line);
            line = @"{";
            output.Add(line);
            line = "string digits = seed.ToString().Trim();";
            output.Add(line);
            line = block.Name + " " + kind + " = new " + block.Name + "();";
            output.Add(line);
            for (int count = 0; count < block.Properties.Count; count++)
            {
                string type      = block.Properties[count].Type;
                string property  = block.Properties[count].Property;
                string construct = GenerateConstruct(scope, type, property);
                line = kind + "." + property + " = " + construct;
                output.Add(line);
            }
            line = @"return " + kind + ";";
            output.Add(line);
            line = @"}";
            output.Add(line);
            return(output);
        }
コード例 #2
0
        /// <summary>
        /// Import property declarations within region-endregion block.
        /// </summary>
        /// <param name="lineNumber">Enters as starting line number, exits as next starting line number.</param>
        /// <returns>Entity meta block for foreign entity.</returns>
        public EntityMetaBlock ImportProperties(ref int lineNumber)
        {
            EntityMetaBlock block            = new EntityMetaBlock();
            Vector          vector           = null;
            string          line             = string.Empty;
            int             nPos1            = 0;
            int             nPos2            = 0;
            int             nEol             = 0;
            bool            propertiesOpened = false;
            bool            propertiesClosed = false;

            while (!propertiesClosed && lineNumber < _inputLines.Length)
            {
                line = _inputLines[lineNumber].Trim();
                if (line.Length > 0)
                {
                    if (!line.StartsWith("//"))
                    {
                        if (!propertiesOpened)
                        {
                            if (line.Contains("#region Properties"))
                            {
                                block = new EntityMetaBlock();
                                nPos1 = line.IndexOf("[");
                                if (nPos1 > -1)
                                {
                                    nPos2 = line.IndexOf("]");
                                    if (nPos2 > -1)
                                    {
                                        block.Name = line.Substring(nPos1 + 1, nPos2 - nPos1 - 1);
                                        if (block.Name.Contains("."))
                                        {
                                            string[] parts = block.Name.Split('.');
                                            block.ShortName = parts[parts.Length - 1];
                                        }
                                        else
                                        {
                                            block.ShortName = block.Name;
                                        }
                                    }
                                }
                                propertiesOpened = true;
                            }
                        }
                        else
                        {
                            if (line.EndsWith("#endregion"))
                            {
                                propertiesClosed = true;
                            }
                            else
                            {
                                if (line.StartsWith("public"))
                                {
                                    vector = new Vector();
                                    if (line.Contains(" readonly "))
                                    {
                                        vector.ReadOnly = true;
                                        line            = line.Replace("readonly ", string.Empty);
                                    }
                                    nPos1 = line.IndexOf(' ');
                                    if (nPos1 > -1)
                                    {
                                        vector.Modifier = line.Substring(0, nPos1).Trim();
                                        nPos2           = line.IndexOf(' ', nPos1 + 1);
                                        if (nPos2 > -1)
                                        {
                                            vector.Type     = line.Substring(nPos1, nPos2 - nPos1).Trim();
                                            nEol            = line.Length;
                                            vector.Property = line.Substring(nPos2, nEol - nPos2).Trim();
                                            vector.Variable = "_" + vector.Property.Substring(0, 1).ToLower() + vector.Property.Substring(1);
                                            vector.Summary  = TitleFromCamelCase(vector.Property) + ".";
                                        }
                                    }
                                    block.Properties.Add(vector);
                                }
                            }
                        }
                    }
                }
                lineNumber++;
            }
            return(block);
        }
コード例 #3
0
        /// <summary>
        /// Import member variable declarations within region-endregion block.
        /// </summary>
        /// <param name="lineNumber">Enters as starting line number, exits as next starting line number.</param>
        /// <returns>Entity meta block for home entity.</returns>
        public EntityMetaBlock ImportMemberVariables(ref int lineNumber)
        {
            EntityMetaBlock block  = new EntityMetaBlock();
            Vector          vector = null;
            string          line   = string.Empty;
            int             nPos1  = 0;
            int             nPos2  = 0;
            int             nEol   = 0;
            bool            memberVariablesOpened = false;
            bool            memberVariablesClosed = false;

            while (!memberVariablesClosed && lineNumber < _inputLines.Length)
            {
                line = _inputLines[lineNumber].Trim();
                if (line.Length > 0)
                {
                    if (!line.StartsWith("//"))
                    {
                        if (!memberVariablesOpened)
                        {
                            if (line.Contains("#region Member"))
                            {
                                block = new EntityMetaBlock();
                                nPos1 = line.IndexOf("[");
                                if (nPos1 > -1)
                                {
                                    nPos2 = line.IndexOf("]");
                                    if (nPos2 > -1)
                                    {
                                        block.Name = line.Substring(nPos1 + 1, nPos2 - nPos1 - 1);
                                        if (block.Name.Contains("."))
                                        {
                                            string[] parts = block.Name.Split('.');
                                            block.ShortName = parts[parts.Length - 1];
                                        }
                                        else
                                        {
                                            block.ShortName = block.Name;
                                        }
                                    }
                                }
                                memberVariablesOpened = true;
                            }
                        }
                        else
                        {
                            if (line.EndsWith("#endregion"))
                            {
                                memberVariablesClosed = true;
                            }
                            else
                            {
                                vector = new Vector();
                                if (line.Contains(" readonly "))
                                {
                                    vector.ReadOnly = true;
                                    line            = line.Replace("readonly ", string.Empty);
                                }
                                nPos1 = line.IndexOf(' ');
                                if (nPos1 > -1)
                                {
                                    vector.Modifier = line.Substring(0, nPos1).Trim();
                                    nPos2           = line.IndexOf(' ', nPos1 + 1);
                                    if (nPos2 > -1)
                                    {
                                        vector.Type = line.Substring(nPos1, nPos2 - nPos1).Trim();
                                        nEol        = line.Length;
                                        nPos1       = line.IndexOf(' ', nPos2 + 1);
                                        if (nPos1 > -1)
                                        {
                                            if (nPos1 < nEol)
                                            {
                                                nEol = nPos1;
                                            }
                                        }
                                        else
                                        {
                                            nPos1 = line.IndexOf('=', nPos2 + 1);
                                            if (nPos1 > -1)
                                            {
                                                if (nPos1 < nEol)
                                                {
                                                    nEol = nPos1;
                                                }
                                            }
                                            else
                                            {
                                                nPos1 = line.IndexOf(';', nPos2 + 1);
                                                if (nPos1 > -1)
                                                {
                                                    if (nPos1 < nEol)
                                                    {
                                                        nEol = nPos1;
                                                    }
                                                }
                                            }
                                        }
                                        if (nPos1 > -1)
                                        {
                                            vector.Variable = line.Substring(nPos2, nPos1 - nPos2).Trim();
                                            if (vector.Variable.Substring(0, 1) == "_")
                                            {
                                                vector.Property = vector.Variable.Substring(1, 1).ToUpper() + vector.Variable.Substring(2);
                                            }
                                            else
                                            {
                                                vector.Property = vector.Variable.Substring(2, 1).ToUpper() + vector.Variable.Substring(3);
                                            }
                                            vector.Summary = ProperCase(DescriptionFromCamelCase(vector.Property)) + ".";
                                        }
                                    }
                                }
                                block.MemberVariables.Add(vector);
                            }
                        }
                    }
                }
                lineNumber++;
            }
            return(block);
        }
コード例 #4
0
        /// <summary>
        /// Import member variable declarations.
        /// </summary>
        private void ImportLines()
        {
            int lineNumber = 0;

            _memberVariablesBlock = ImportMemberVariables(ref lineNumber);
        }
コード例 #5
0
 /// <summary>
 /// Import one set of property declarations.
 /// </summary>
 private void ImportLines()
 {
     int lineNumber = 0;
     _entityBlock = ImportProperties(ref lineNumber);
 }