@@ -439,47 +439,50 @@ static internal bool IsNonAttributedTypeValidForSerialization(Type type)
439439 }
440440 }
441441
442- private static string [ ] s_knownSerializableTypeNames = new string [ ] {
443- "System.Collections.Queue" ,
444- "System.Collections.Stack" ,
445- "System.Globalization.CultureInfo" ,
446- "System.Version" ,
447- "System.Collections.Generic.KeyValuePair `2" ,
448- "System.Collections.Generic.Queue `1" ,
449- "System.Collections.Generic.Stack`1" ,
450- "System.Collections.ObjectModel.ReadOnlyCollection`1" ,
451- "System.Collections.ObjectModel.ReadOnlyDictionary`2" ,
452- "System.Tuple`1" ,
453- "System.Tuple`2" ,
454- "System.Tuple`3" ,
455- "System.Tuple`4" ,
456- "System.Tuple`5" ,
457- "System.Tuple`6" ,
458- "System.Tuple`7" ,
459- "System.Tuple`8" ,
442+ private static readonly Dictionary < string , string [ ] > s_knownSerializableTypeInfos = new Dictionary < string , string [ ] > {
443+ { "System.Collections.Generic.KeyValuePair`2" , Array . Empty < string > ( ) } ,
444+ { "System.Collections.Generic.Queue`1" , new [ ] { "_syncRoot" } } ,
445+ { "System.Collections.Generic.Stack`1" , new [ ] { "_syncRoot" } } ,
446+ { "System.Collections.ObjectModel.ReadOnlyCollection`1" , new [ ] { "_syncRoot" } } ,
447+ { "System.Collections.ObjectModel.ReadOnlyDictionary `2" , new [ ] { "_syncRoot" , "_keys" , "_values" } } ,
448+ { "System.Tuple `1" , Array . Empty < string > ( ) } ,
449+ { "System.Tuple`2" , Array . Empty < string > ( ) } ,
450+ { "System.Tuple`3" , Array . Empty < string > ( ) } ,
451+ { "System.Tuple`4" , Array . Empty < string > ( ) } ,
452+ { "System.Tuple`5" , Array . Empty < string > ( ) } ,
453+ { "System.Tuple`6" , Array . Empty < string > ( ) } ,
454+ { "System.Tuple`7" , Array . Empty < string > ( ) } ,
455+ { "System.Tuple`8" , Array . Empty < string > ( ) } ,
456+ { "System.Collections.Queue" , new [ ] { "_syncRoot" } } ,
457+ { "System.Collections.Stack" , new [ ] { "_syncRoot" } } ,
458+ { "System.Globalization.CultureInfo" , Array . Empty < string > ( ) } ,
459+ { "System.Version" , Array . Empty < string > ( ) } ,
460460 } ;
461461
462+ private static string GetGeneralTypeName ( Type type )
463+ {
464+ TypeInfo typeInfo = type . GetTypeInfo ( ) ;
465+ return type . GetTypeInfo ( ) . IsGenericType && ! typeInfo . IsGenericParameter
466+ ? typeInfo . GetGenericTypeDefinition ( ) . FullName
467+ : type . FullName ;
468+ }
469+
462470 internal static bool IsKnownSerializableType ( Type type )
463471 {
464472 // Applies to known types that DCS understands how to serialize/deserialize
465473 //
474+ string typeFullName = GetGeneralTypeName ( type ) ;
466475
467- // Ajdust for generic type
468- if ( type . GetTypeInfo ( ) . IsGenericType && ! type . GetTypeInfo ( ) . IsGenericTypeDefinition )
469- {
470- type = type . GetGenericTypeDefinition ( ) ;
471- }
476+ return s_knownSerializableTypeInfos . ContainsKey ( typeFullName )
477+ || Globals . TypeOfException . IsAssignableFrom ( type ) ;
478+ }
472479
473- // Check for known types
474- if ( Enumerable . Contains ( s_knownSerializableTypeNames , type . FullName ) )
475- {
476- return true ;
477- }
478- //Enable ClassDataContract to give support to Exceptions.
479- if ( Globals . TypeOfException . IsAssignableFrom ( type ) )
480- return true ;
480+ internal static bool IsNonSerializedMember ( Type type , string memberName )
481+ {
482+ string typeFullName = GetGeneralTypeName ( type ) ;
481483
482- return false ;
484+ return s_knownSerializableTypeInfos . ContainsKey ( typeFullName )
485+ && s_knownSerializableTypeInfos [ typeFullName ] . Contains ( memberName ) ;
483486 }
484487
485488 private XmlDictionaryString [ ] CreateChildElementNamespaces ( )
@@ -1073,8 +1076,7 @@ private void ImportDataMembers()
10731076
10741077 private static bool CanSerializeMember ( FieldInfo field )
10751078 {
1076- return field != null &&
1077- field . FieldType != Globals . TypeOfObject ; // Don't really know how to serialize plain System.Object instance;
1079+ return field != null && ! ClassDataContract . IsNonSerializedMember ( field . DeclaringType , field . Name ) ;
10781080 }
10791081
10801082 private bool SetIfGetOnlyCollection ( DataMember memberContract )
0 commit comments