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

Commit 935225f

Browse files
committed
Extract OnlySerializableProperties into a reusable ext method
1 parent 0532209 commit 935225f

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

src/ServiceStack.Text/ReflectionExtensions.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,11 @@ internal static void Reset()
649649
public static PropertyInfo[] GetSerializableProperties(this Type type)
650650
{
651651
var publicProperties = GetPublicProperties(type);
652+
return publicProperties.OnlySerializableProperties(type);
653+
}
654+
655+
public static PropertyInfo[] OnlySerializableProperties(this PropertyInfo[] publicProperties, Type type = null)
656+
{
652657
var publicReadableProperties = publicProperties.Where(x => x.PropertyGetMethod() != null);
653658

654659
if (type.IsDto())
@@ -659,10 +664,11 @@ public static PropertyInfo[] GetSerializableProperties(this Type type)
659664

660665
// else return those properties that are not decorated with IgnoreDataMember
661666
return publicReadableProperties
662-
.Where(prop => prop.AllAttributes().All(attr => {
663-
var name = attr.GetType().Name;
664-
return !IgnoreAttributesNamed.Contains(name);
665-
}))
667+
.Where(prop => prop.AllAttributes()
668+
.All(attr => {
669+
var name = attr.GetType().Name;
670+
return !IgnoreAttributesNamed.Contains(name);
671+
}))
666672
.Where(prop => !JsConfig.ExcludeTypes.Contains(prop.PropertyType))
667673
.ToArray();
668674
}
@@ -1010,6 +1016,9 @@ public static bool HasAttributeNamed(this MemberInfo mi, string name)
10101016
const string DataContract = "DataContractAttribute";
10111017
public static bool IsDto(this Type type)
10121018
{
1019+
if (type == null)
1020+
return false;
1021+
10131022
#if (NETFX_CORE || PCL)
10141023
return type.HasAttribute<DataContractAttribute>();
10151024
#else

0 commit comments

Comments
 (0)