-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ILLink annotations to S.D.Common related to DbConnectionStringBui…
…lder (#54280) * Add ILLink annotations to S.D.Common related to DbConnectionStringBuilder * address some feedback * Make GetEvents() safe * make GetProperties safe * Mark GetProperties with RUC
- Loading branch information
Showing
5 changed files
with
191 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
159 changes: 159 additions & 0 deletions
159
src/libraries/System.Data.Common/tests/TrimmingTests/DbConnectionStringBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Data.Common; | ||
using System.ComponentModel; | ||
using System.Collections; | ||
|
||
namespace DbConnectionStringBuilderTrimmingTests | ||
{ | ||
class Program | ||
{ | ||
static int Main(string[] args) | ||
{ | ||
DbConnectionStringBuilder2 dcsb2 = new(); | ||
ICustomTypeDescriptor td = dcsb2; | ||
|
||
if (td.GetClassName() != "DbConnectionStringBuilderTrimmingTests.DbConnectionStringBuilder2") | ||
{ | ||
throw new Exception("Class name got trimmed"); | ||
} | ||
|
||
if (td.GetComponentName() != "Test Component Name") | ||
{ | ||
throw new Exception("Component name got trimmed"); | ||
} | ||
|
||
bool foundAttr = false; | ||
|
||
foreach (Attribute attr in td.GetAttributes()) | ||
{ | ||
if (attr.GetType().Name == "TestAttribute") | ||
{ | ||
if (attr.ToString() != "Test Attribute Value") | ||
{ | ||
throw new Exception("Test attribute value differs"); | ||
} | ||
|
||
if (foundAttr) | ||
{ | ||
throw new Exception("More than one attribute found"); | ||
} | ||
|
||
foundAttr = true; | ||
} | ||
} | ||
|
||
if (!foundAttr) | ||
{ | ||
throw new Exception("Attribute not found"); | ||
} | ||
|
||
bool foundEvent = false; | ||
bool foundEventWithDisplayName = false; | ||
|
||
foreach (EventDescriptor ev in td.GetEvents()) | ||
{ | ||
if (ev.DisplayName == "TestEvent") | ||
{ | ||
if (foundEvent) | ||
{ | ||
throw new Exception("More than one event TestEvent found."); | ||
} | ||
|
||
foundEvent = true; | ||
} | ||
|
||
if (ev.DisplayName == "Event With DisplayName") | ||
{ | ||
if (foundEventWithDisplayName) | ||
{ | ||
throw new Exception("More than one event with display name found."); | ||
} | ||
|
||
foundEventWithDisplayName = true; | ||
} | ||
} | ||
|
||
if (!foundEvent) | ||
{ | ||
throw new Exception("Event not found"); | ||
} | ||
|
||
if (!foundEventWithDisplayName) | ||
{ | ||
throw new Exception("Event with DisplayName not found"); | ||
} | ||
|
||
bool propertyFound = false; | ||
foreach (DictionaryEntry kv in dcsb2.GetProperties2()) | ||
{ | ||
PropertyDescriptor val = (PropertyDescriptor)kv.Value; | ||
if (val.Name == "TestProperty") | ||
{ | ||
if (propertyFound) | ||
{ | ||
throw new Exception("More than one property TestProperty found."); | ||
} | ||
|
||
propertyFound = true; | ||
} | ||
} | ||
|
||
if (!propertyFound) | ||
{ | ||
throw new Exception("Property not found"); | ||
} | ||
|
||
return 100; | ||
} | ||
} | ||
|
||
[Test("Test Attribute Value")] | ||
class DbConnectionStringBuilder2 : DbConnectionStringBuilder, IComponent | ||
{ | ||
#pragma warning disable CS0067 // The event is never used | ||
public event EventHandler Disposed; | ||
public event Action TestEvent; | ||
[DisplayName("Event With DisplayName")] | ||
public event Action TestEvent2; | ||
#pragma warning restore CS0067 | ||
|
||
public string TestProperty { get; set; } | ||
public ISite Site { get => new TestSite(); set => throw new NotImplementedException(); } | ||
public void Dispose() { } | ||
|
||
public Hashtable GetProperties2() | ||
{ | ||
Hashtable propertyDescriptors = new Hashtable(); | ||
GetProperties(propertyDescriptors); | ||
return propertyDescriptors; | ||
} | ||
} | ||
|
||
class TestSite : INestedSite | ||
{ | ||
public string FullName => null; | ||
public IComponent Component => throw new NotImplementedException(); | ||
public IContainer Container => throw new NotImplementedException(); | ||
public bool DesignMode => throw new NotImplementedException(); | ||
public string Name { get => "Test Component Name"; set => throw new NotImplementedException(); } | ||
public object GetService(Type serviceType) => null; | ||
} | ||
|
||
class TestAttribute : Attribute | ||
{ | ||
public string Test { get; private set; } | ||
|
||
public TestAttribute(string test) | ||
{ | ||
Test = test; | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return Test; | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/libraries/System.Data.Common/tests/TrimmingTests/System.Data.Common.TrimmingTests.proj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
<Project DefaultTargets="Build"> | ||
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.props))" /> | ||
|
||
<ItemGroup> | ||
<TestConsoleAppSourceFiles Include="CreateSqlXmlReader.cs" /> | ||
<TestConsoleAppSourceFiles Include="DbConnectionStringBuilder.cs" /> | ||
</ItemGroup> | ||
|
||
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.targets))" /> | ||
</Project> |