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

.NET property not accessible in derived classes where only the setter or the getter has been overridden #1455

Closed
Labels
Milestone
@spynetcamera

Description

@spynetcamera

Environment

  • Pythonnet version: 2.5.2
  • Python version: 3.7
  • Operating System: Windows 10
  • .NET Runtime: 4.8

Details

  • Let's create a simple base class that exposes a property, then create a derived class that overrides the setter, but not the getter (that is supposed to be as it was defined in the base class)
namespacePythonNetTest{publicclassBaseClass{protectedstringname="noname";publicvirtualstringName{get=>name;set=>name=value;}}publicclassDerivedClass:BaseClass{publicoverridestringName{set=>base.Name=value.ToUpper();}}}
  • Let's now use the above classes in Python
importclrclr.AddReference("PythonNetTest")fromPythonNetTestimportBaseClass,DerivedClassd=DerivedClass()b=BaseClass()b.Name='BaseClass Name'd.Name='DerivedClass Name'print(b.Name)# okprint(d.Name)# TypeError: property cannot be read
  • Here theprint(d.Name) will rise the exceptionTypeError: property cannot be read.
  • As a workaround it is possible to useprint(d.GetType().BaseType.GetProperty('Name').GetValue(d)) instead, but it is not one would expect.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp