Skip to content
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
2 changes: 1 addition & 1 deletion src/Exceptionless/Extensions/DataDictionaryExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public static void AddObject(this IData data, ExtendedDataInfo info, Exceptionle
int index = 1;
while (data.Data.ContainsKey(name))
name = dataType.Name + index++;
} else if (name.AnyWildcardMatches(exclusions, true)) {
} else if (exclusions.Length > 0 && name.AnyWildcardMatches(exclusions, true)) {
return;
}

Expand Down
9 changes: 4 additions & 5 deletions src/Exceptionless/Serializer/DefaultJsonSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,10 @@ public virtual string Serialize(object model, string[] exclusions = null, int ma
if (maxDepth < 1)
maxDepth = Int32.MaxValue;

var excludedPropertyNames = new HashSet<string>(exclusions ?? new string[0], StringComparer.OrdinalIgnoreCase);
using (var sw = new StringWriter()) {
using (var jw = new JsonTextWriterWithExclusions(sw, excludedPropertyNames)) {
using (var jw = new JsonTextWriterWithExclusions(sw, exclusions)) {
jw.Formatting = Formatting.None;
Func<JsonProperty, object, bool> include = (property, value) => ShouldSerialize(jw, property, value, maxDepth, excludedPropertyNames);
Func<JsonProperty, object, bool> include = (property, value) => ShouldSerialize(jw, property, value, maxDepth, exclusions);
var resolver = new ExceptionlessContractResolver(include);
serializer.ContractResolver = resolver;
if (continueOnSerializationError)
Expand All @@ -71,9 +70,9 @@ public virtual object Deserialize(string json, Type type) {
return JsonConvert.DeserializeObject(json, type, _serializerSettings);
}

private bool ShouldSerialize(JsonTextWriterWithDepth jw, JsonProperty property, object obj, int maxDepth, ISet<string> excludedPropertyNames) {
private bool ShouldSerialize(JsonTextWriterWithDepth jw, JsonProperty property, object obj, int maxDepth, string[] excludedPropertyNames) {
try {
if (excludedPropertyNames != null && (property.UnderlyingName.AnyWildcardMatches(excludedPropertyNames, true) || property.PropertyName.AnyWildcardMatches(excludedPropertyNames, true)))
if (excludedPropertyNames != null && excludedPropertyNames.Length > 0 && (property.UnderlyingName.AnyWildcardMatches(excludedPropertyNames, ignoreCase: true) || property.PropertyName.AnyWildcardMatches(excludedPropertyNames, ignoreCase: true)))
return false;

bool isPrimitiveType = DefaultContractResolver.IsJsonPrimitiveType(property.PropertyType);
Expand Down
11 changes: 7 additions & 4 deletions src/Exceptionless/Serializer/JsonTextWriterWithExclusions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@

namespace Exceptionless.Serializer
{
internal class JsonTextWriterWithExclusions : JsonTextWriterWithDepth {
private readonly ISet<string> _excludedPropertyNames;
internal sealed class JsonTextWriterWithExclusions : JsonTextWriterWithDepth {
private readonly string[] _excludedPropertyNames;

public JsonTextWriterWithExclusions(TextWriter textWriter, ISet<string> excludedPropertyNames) : base(textWriter) {
public JsonTextWriterWithExclusions(TextWriter textWriter, string[] excludedPropertyNames) : base(textWriter) {
_excludedPropertyNames = excludedPropertyNames;
}

public override bool ShouldWriteProperty(string name) {
return !name.AnyWildcardMatches(_excludedPropertyNames, true);
var exclusions = _excludedPropertyNames;
return exclusions is null ||
exclusions.Length == 0 ||
!name.AnyWildcardMatches(exclusions, ignoreCase: true);
}
}
}