When .NET (i.e. C#) is invoked from IronPython the CodeContext is automatically injected if the called code opts to receive it. Assuming that you have an assembly, class, and method looking as follows:
namespace ClassLibrary1
{
public class Class1
{
public static void MyMethod(CodeContext ctx, int number, string text)
{
var msg = string.Format("Warning: {0} and {1} ...", number, text);
PythonWarnings.warn(ctx, msg, null, 0);
}
}
}
Note that MyMethod accepts a CodeContext as its first parameter and can be invoked from IronPython with just the last two parameters provided:
import clr
clr.AddReference("ClassLibrary1")
from ClassLibrary1 import Class1
Class1.MyMethod(1234, "test")