Title: Add Support for Adding .NET Attributes when Creating .NET Classes · Issue #1768 · pythonnet/pythonnet · GitHub
Open Graph Title: Add Support for Adding .NET Attributes when Creating .NET Classes · Issue #1768 · pythonnet/pythonnet
X Title: Add Support for Adding .NET Attributes when Creating .NET Classes · Issue #1768 · pythonnet/pythonnet
Description: Environment Pythonnet version: 3.x Python version: 3.x Operating System: Any .NET Runtime: .Net Framework 4 / .Net6 Details I want to be able to specify attributes on my class defined in python. This is essential for my specific use case...
Open Graph Description: Environment Pythonnet version: 3.x Python version: 3.x Operating System: Any .NET Runtime: .Net Framework 4 / .Net6 Details I want to be able to specify attributes on my class defined in python. Th...
X Description: Environment Pythonnet version: 3.x Python version: 3.x Operating System: Any .NET Runtime: .Net Framework 4 / .Net6 Details I want to be able to specify attributes on my class defined in python. Th...
Opengraph URL: https://github.com/pythonnet/pythonnet/issues/1768
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Add Support for Adding .NET Attributes when Creating .NET Classes ","articleBody":"### Environment\r\n\r\n- Pythonnet version: 3.x\r\n- Python version: 3.x\r\n- Operating System: Any\r\n- .NET Runtime: .Net Framework 4 / .Net6\r\n\r\n### Details\r\n\r\nI want to be able to specify attributes on my class defined in python. This is essential for my specific use case, but I imagine generally useful. I can come up with 3 different situations where it could be useful to add attributes:\r\n\r\n1. Attributes on types - This can be done with an annotation\r\n2. Attributes on methods - This can be done with an annotation\r\n3. Attributes on properties - It seems clr.clrproperty needs to be modified to support it.\r\n\r\n```python\r\n### from test_clrmethod.py\r\n\r\n# Attaching attributes to types (1)\r\n@clr.attribute(DebuggerDisplayAttribute, \"ExampleClrClass: X={X}\")\r\nclass ExampleClrClass(System.Object):\r\n __namespace__ = \"PyTest\"\r\n def __init__(self):\r\n self._x = 3\r\n\r\n # Attaching attributes to methods (2)\r\n @clr.clrmethod(int, [int])\r\n @clr.attribute(DescriptionAttribute, \"Test method\")\r\n def test(self, x):\r\n return x*2\r\n\r\n def get_X(self):\r\n return self._x\r\n def set_X(self, value):\r\n self._x = value\r\n\r\n # Attaching attributes to properties (3)\r\n X = clr.clrproperty(int, get_X, set_X)\\\r\n .attribute(DescriptionAttribute, \"Gets or sets X\")\\\r\n .attribute(BrowsableAttribute, True)\r\n\r\n # Also attaching attributes to properties (3)\r\n @clr.clrproperty(int)\r\n @clr.attribute(DescriptionAttribute, \"Gets Y\")\r\n def Y(self):\r\n return self._x * 2\r\n```\r\n\r\nRegarding using ```clr.attribte(DebuggerDisplayAttribute, \"...\")``` vs ```clr.attribute(DebuggerDisplay(\"...\"))```, it is exceedingly hard to infer how an attribute is constructed form the attribute value itself. Instead the list of constructors can be iterated and matched with a list of arguments and this way the best matching constructor can be found.\r\n\r\n\r\nI can probably implement this myself, but before making a PR I want to know if it will be accepted or it is a bad idea.","author":{"url":"https://github.com/rmadsen-ks","@type":"Person","name":"rmadsen-ks"},"datePublished":"2022-04-13T09:23:40.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":8},"url":"https://github.com/1768/pythonnet/issues/1768"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:126bc872-f502-3043-46e6-5c35caca71cd |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 91CA:30B45A:211508F:2C43D2C:69705DCA |
| html-safe-nonce | 211ebda3c701e88d0d92c14bd5f46bead3676a192fba4cce0524061530694d56 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MUNBOjMwQjQ1QToyMTE1MDhGOjJDNDNEMkM6Njk3MDVEQ0EiLCJ2aXNpdG9yX2lkIjoiNzMzMTIzMjczMDQ3MDk2NDY4MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 76af2b4d38fce3a25727ba607082df42ce4dad3178b103dadf7832983bd2b564 |
| hovercard-subject-tag | issue:1203033536 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/pythonnet/pythonnet/1768/issue_layout |
| twitter:image | https://opengraph.githubassets.com/70e9f75ca4ad7cf63db24e75c11d74ef831e299a0d1712466f2714eed44f00f8/pythonnet/pythonnet/issues/1768 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/70e9f75ca4ad7cf63db24e75c11d74ef831e299a0d1712466f2714eed44f00f8/pythonnet/pythonnet/issues/1768 |
| og:image:alt | Environment Pythonnet version: 3.x Python version: 3.x Operating System: Any .NET Runtime: .Net Framework 4 / .Net6 Details I want to be able to specify attributes on my class defined in python. Th... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | rmadsen-ks |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9920a62ba22d06470388e2904804fb7e5ec51c9e35f81784e9191394c74b2bd2 |
| turbo-cache-control | no-preview |
| go-import | github.com/pythonnet/pythonnet git https://github.com/pythonnet/pythonnet.git |
| octolytics-dimension-user_id | 6050430 |
| octolytics-dimension-user_login | pythonnet |
| octolytics-dimension-repository_id | 14748123 |
| octolytics-dimension-repository_nwo | pythonnet/pythonnet |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 14748123 |
| octolytics-dimension-repository_network_root_nwo | pythonnet/pythonnet |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7d6181066430cc06553c8396ca201e194ae33cb9 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width