public static IntPtr ToPython(object value) { if (value == null) { return(Py_None); } PythonObject result = PythonObject.From(value); if (result != null) { return(result); } if (ClrToPython.ContainsKey(value)) { return((PythonObject)ClrToPython[value]); } Type type = value.GetType(); PythonClass pythonType = TypeManager.ToPython(type); result = pythonType.CreateEmpty(); Register(value, result); return(result); }
private void criatabela1_Click(object sender, EventArgs e) { if (Directory.Exists(pathName.Text)) { Parametros parametros = new Parametros { appname = appName.Text.ToString(), tabela = tableName.Text.ToString(), caminho = pathName.Text.ToString() }; List <Campos> campos = new List <Campos> { }; foreach (DataGridViewRow linha in fields.Rows) { if (linha.Cells["nome"].Value != null && linha.Cells["tipo"].Value != null && linha.Cells["format"].Value != null) { campos.Add(new Campos { nome = linha.Cells["nome"].Value.ToString(), tipo = linha.Cells["tipo"].Value.ToString(), format = linha.Cells["format"].Value.ToString() }); } } PythonClass.Executa(parametros, campos); } else { MessageBox.Show("Caminho inválido"); } }
public void Type() { string pythonModuleCode = @"class TestType: def get_OldProperty(self): return 0 def set_OldProperty(self, value): pass @property def NewProperty(self): return 'test' @NewProperty.setter def NewProperty(self, value): pass"; PythonModule pythonModule = Build(pythonModuleCode); PythonClass pythonClass = pythonModule.Dictionary.Values.OfType <PythonClass>().First(); Type clrType = TypeManager.FromPython(pythonClass); PropertyInfo oldPropertyInfo = clrType.GetProperty("OldProperty"); //Assert.IsNotNull(oldPropertyInfo); PropertyInfo newPropertyInfo = clrType.GetProperty("NewProperty"); Assert.IsNotNull(newPropertyInfo); Assert.AreEqual(newPropertyInfo.PropertyType, typeof(object)); }
public static void Initialize(string name) { Py_NoSiteFlag = true; Py_Initialize(); PythonModule = new PythonModule(name); PythonModule.AddFunction(nameof(AddReference), a => AddReference(null, a)); PythonModule.AddFunction(nameof(Break), a => Break(null, null)); PythonModule.SetAttribute(nameof(System), new ClrNamespace(nameof(System))); ClrClass = new PythonClass("clr"); ClrClass.AddMethod(nameof(__getattr__), __getattr__); ClrClass.AddMethod(nameof(__str__), __str__); ClrClass.AddMethod(nameof(AddReference), AddReference); ClrClass.AddMethod(nameof(Break), Break); //ClrClass.AddMethod("Method", Method); //ClrClass.AddProperty("Property", GetProperty, SetProperty); ClrObject = ClrClass.Create(); PythonModule.SetAttribute("clr", ClrObject); }
public IEnumerable <CompletionData> SelfDotCompletionData(PythonClass klass) { foreach (var attr in klass.Attributes) { yield return(new CompletionData(attr.Name, s_ImgAttr, attr.Documentation)); } foreach (var func in klass.Functions) { yield return(new CompletionData(func.Name, s_ImgFunc, func.Documentation)); } }
public override void BuildNode(ITreeBuilder treeBuilder, object dataObject, ref string label, ref Gdk.Pixbuf icon, ref Gdk.Pixbuf closedIcon) { PythonClass pyClass = dataObject as PythonClass; label = pyClass.Name; icon = Context.GetIcon(MonoDevelop.Ide.Gui.Stock.Class); }
public override bool Walk(ClassDefinition node) { var klass = new PythonClass() { Name = node.Name, Region = GetDomRegion(node), Documentation = node.Documentation }; containers.Peek().Classes.Add(klass); containers.Push(klass); return(base.Walk(node)); }
public override void BuildChildNodes(ITreeBuilder treeBuilder, object dataObject) { PythonClass pyClass = dataObject as PythonClass; if (pyClass == null) { return; } foreach (PythonAttribute pyAttr in pyClass.Attributes) { treeBuilder.AddChild(pyAttr); } foreach (PythonFunction pyFunc in pyClass.Functions) { treeBuilder.AddChild(pyFunc); } }
static ClrNamespace() { Type = new PythonClass("namespace"); Type.AddMethod("__getattr__", __getattr__); Type.AddMethod("__str__", __str__); }
public override string GetNodeName(ITreeNavigator thisNode, object dataObject) { PythonClass pyClass = dataObject as PythonClass; return(pyClass.Name); }
static ClrExtensionMethod() { Type = new PythonClass("extension"); Type.AddMethod("__call__", __call__); }
public PythonMember(PythonClass parent) { this.parent = parent; }