private void ImportSystemExceptionDataMembers() { /* * The data members imported for System.Exception are private fields. They must be treated specially. * The EssentialExceptionFields Dictionary keeps track of which private fields needs to be imported, and also the name that they should be serialized with. */ Type type = this.UnderlyingType; List <DataMember> tempMembers; tempMembers = new List <DataMember>(); Dictionary <string, DataMember> memberNamesTable = new Dictionary <string, DataMember>(); foreach (string fieldInfoName in EssentialExceptionFields.Keys) { FieldInfo member = type.GetField(fieldInfoName, BindingFlags.NonPublic | BindingFlags.DeclaredOnly | BindingFlags.Instance); if (CanSerializeMember(member)) { DataMember memberContract = new DataMember(member); memberContract.Name = DataContract.EncodeLocalName(member.Name); memberContract.IsRequired = false; memberContract.IsNullable = DataContract.IsTypeNullable(memberContract.MemberType); CheckAndAddMember(tempMembers, memberContract, memberNamesTable); } } Interlocked.MemoryBarrier(); _members = tempMembers; }
private void ImportDataMembers() { /* * DataMembers are used for the deserialization of Exceptions. * DataMembers represent the fields and/or settable properties that the underlying Exception has. * The DataMembers are stored and eventually passed to a ClassDataContract created from the underlying Exception. * The ClassDataContract uses the list of DataMembers to set the fields/properties for the newly created Exception. * If a DataMember is a property it must be settable. */ Type type = this.UnderlyingType; if (type == Globals.TypeOfException) { ImportSystemExceptionDataMembers(); //System.Exception must be handled specially because it is the only exception that imports private fields. return; } List <DataMember> tempMembers; if (BaseContract != null) { tempMembers = new List <DataMember>(BaseContract.Members); //Don't set tempMembers = BaseContract.Members and then start adding, because this alters the base's reference. } else { tempMembers = new List <DataMember>(); } Dictionary <string, DataMember> memberNamesTable = new Dictionary <string, DataMember>(); MemberInfo[] memberInfos; memberInfos = type.GetMembers(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public); for (int i = 0; i < memberInfos.Length; i++) { MemberInfo member = memberInfos[i]; //Public properties with set methods can be deserialized with the ClassDataContract PropertyInfo publicProperty = member as PropertyInfo; if (publicProperty != null && publicProperty.SetMethod != null) { DataMember memberContract = new DataMember(member); memberContract.Name = DataContract.EncodeLocalName(member.Name); memberContract.IsRequired = false; memberContract.IsNullable = DataContract.IsTypeNullable(memberContract.MemberType); if (HasNoConflictWithBaseMembers(memberContract)) { CheckAndAddMember(tempMembers, memberContract, memberNamesTable); } } } Interlocked.MemoryBarrier(); _members = tempMembers; }