コード例 #1
0
        public static string GetMethodBody(Compilation compilation, SyntaxNode methodBody)
        {
            ShaderSyntaxRewriter syntaxRewriter = new ShaderSyntaxRewriter(compilation);
            SyntaxNode           newBody        = syntaxRewriter.Visit(methodBody);

            string shaderSource = newBody.ToFullString();

            return(FormatShaderString(shaderSource));
        }
コード例 #2
0
        public static string GetMethodBody(MethodInfo methodInfo)
        {
            Compilation             compilation = GetCompilation(methodInfo.DeclaringType);
            MethodDeclarationSyntax methodNode  = GetMethodDeclaration(methodInfo, compilation.SyntaxTrees.Single());

            ShaderSyntaxRewriter syntaxRewriter = new ShaderSyntaxRewriter(compilation);
            SyntaxNode           newBody        = syntaxRewriter.Visit(methodNode.Body);

            string shaderSource = newBody.ToFullString();

            // TODO: See why the System namespace in System.Math is not present in UWP projects.
            shaderSource = shaderSource.Replace("Math.Max", "max");
            shaderSource = shaderSource.Replace("Math.Pow", "pow");
            shaderSource = shaderSource.Replace("Math.Sin", "sin");

            shaderSource = shaderSource.Replace("vector", "vec");
            shaderSource = Regex.Replace(shaderSource, @"\d+[fF]", m => m.Value.Replace("f", ""));

            return(shaderSource.Replace(Environment.NewLine + "    ", Environment.NewLine).Trim());
        }