Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 379c4ff

Browse files
committed
Add JsConfig.ExcludeTypeNames + guard against TargetIE
1 parent e03bbb0 commit 379c4ff

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

src/ServiceStack.Text/JsConfig.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,12 @@ public static HashSet<Type> ExcludeTypes
641641
set => Config.AssertNotInit().ExcludeTypes = value;
642642
}
643643

644+
public static HashSet<string> ExcludeTypeNames
645+
{
646+
get => JsConfigScope.Current != null ? JsConfigScope.Current.ExcludeTypeNames : Config.Instance.ExcludeTypeNames;
647+
set => Config.AssertNotInit().ExcludeTypeNames = value;
648+
}
649+
644650
public static string[] IgnoreAttributesNamed
645651
{
646652
set => ReflectionExtensions.IgnoreAttributesNamed = value;

src/ServiceStack.Text/JsConfigScope.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public void Dispose()
5858
public class Config
5959
{
6060
private static Config instance;
61-
internal static Config Instance => instance ?? (instance = new Config(Defaults));
61+
internal static Config Instance => instance ??= new Config(Defaults);
6262
internal static bool HasInit = false;
6363

6464
public static Config AssertNotInit() => HasInit
@@ -176,6 +176,7 @@ public bool EmitLowercaseUnderscoreNames
176176
public EmptyCtorFactoryDelegate ModelFactory { get; set; }
177177
public string[] ExcludePropertyReferences { get; set; }
178178
public HashSet<Type> ExcludeTypes { get; set; }
179+
public HashSet<string> ExcludeTypeNames { get; set; }
179180
public bool EscapeUnicode { get; set; }
180181
public bool EscapeHtmlChars { get; set; }
181182

@@ -216,7 +217,11 @@ public bool EmitLowercaseUnderscoreNames
216217
MaxDepth = 50,
217218
OnDeserializationError = null,
218219
ModelFactory = ReflectionExtensions.GetConstructorMethodToCache,
219-
ExcludeTypes = new HashSet<Type> { typeof(System.IO.Stream) },
220+
ExcludeTypes = new HashSet<Type> {
221+
typeof(System.IO.Stream),
222+
typeof(System.Reflection.MethodBase),
223+
},
224+
ExcludeTypeNames = new HashSet<string> {}
220225
};
221226

222227
public Config Populate(Config config)
@@ -257,6 +262,7 @@ public Config Populate(Config config)
257262
OnDeserializationError = config.OnDeserializationError;
258263
ModelFactory = config.ModelFactory;
259264
ExcludeTypes = config.ExcludeTypes;
265+
ExcludeTypeNames = config.ExcludeTypeNames;
260266
return this;
261267
}
262268
}

src/ServiceStack.Text/ReflectionExtensions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,8 @@ public static PropertyInfo[] OnlySerializableProperties(this PropertyInfo[] prop
637637
var name = attr.GetType().Name;
638638
return !IgnoreAttributesNamed.Contains(name);
639639
}))
640-
.Where(prop => !JsConfig.ExcludeTypes.Contains(prop.PropertyType))
640+
.Where(prop => !(JsConfig.ExcludeTypes.Contains(prop.PropertyType) ||
641+
JsConfig.ExcludeTypeNames.Contains(prop.PropertyType.FullName)))
641642
.ToArray();
642643
}
643644

src/ServiceStack.Text/TypeSerializer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ private static bool HasCircularReferences(object value, Stack<object> parentValu
346346
{
347347
var type = value?.GetType();
348348

349-
if (type == null || !type.IsClass || value is string)
349+
if (type == null || !type.IsClass || value is string || value is Type)
350350
return false;
351351

352352
if (parentValues == null)

0 commit comments

Comments
 (0)