Skip to content

Code Quality: Improved DependencyProperty generator #16025

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 27, 2024

Conversation

0x5bfa
Copy link
Member

@0x5bfa 0x5bfa commented Aug 17, 2024

Resolved / Related Issues

The primary achievement is to reduce lines of code and verbosity when declaring DependencyProperties.

Steps used to test these changes

None

@0x5bfa 0x5bfa force-pushed the 5bfa/CQ-DepPropAttrib branch from acd9112 to 09d923c Compare August 18, 2024 08:51
@0x5bfa

This comment was marked as resolved.

@Poker-sang
Copy link
Contributor

Poker-sang commented Aug 18, 2024

Thanks for your help. 🤔 Since we've made it to the eve of the partial properties, maybe we can wait for C#13 to come out before making adjustments? That way we can implement it in this syntax:

[DependencyProperty(PropertyChangedCallback, etc.)]
public partial object? MyProperty { get; private set; } = new Object();

This way is much easier and more readable. And perhaps CommunityToolkit would like to implement a better version?

@0x5bfa

This comment was marked as resolved.

@0x5bfa

This comment was marked as outdated.

@Poker-sang
Copy link
Contributor

Poker-sang commented Aug 18, 2024

@Poker-sang fyi. btw do you know how to emit ExpressionSyntax from TypedConstant that can be obtained from attribute properties list? This abb4661 does its job but looks quite bad.

If you wish to do so, then yes. You can get it through

((TypeDeclarationSyntax)generatorAttributeSyntaxContext.TargetNode).AttributeLists[0].Attributes[0].ArgumentList.Arguments[0].Expression

or

((AttributeSyntax)attributeData.ApplicationSyntaxReference).ArgumentList.Arguments[0].Expression

However the arguments of the attributes only allow constants, which I don't think is very useful, so I used string

@0x5bfa

This comment was marked as resolved.

@Poker-sang
Copy link
Contributor

Poker-sang commented Aug 20, 2024

I think I'd like to use the latter one but there seems to be a cast error.

Oh sorry, I didn't test it. It should be .GetSyntax() or .GetSyntaxAsync():

((AttributeSyntax)attributeData.ApplicationSyntaxReference.GetSyntax()).ArgumentList.Arguments[0].Expression

@0x5bfa
Copy link
Member Author

0x5bfa commented Aug 21, 2024

Worked thanks!!
Could you review?

@0x5bfa 0x5bfa force-pushed the 5bfa/CQ-DepPropAttrib branch from d0445e4 to f2e8349 Compare August 21, 2024 15:10
Copy link
Contributor

@Poker-sang Poker-sang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

yaira2
yaira2 previously approved these changes Aug 21, 2024
@0x5bfa
Copy link
Member Author

0x5bfa commented Aug 23, 2024

That didn't work; somehow emitted property type string like "IconType" and caused an invalid cast exception.

Reverted to your original approach, I think we can wait for .NET partial properties to achieve this as you suggested.

Again, ready.

Copy link
Contributor

@XTorLukas XTorLukas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@yaira2 yaira2 added ready to merge Pull requests that are approved and ready to merge and removed needs - code review labels Aug 27, 2024
@yaira2
Copy link
Member

yaira2 commented Aug 27, 2024

@0x5bfa are you ready for me to merge this?

@0x5bfa
Copy link
Member Author

0x5bfa commented Aug 27, 2024

YES!!

@yaira2 yaira2 merged commit 4229553 into files-community:main Aug 27, 2024
6 checks passed
0x5bfa added a commit to 0x5bfa/Files that referenced this pull request Aug 28, 2024
@0x5bfa 0x5bfa deleted the 5bfa/CQ-DepPropAttrib branch August 28, 2024 15:34
@hishitetsu
Copy link
Member

This PR disables changing the sort order by clicking on the header of the details layout.
image

@0x5bfa
Copy link
Member Author

0x5bfa commented Aug 30, 2024

Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready to merge Pull requests that are approved and ready to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants