Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Generic class nested within a class cannot be instantiated #1906

Open
Labels
@hasslerb

Description

@hasslerb

Environment

  • Pythonnet version: 2.5.2
  • Python version: 3.7.9
  • Operating System: Windows 11
  • .NET Runtime: 4.8.04161

Details

When I try to instantiate a C#-defined generic class in python, I see an error if the generic class is nested within another class.

Consider 3 types of classes

namespace Bar{    public class GenericClass<T>    {        public T Dummy;    }    public static class FooStatic    {        public class GenericClassNestedStatic<T>        {            public T Dummy;        }    }    public class Foo    {        public class GenericClassNested<T>        {            public T Dummy;        }    }}

If I run this in python, it executes without issues

from System import UInt32a = getattr(Bar, "GenericClass`1")b = a[UInt32]()

However, when I try

foo = Bar.Foo()c = getattr(foo, "GenericClassNested`1")d = c[UInt32]()

or

c = getattr(Bar.FooStatic, "GenericClassNestedStatic`1")d = c[UInt32]()

they both result in

d = c[UInt32]()TypeError: no type matches params

Is this capability simply not supported, or am I approaching this incorrectly?

Additionally, if I rename my classes the same with a differently scoped context,

namespace Bar{    public class GenericClass<T>    {        public T Dummy;    }    public class Foo    {        public class GenericClass<T>        {            public T Dummy;        }    }}

when I execute

foo = Bar.Foo()c = getattr(foo, "GenericClass`1")d = c[UInt32]()

this succeeds, but it seems to create an instance ofBar.GenericClass rather thanBar.Foo.GenericClass

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp