Skip to content

Commit 59c8762

Browse files
authored
Merge pull request #109 from bugsnag/martin308/ignore-classes
Allow fully qualified types to be provided in config files
2 parents 60c3875 + 432f8de commit 59c8762

File tree

5 files changed

+69
-9
lines changed

5 files changed

+69
-9
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ Changelog
33

44
## Unreleased
55

6+
* Add additional method of specifying ignore classes to allow for providing fully qualified assembly names in config files.
7+
| [martin308](https://github.com/martin308)
8+
| [#109](https://github.com/bugsnag/bugsnag-dotnet/pull/109)
9+
610
* Include Configuration package with WebApi
711
| [martin308](https://github.com/martin308)
812
| [#105](https://github.com/bugsnag/bugsnag-dotnet/pull/105)

src/Bugsnag.ConfigurationSection/Configuration.cs

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ public string[] ProjectNamespaces
207207

208208
private const string ignoreClasses = "ignoreClasses";
209209

210-
[ConfigurationProperty("ignoreClasses", IsRequired = false)]
210+
[ConfigurationProperty(ignoreClasses, IsRequired = false)]
211211
private string InternalIgnoreClasses
212212
{
213213
get
@@ -229,18 +229,71 @@ public Type[] IgnoreClasses
229229
{
230230
get
231231
{
232-
if (_ignoreClasses == null && InternalIgnoreClasses != null)
232+
if (_ignoreClasses == null)
233233
{
234-
_ignoreClasses = InternalIgnoreClasses
235-
.Split(',')
236-
.Select(c => Type.GetType(c))
237-
.Where(t => t != null).ToArray();
234+
_ignoreClasses = CompleteIgnoreClasses
235+
.Select(t => Type.GetType(t))
236+
.Where(c => c != null)
237+
.ToArray();
238238
}
239239

240240
return _ignoreClasses;
241241
}
242242
}
243243

244+
private IEnumerable<string> CompleteIgnoreClasses
245+
{
246+
get
247+
{
248+
if (InternalIgnoreClasses != null)
249+
{
250+
foreach (var item in InternalIgnoreClasses.Split(','))
251+
{
252+
yield return item;
253+
}
254+
}
255+
256+
if (InternalExtendedIgnoreClasses.Count > 0)
257+
{
258+
foreach (ExtendedIgnoreClass item in InternalExtendedIgnoreClasses)
259+
{
260+
yield return item.Name;
261+
}
262+
}
263+
}
264+
}
265+
266+
private const string extendedIgnoreClasses = "assemblyQualifiedIgnoreClasses";
267+
268+
[ConfigurationProperty(extendedIgnoreClasses, IsRequired = false)]
269+
private ExtendedIgnoreClassCollection InternalExtendedIgnoreClasses
270+
{
271+
get
272+
{
273+
return (ExtendedIgnoreClassCollection)this[extendedIgnoreClasses];
274+
}
275+
}
276+
277+
[ConfigurationCollection(typeof(ExtendedIgnoreClass), AddItemName = "class", CollectionType = ConfigurationElementCollectionType.BasicMap)]
278+
class ExtendedIgnoreClassCollection : ConfigurationElementCollection
279+
{
280+
protected override ConfigurationElement CreateNewElement()
281+
{
282+
return new ExtendedIgnoreClass();
283+
}
284+
285+
protected override object GetElementKey(ConfigurationElement element)
286+
{
287+
return ((ExtendedIgnoreClass)element).Name;
288+
}
289+
}
290+
291+
class ExtendedIgnoreClass : ConfigurationElement
292+
{
293+
[ConfigurationProperty("name", IsRequired = true)]
294+
public string Name => (string)this["name"];
295+
}
296+
244297
private const string metadataFilters = "metadataFilters";
245298

246299
[ConfigurationProperty(metadataFilters, IsRequired = false)]

tests/Bugsnag.ConfigurationSection.Tests/Complete.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
proxyPassword="password"
2222
sessionsEndpoint="https://www.bugsnag.com"
2323
maximumBreadcrumbs="30">
24+
<assemblyQualifiedIgnoreClasses>
25+
<class name="Xunit.FactAttribute, xunit.core" />
26+
</assemblyQualifiedIgnoreClasses>
2427
<metadata>
2528
<item key="test" value="wow" />
2629
</metadata>

tests/Bugsnag.ConfigurationSection.Tests/CompleteTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public void ProjectNamespacesIsSet()
7070
[Fact]
7171
public void IgnoreClassesIsSet()
7272
{
73-
Assert.Equal(new[] { typeof(NotImplementedException), typeof(DllNotFoundException) }, TestConfiguration.IgnoreClasses);
73+
Assert.Equal(new[] { typeof(NotImplementedException), typeof(DllNotFoundException), typeof(FactAttribute) }, TestConfiguration.IgnoreClasses);
7474
}
7575

7676
[Fact]

tests/Bugsnag.ConfigurationSection.Tests/DefaultTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ public void ProjectNamespacesIsNull()
6262
}
6363

6464
[Fact]
65-
public void IgnoreClassesIsNull()
65+
public void IgnoreClassesIsEmpty()
6666
{
67-
Assert.Null(TestConfiguration.IgnoreClasses);
67+
Assert.Empty(TestConfiguration.IgnoreClasses);
6868
}
6969

7070
[Fact]

0 commit comments

Comments
 (0)