Skip to content

Conversation

benrr101
Copy link
Contributor

@benrr101 benrr101 commented Apr 8, 2025

Description: This change is a bit heavier than it should be because of reasons...

  • Move SqlClientPermission from netfx project to common project
  • Separate SqlClientPermissionAttribute from the SqlClientPermission file into its own file in the common project
  • Move NameValuePermission into SqlClientPermission class, as a subclass
    • This class is only used for SqlClientPermission, and I really didn't like it hanging out in the middle by itself.
  • Applied some reorg/cleanup of SqlClientPermission
    • I would have gone further with this, but because this class overrides most of the base implementation (System.Data.Common.DBDataPermission), it's a bit more difficult to untangle.
  • Removed XML encode and decode methods
    • This is available via built-in methods, so it is not ideal to write our own.

Testing: For the most past, there are no functional changes. Code is moved around. CI should validate.

@benrr101 benrr101 added the Common Project 🚮 Things that relate to the common project project label Apr 8, 2025
@benrr101 benrr101 requested review from a team and Copilot April 8, 2025 18:51
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 4 out of 5 changed files in this pull request and generated no comments.

Files not reviewed (1)
  • src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj: Language not supported

Copy link

codecov bot commented Apr 10, 2025

Codecov Report

Attention: Patch coverage is 35.24904% with 169 lines in your changes missing coverage. Please review.

Project coverage is 73.03%. Comparing base (c5e3c40) to head (beb9014).
Report is 25 commits behind head on main.

Files with missing lines Patch % Lines
...rosoft/Data/SqlClient/SqlClientPermission.netfx.cs 35.65% 166 Missing ⚠️
...ta/SqlClient/SqlClientPermissionAttribute.netfx.cs 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3262      +/-   ##
==========================================
+ Coverage   72.98%   73.03%   +0.04%     
==========================================
  Files         299      299              
  Lines       57215    57194      -21     
==========================================
+ Hits        41760    41770      +10     
+ Misses      15455    15424      -31     
Flag Coverage Δ
addons 92.58% <ø> (ø)
netcore 75.27% <ø> (+0.08%) ⬆️
netfx 71.43% <35.24%> (-0.06%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@benrr101 benrr101 added this to the 6.1-preview2 milestone Apr 29, 2025
@cheenamalhotra cheenamalhotra requested review from cheenamalhotra and a team May 1, 2025 16:22
Comment on lines +25 to +28
public override IPermission CreatePermission()
{
return new SqlClientPermission(this);
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public override IPermission CreatePermission()
{
return new SqlClientPermission(this);
}
public override IPermission CreatePermission() => new SqlClientPermission(this);


private bool _IsUnrestricted
{
get
Copy link
Member

Choose a reason for hiding this comment

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

get => base.IsUnrestricted();

Copy link
Contributor

Choose a reason for hiding this comment

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

Personally, I like function bodies enclosed in braces. And in this case, it matches the format of the sibling setter. The => notation increases code density, which isn't necessarily a good thing. Personal preference I guess.

Comment on lines +114 to +117
public override IPermission Copy()
{
return new SqlClientPermission(this);
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public override IPermission Copy()
{
return new SqlClientPermission(this);
}
public override IPermission Copy() => new SqlClientPermission(this);

Comment on lines +588 to +591
internal NameValuePermission CopyNameValue()
{
return new NameValuePermission(this);
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
internal NameValuePermission CopyNameValue()
{
return new NameValuePermission(this);
}
internal NameValuePermission CopyNameValue() => new NameValuePermission(this);


private bool _IsUnrestricted
{
get
Copy link
Contributor

Choose a reason for hiding this comment

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

Personally, I like function bodies enclosed in braces. And in this case, it matches the format of the sibling setter. The => notation increases code density, which isn't necessarily a good thing. Personal preference I guess.

}

string unrestrictedValue = securityElement.Attribute(XmlStr._Unrestricted);
_IsUnrestricted = unrestrictedValue != null && bool.Parse(unrestrictedValue);
Copy link
Contributor

Choose a reason for hiding this comment

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

Just FYI, but this seemingly benign assignment can (surprisingly) throw reflection exceptions, which we don't document. In fact, the docs don't claim this function will throw anything!

@benrr101 benrr101 merged commit 516b402 into main May 6, 2025
251 checks passed
@benrr101 benrr101 deleted the dev/russellben/merge/sqlclientpermission branch May 6, 2025 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Common Project 🚮 Things that relate to the common project project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants