Exemple #1
0
 /// <summary>
 /// Essentially calls the <see cref="ClassWtriter"/> class and writes the content in the file.
 /// </summary>
 private void TraceContent()
 {
     ClassWriter.SetRefferenceCount((uint)refferences);
     ClassWriter.SetPrivateFieldsCount(privateFieldsCount);
     ClassWriter.SetPublicFieldsCount(publicFieldsCount);
     ClassWriter.SetPrivateMethodsCount(privateMethodsCount);
     ClassWriter.SetPublicMethodsCount(publicMethodsCount);
     ClassWriter.SetInheritsList(inheritsList);
     foreach (string item in xmlContent)
     {
         ClassWriter.Parse(item);
     }
 }
Exemple #2
0
        /// <summary>
        /// Searches a given <see cref="XmlNode"/> and checks it's attributes.
        /// </summary>
        /// <param name="node"><see cref="XmlNode"/> to search and parse.</param>
        private string Search(XmlNode node)
        {
            #region Namespace
            if (node.Name == "nameSpace") //parsing the working namespace
            {
                if (node.Attributes["name"] != null)
                {
                    return(Namespace(node.Attributes["name"].Value));
                }
            }
            #endregion Namespace

            #region Reference
            if (node.Name == "ref" && !this.noDependencies) //non-empty "dependencies" tag..
            {
                if (node.Attributes["using"] != null)       //parsing all "using" directives
                {
                    refferences++; return(Using(node.Attributes["using"].Value));
                }
                else
                {
                    return($"{error} Missing \"using\" argument in \"<ref/>\" tag.");
                }
            }
            #endregion Reference

            #region Inherits

            if (node.Name == "inherit" && !this.noInherits)
            {
                if (node.Attributes["name"] != null)
                {
                    var  toInherit = node.Attributes["name"].Value;
                    bool generic   = false;
                    if (toInherit.EndsWith("{T}"))
                    {
                        toInherit = toInherit.Remove(toInherit.Length - 3, 3);
                        generic   = true;
                    }
                    if (generic)
                    {
                        inheritsList.Add($"{toInherit}<T>");
                    }
                    else
                    {
                        inheritsList.Add(toInherit);
                    }
                }
                else
                {
                    return($"Missing \"name\" argument in tag \"<inherit>\"!");
                }
            }

            #endregion Inherits

            #region Class
            if (node.Name == "class") // parsing the class name/type/protection level
            {
                if (node.Attributes["protectionLevel"] != null && node.Attributes["type"] != null && node.Attributes["name"] != null)
                {
                    return(new ClassParser(node.Attributes["protectionLevel"].Value, node.Attributes["type"].Value,
                                           node.Attributes["name"].Value).Parse());
                }
                else if (node.Attributes["protectionLevel"] != null && node.Attributes["name"] != null)
                {
                    return(new ClassParser(node.Attributes["protectionLevel"].Value, node.Attributes["name"].Value).Parse());
                }
                else if (node.Attributes["type"] != null && node.Attributes["name"] != null)
                {
                    return(new ClassParser(node.Attributes["type"].Value, 0, node.Attributes["name"].Value).Parse());
                }
                else
                {
                    return(new ClassParser(node.Attributes["name"].Value).Parse());
                }
            }
            #endregion Class

            if (node.Name == "class" && node.Attributes["type"] != null)
            {
                ClassType = node.Attributes["type"].Value;
            }

            #region Item
            if (node.Name == "item" && !this.noPrivateFields) //parsing PRIVATE fields
            {
                privateFieldsCount++;
                if (node.Attributes["type"] != null && node.Attributes["returnType"] != null
                    & node.Attributes["value"] != null && node.InnerText != null)
                {
                    return(new ItemParser(node.Attributes["type"].Value, node.Attributes["returnType"].Value,
                                          node.Attributes["value"].Value, node.InnerText).Parse());
                }
                else if (node.Attributes["type"] == null && node.Attributes["returnType"] != null &&
                         node.Attributes["value"] == null && node.InnerText != null)
                {
                    return(new ItemParser(node.Attributes["returnType"].Value, node.InnerText).Parse());
                }
                else if (node.Attributes["type"] == null && node.Attributes["returnType"] != null &&
                         node.Attributes["value"] != null && node.InnerText != null)
                {
                    return(new ItemParser(node.Attributes["returnType"].Value, node.Attributes["value"].Value, node.InnerText).Parse());
                }
                else if (node.Attributes["type"] != null && node.Attributes["returnType"] != null &&
                         node.Attributes["value"] == null && node.InnerText != null)
                {
                    return(new ItemParser(node.Attributes["type"].Value, node.Attributes["returnType"].Value, node.InnerText, 0).Parse());
                }

                else
                {
                    return($"{error} Invalid or missing XML argument in tag \"{node.Name}\"!");
                }
            }
            #endregion Item

            #region Encapsulation
            if (node.Name == "encapsulate") //encapsulation property
            {
                if (node.InnerText != null)
                {
                    if (node.InnerText.ToLower() == "true" || node.InnerText.ToLower() == "false")
                    {
                        ClassWriter.SetEncapsulation(node.InnerText);
                    }
                    else
                    {
                        Console.WriteLine("WRONG \"ENCAPSULATION\" TAG!");
                    }
                }
            }
            #endregion Encapsulation

            #region PublicItem
            if (node.Name == "publicItem" && !this.noPublicFields)//parsing publicItems property
            {
                publicFieldsCount++;
                if (node.Attributes["type"] != null && node.Attributes["returnType"] != null
                    & node.Attributes["value"] != null && node.InnerText != null)
                {
                    return(new ItemParser(node.Attributes["type"].Value, node.Attributes["returnType"].Value,
                                          node.Attributes["value"].Value, node.InnerText, false).Parse());
                }
                else if (node.Attributes["type"] == null && node.Attributes["returnType"] != null &&
                         node.Attributes["value"] == null && node.InnerText != null)
                {
                    return(new ItemParser(null, node.Attributes["returnType"].Value, null, node.InnerText, false).Parse());
                }
                else if (node.Attributes["type"] == null && node.Attributes["returnType"] != null &&
                         node.Attributes["value"] != null && node.InnerText != null)
                {
                    return(new ItemParser(node.Attributes["returnType"].Value, node.Attributes["value"].Value, node.InnerText, false).Parse());
                }

                else
                {
                    return($"{error} Invalid or missing XML argument in tag \"{node.Name}\"!");
                }
            }
            #endregion PublicItem

            #region Method
            if (node.Name == "method" && !this.noPrivateMethods)
            {
                privateMethodsCount++;
                #region No arguments
                if (node.Attributes["type"] != null && node.Attributes["returnType"] != null && node.Attributes["param"] == null &&
                    node.Attributes["params"] == null && node.InnerText != null)    //HAS NO PARAMETERS
                {
                    return(new MethodParser(node.Attributes["type"].Value, node.Attributes["returnType"].Value, node.InnerText).Parse());
                }
                else if (node.Attributes["type"] == null && node.Attributes["returnType"] != null && node.Attributes["param"] == null &&
                         node.Attributes["params"] == null && node.InnerText != null) //HAS NO PARAMETERS!
                {
                    return(new MethodParser(node.Attributes["returnType"].Value, node.InnerText).Parse());
                }
                #endregion No arguments

                #region Single argument
                else if (node.Attributes["type"] != null && node.Attributes["returnType"] != null && node.Attributes["param"] != null &&
                         node.Attributes["params"] == null && node.InnerText != null) //have ONE parameter and type!
                {
                    return(new MethodParser(node.Attributes["type"].Value, node.Attributes["returnType"].Value, node.InnerText, true,
                                            0, node.Attributes["param"].Value).Parse());
                }
                else if (node.Attributes["type"] == null && node.Attributes["returnType"] != null && node.Attributes["param"] != null &&
                         node.Attributes["params"] == null && node.InnerText != null) //have ONE parameter and NO type!
                {
                    return(new MethodParser(null, node.Attributes["returnType"].Value, node.InnerText, true, 0, node.Attributes["param"].Value).Parse());
                }
                #endregion Single argument

                #region Many Arguments
                else if (node.Attributes["type"] != null && node.Attributes["returnType"] != null && node.Attributes["param"] == null &&
                         node.Attributes["params"] != null && node.InnerText != null) //have MANY parameters and type!
                {
                    return(new MethodParser(node.Attributes["type"].Value, node.Attributes["returnType"].Value, node.InnerText, true,
                                            GetConstructorParameters(node.Attributes["params"].Value)).Parse());
                }
                else if (node.Attributes["type"] == null && node.Attributes["returnType"] != null && node.Attributes["param"] == null &&
                         node.Attributes["params"] != null && node.InnerText != null) //have MANY parameters and NO type!
                {
                    return(new MethodParser(null, node.Attributes["returnType"].Value, node.InnerText, true,
                                            GetConstructorParameters(node.Attributes["params"].Value)).Parse());
                }

                #endregion Many Arguments

                else
                {
                    return($"{error} Invalid or missing XML argument in tag \"{node.Name}\"!");
                }
            }


            #endregion Method

            #region PublicMethod

            if (node.Name == "publicMethod" && !this.noPublicMethods)
            {
                publicMethodsCount++;
                #region No arguments
                if (node.Attributes["type"] != null && node.Attributes["returnType"] != null && node.Attributes["param"] == null &&
                    node.Attributes["params"] == null && node.InnerText != null)
                {
                    return(new MethodParser(node.Attributes["type"].Value, node.Attributes["returnType"].Value, node.InnerText, false, 0, null).Parse());
                }
                else if (node.Attributes["type"] == null && node.Attributes["returnType"] != null && node.Attributes["param"] == null &&
                         node.Attributes["params"] == null && node.InnerText != null)
                {
                    return(new MethodParser(node.Attributes["returnType"].Value, node.InnerText, false).Parse());
                }

                #endregion No arguments

                #region Single argument
                else if (node.Attributes["type"] != null && node.Attributes["returnType"] != null && node.Attributes["param"] != null &&
                         node.Attributes["params"] == null && node.InnerText != null) //have ONE parameter and type!
                {
                    return(new MethodParser(node.Attributes["type"].Value, node.Attributes["returnType"].Value, node.InnerText, false,
                                            0, node.Attributes["param"].Value).Parse());
                }
                else if (node.Attributes["type"] == null && node.Attributes["returnType"] != null && node.Attributes["param"] != null &&
                         node.Attributes["params"] == null && node.InnerText != null) //have ONE parameter and NO type!
                {
                    return(new MethodParser(null, node.Attributes["returnType"].Value, node.InnerText, false, 0, node.Attributes["param"].Value).Parse());
                }
                #endregion Single argument

                #region Many Arguments
                else if (node.Attributes["type"] != null && node.Attributes["returnType"] != null && node.Attributes["param"] == null &&
                         node.Attributes["params"] != null && node.InnerText != null) //have MANY parameters and type!
                {
                    return(new MethodParser(node.Attributes["type"].Value, node.Attributes["returnType"].Value, node.InnerText, false,
                                            GetConstructorParameters(node.Attributes["params"].Value)).Parse());
                }
                else if (node.Attributes["type"] == null && node.Attributes["returnType"] != null && node.Attributes["param"] == null &&
                         node.Attributes["params"] != null && node.InnerText != null) //have MANY parameters and NO type!
                {
                    return(new MethodParser(null, node.Attributes["returnType"].Value, node.InnerText, false,
                                            GetConstructorParameters(node.Attributes["params"].Value)).Parse());
                }

                #endregion Many Arguments

                else
                {
                    return($"{error} Invalid or missing XML argument in tag \"{node.Name}\"!");
                }
            }
            #endregion PublicMethod

            #region Constructor/s

            if (node.Name == "constructor")
            {
                if (node.Attributes != null && node.Attributes["protectionLevel"] != null && node.Attributes["param"] != null)
                {
                    return(new ConstuctorGenerator(node.Attributes["protectionLevel"].Value, node.Attributes["param"].Value).Parse());
                }
                else if (node.Attributes != null && node.Attributes["protectionLevel"] == null && node.Attributes["param"] != null)
                {
                    return(new ConstuctorGenerator(node.Attributes["param"].Value).Parse());
                }
                else if (node.Attributes != null && node.Attributes["protectionLevel"] != null && node.Attributes["params"] != null)
                {
                    return(new ConstuctorGenerator(node.Attributes["protectionLevel"].Value,
                                                   GetConstructorParameters(node.Attributes["params"].Value)).Parse());
                }
                else if (node.Attributes != null && node.Attributes["protectionLevel"] == null && node.Attributes["params"] != null)
                {
                    return(new ConstuctorGenerator(GetConstructorParameters(node.Attributes["params"].Value)).Parse());
                }
            }

            #endregion Constructor/s

            return(string.Empty);
        }