Class instance a derived Python class or pure C#?
See original GitHub issueHey everybody, I am trying to see if there is a way to determine if my instance of a class is a pure C# class or a derived from C# Python class.
Here is an example:
Lets say I have a C# class public class Parent
,
-> in Python I create a subclass of it class PyClass(Parent)
,
-> in C# I create a subclass of it public class CSharpClass : Parent
In both of these cases when I create the new objects it will use the Parent class constructor, but in that constructor I would like the behaviour to change if the instance is from a derived python class.
Is there a way to verify in the Parent class constructor that its being used in a derived Python class?
Thank you!
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Cast base class to derived class python (or more ...
This is as close to a "cast" as you can get in Python, and like casting in C, it is not to be...
Read more >9. Classes — Python 3.11.4 documentation
Python classes provide all the standard features of Object Oriented Programming: the class inheritance mechanism allows multiple base classes, a derived class ......
Read more >Python issubclass()
It is the capability of one class to derive or inherit the properties from some other class. It also provides the reusability of...
Read more >Python Classes: The Power of Object-Oriented Programming
In this tutorial, you'll learn how to create and use full-featured classes in your Python code. Classes provide a great way to solve...
Read more >Subclassing and Inheritance — Programming in Python 7.0 ...
Classes can inherit attributes and behavior from pre-existing classes called base classes or super classes. The resulting classes are known as derived ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@C-SELLERS I was debugging some unrelated issue today, and came across
ClassDerivedObject
, that handles certain Python classes derived from C#.First, is there a reason you don’t want to define your class as a CLR-like class? To do that you’d need to set
__namespace__
like this:I believe in this case the derived class will implement dummy
IPythonDerivedType
.Just a heads up, if anybody tries using the above, instances will also contain a copy of the object your originally passed in. I realize this probably isn’t desired so I added one extra step that will go get the type first, then dispose of our converted Python obj.