Exemple #1
0
        public static string ConvertToMof(MethodDeclarationAst node, MofQuirks quirks = MofQuirks.None)
        {
            var source = new StringBuilder();

            if ((node.Qualifiers != null) && node.Qualifiers.Qualifiers.Count > 0)
            {
                source.AppendFormat("{0}", MofGenerator.ConvertToMof(node.Qualifiers, quirks));
            }
            var quirkEnabled = (quirks & MofQuirks.PrefixSpaceBeforeQualifierlessMethodDeclarations) == MofQuirks.PrefixSpaceBeforeQualifierlessMethodDeclarations;

            if (quirkEnabled || ((node.Qualifiers != null) && node.Qualifiers.Qualifiers.Count > 0))
            {
                source.AppendFormat(" ");
            }
            source.AppendFormat("{0} {1}", node.ReturnType.Name, node.Name.Name);
            if (node.Parameters.Count == 0)
            {
                source.Append("();");
            }
            else
            {
                var values = node.Parameters.Select(p => MofGenerator.ConvertToMof(p, quirks)).ToArray();
                source.AppendFormat("({0});", string.Join(", ", values));
            }
            return(source.ToString());
        }
        public static string ConvertMethodDeclarationAst(MethodDeclarationAst node, MofQuirks quirks = MofQuirks.None)
        {
            var prefixQuirkEnabled = (quirks & MofQuirks.PrefixSpaceBeforeQualifierlessMethodDeclarations) == MofQuirks.PrefixSpaceBeforeQualifierlessMethodDeclarations;

            var source = new StringBuilder();

            if (node.QualifierList.QualifierValues.Any())
            {
                source.Append(AstMofGenerator.ConvertQualifierListAst(node.QualifierList, quirks));
            }

            if (prefixQuirkEnabled || node.QualifierList.QualifierValues.Any())
            {
                source.Append(" ");
            }

            source.Append(node.ReturnType.Name);
            if (node.ReturnTypeIsArray)
            {
                source.Append("[]");
            }

            source.Append(" ");
            source.Append(node.Name.Name);

            if (node.Parameters.Count == 0)
            {
                source.Append("();");
            }
            else
            {
                var values = node.Parameters.Select(p => AstMofGenerator.ConvertParameterDeclarationAst(p, quirks)).ToArray();
                source.Append("(");
                source.Append(string.Join(", ", values));
                source.Append(");");
            }

            return(source.ToString());
        }