Here is a simplified example of what I'm trying to do:
class Unit
{
public int HP { get; set; }
public int Attack { get; set; }
public Unit(int HP, int Attack)
{
this.HP = HP;
this.Attack = Attack;
}
public void PointlessFunction() { }
public override string ToString()
{
return "HP: " + HP.ToString() + " Attack: " + Attack.ToString();
}
}
class Program
{
static void Main(string[] args)
{
ScriptEngine Engine = Python.CreateEngine();
ScriptScope Scope = Engine.CreateScope();
Scope.SetVariable("Unit", DynamicHelpers.GetPythonTypeFromType(typeof(Unit)));
// declare instance of Unit
Engine.Execute("u = Unit(10,5)", Scope);
// display Unit instance
Engine.Execute("print u", Scope);
//HP: 10 Attack: 5
// Try to change something
Engine.Execute("u.HP = 20", Scope);
//Unhandled Exception: System.MissingMemberException: 'Unit' object has no attribute 'HP'
// Try to run a function
Engine.Execute("u.PointlessFunction()", Scope);
//Unhandled Exception: System.MissingMemberException: 'Unit' object has no attribute 'PointlessFunction'
}
}