Classes without __namespace__ cannot be used for reflection
See original GitHub issueEnvironment
- Pythonnet version: 3.0.0-preview2022-04-11
- Python version: 3.10
- Operating System: MacOS
- .NET Runtime: .net 6
Details
My software does lots of reflection on “plugin” types. Simply inheriting from a specific type is enough in C#, but when I use python.net I also have to define __namespace__
. Since my users generally have the namespace being <Module>.<Class>, there is no logic reason for them to have to do this.
I can see which part of the code causes this:
// from MetaType.cs:133 (git: 7247da55c174be1b733e5f9fc4e1c356f6c42dc4)
if (clsDict.HasKey("__assembly__") || clsDict.HasKey("__namespace__"))
{
return TypeManager.CreateSubType(name, base_type, clsDict);
}
I am wonder if we could broaden the cases where TypeManager.CreateSubType is used. For example in cases where the super class is a type created with CreateSubType, or just any .NET class in general. Maybe it could also be if the super class implements a specific interface.
_TODO_
Add a way to not have to specify namespace in the class in order for reflection to work.
Issue Analytics
- State:
- Created a year ago
- Comments:11 (10 by maintainers)
Top Results From Across the Web
C# - Is there a way to load classes from a namespace ...
So I tried to use reflection with the code below: ... the bottom line is you can't get around listing all your commands...
Read more >System.Reflection Namespace
Represents a missing Object. This class cannot be inherited. Performs reflection on a module. Represents nullability information.
Read more >c# - Get nested type name without namespace
As you've noticed that returns Baz when you want Foo.Bar.Baz . Either you use reflection to get the three types and concatenate their...
Read more >Get Full Name of Namespace, Can't Use nameof : r/csharp
I am doing reflection on an assembly & am trying to appropriately get the name of a namespace. If I use: string namespace...
Read more >Manual: Namespaces
A namespace is simply a collection of classes that are referred to using a ... Unity gives the following warning in the console:...
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
Hi @filmor, sure, but I have a bunch of features on that fork, some more or less experimental. In total, it is not that many changes. I’ll clean it up a bit and setup a PR.
@lostmsu I lined out how we could do it anyhow, via a runtime/startup feature flag mechanism. No magic required.