module sphinxext.sphinx_runcsharp_extension

Inheritance diagram of csharpy.sphinxext.sphinx_runcsharp_extension

Short summary

module csharpy.sphinxext.sphinx_runcsharp_extension

Extends Sphinx to easily write documentation.

source on GitHub

Classes

class

truncated documentation

RunCSharpDirective

Runs a C# script based on runpython. The directive adds a couple of options:

Functions

function

truncated documentation

_make_options

setup

Adds the directive RunCSharpDirective.

Methods

method

truncated documentation

_modify_script_before_running

modify_script_before_running

The methods modifies the script to csharpy to run C# from Python.

Documentation

Extends Sphinx to easily write documentation.

source on GitHub

class csharpy.sphinxext.sphinx_runcsharp_extension.RunCSharpDirective(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine)[source]

Bases: pyquickhelper.sphinxext.sphinx_runpython_extension.RunPythonDirective

Runs a C# script based on runpython. The directive adds a couple of options:

  • 'dependency': list of necessary dependencies, list comma separated

  • 'entrypoint': function to call first to start the program, it can be empty, it must be a function without any argument.

  • 'using': list of necessary usings, list comma separated

A few examples, the first one shows how to call one function inside others.

.. runcsharp::
    :showcode:
    :entrypoint: main

    public static class Zoo
    {
        public static double Square(double x)
        {
            return x*x;
        }
    }

    public static void main()
    {
        Console.WriteLine("{0}", Zoo.Square(3));
    }

Which renders as:

<<<

public static class Zoo
{
    public static double Square(double x)
    {
        return x * x
    }
}

public static void main()
{
    Console.WriteLine("{0}", Zoo.Square(3))
}

>>>

    9

The next one does not have any function (and cannot have) but requires some dependencies.

.. runcsharp::
    :showcode:
    :language: csharp
    :using: System.Linq, System.Text, System.Collections.Generic

    var li = new [] {"a", "b"};
    var mes = string.Join(",", li.Select(c => c.ToUpper()));
    Console.WriteLine("{0}", mes);

Which renders as:

<<<

var li = new[] {"a", "b"}
var mes = string.Join(",", li.Select(c= > c.ToUpper()))
Console.WriteLine("{0}", mes)

>>>

    A,B

source on GitHub

_modify_script_before_running(script, usings, dependencies)[source]
modify_script_before_running(script)[source]

The methods modifies the script to csharpy to run C# from Python.

source on GitHub

csharpy.sphinxext.sphinx_runcsharp_extension._make_options()[source]
csharpy.sphinxext.sphinx_runcsharp_extension.setup(app)[source]

Adds the directive RunCSharpDirective.

source on GitHub