Skip to content
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

Allow fully qualified types to be provided in config files #109

Merged
merged 3 commits into from
Jul 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ Changelog

## Unreleased

* Add additional method of specifying ignore classes to allow for providing fully qualified assembly names in config files.
| [martin308](https://github.com/martin308)
| [#109](https://github.com/bugsnag/bugsnag-dotnet/pull/109)

* Include Configuration package with WebApi
| [martin308](https://github.com/martin308)
| [#105](https://github.com/bugsnag/bugsnag-dotnet/pull/105)
Expand Down
65 changes: 59 additions & 6 deletions src/Bugsnag.ConfigurationSection/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public string[] ProjectNamespaces

private const string ignoreClasses = "ignoreClasses";

[ConfigurationProperty("ignoreClasses", IsRequired = false)]
[ConfigurationProperty(ignoreClasses, IsRequired = false)]
private string InternalIgnoreClasses
{
get
Expand All @@ -229,18 +229,71 @@ public Type[] IgnoreClasses
{
get
{
if (_ignoreClasses == null && InternalIgnoreClasses != null)
if (_ignoreClasses == null)
{
_ignoreClasses = InternalIgnoreClasses
.Split(',')
.Select(c => Type.GetType(c))
.Where(t => t != null).ToArray();
_ignoreClasses = CompleteIgnoreClasses
.Select(t => Type.GetType(t))
.Where(c => c != null)
.ToArray();
}

return _ignoreClasses;
}
}

private IEnumerable<string> CompleteIgnoreClasses
{
get
{
if (InternalIgnoreClasses != null)
{
foreach (var item in InternalIgnoreClasses.Split(','))
{
yield return item;
}
}

if (InternalExtendedIgnoreClasses.Count > 0)
{
foreach (ExtendedIgnoreClass item in InternalExtendedIgnoreClasses)
{
yield return item.Name;
}
}
}
}

private const string extendedIgnoreClasses = "assemblyQualifiedIgnoreClasses";

[ConfigurationProperty(extendedIgnoreClasses, IsRequired = false)]
private ExtendedIgnoreClassCollection InternalExtendedIgnoreClasses
{
get
{
return (ExtendedIgnoreClassCollection)this[extendedIgnoreClasses];
}
}

[ConfigurationCollection(typeof(ExtendedIgnoreClass), AddItemName = "class", CollectionType = ConfigurationElementCollectionType.BasicMap)]
class ExtendedIgnoreClassCollection : ConfigurationElementCollection
{
protected override ConfigurationElement CreateNewElement()
{
return new ExtendedIgnoreClass();
}

protected override object GetElementKey(ConfigurationElement element)
{
return ((ExtendedIgnoreClass)element).Name;
}
}

class ExtendedIgnoreClass : ConfigurationElement
{
[ConfigurationProperty("name", IsRequired = true)]
public string Name => (string)this["name"];
}

private const string metadataFilters = "metadataFilters";

[ConfigurationProperty(metadataFilters, IsRequired = false)]
Expand Down
3 changes: 3 additions & 0 deletions tests/Bugsnag.ConfigurationSection.Tests/Complete.config
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
proxyPassword="password"
sessionsEndpoint="https://www.bugsnag.com"
maximumBreadcrumbs="30">
<assemblyQualifiedIgnoreClasses>
<class name="Xunit.FactAttribute, xunit.core" />
</assemblyQualifiedIgnoreClasses>
<metadata>
<item key="test" value="wow" />
</metadata>
Expand Down
2 changes: 1 addition & 1 deletion tests/Bugsnag.ConfigurationSection.Tests/CompleteTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void ProjectNamespacesIsSet()
[Fact]
public void IgnoreClassesIsSet()
{
Assert.Equal(new[] { typeof(NotImplementedException), typeof(DllNotFoundException) }, TestConfiguration.IgnoreClasses);
Assert.Equal(new[] { typeof(NotImplementedException), typeof(DllNotFoundException), typeof(FactAttribute) }, TestConfiguration.IgnoreClasses);
}

[Fact]
Expand Down
4 changes: 2 additions & 2 deletions tests/Bugsnag.ConfigurationSection.Tests/DefaultTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ public void ProjectNamespacesIsNull()
}

[Fact]
public void IgnoreClassesIsNull()
public void IgnoreClassesIsEmpty()
{
Assert.Null(TestConfiguration.IgnoreClasses);
Assert.Empty(TestConfiguration.IgnoreClasses);
}

[Fact]
Expand Down