static private SerializationSetValue ( |
||
fi | ||
target | object | |
value | object | |
리턴 | void |
internal static SerializationInfo PrepareConstructorArgs(object serObj, string[] fieldNames, object[] fieldValues, out StreamingContext context) { SerializationInfo serializationInfo = null; if (serObj is ISerializable) { serializationInfo = new SerializationInfo(serObj.GetType(), ObjectCloneHelper.s_converter); for (int i = 0; i < fieldNames.Length; i++) { if (fieldNames[i] != null) { serializationInfo.AddValue(fieldNames[i], fieldValues[i]); } } } else { Hashtable hashtable = new Hashtable(); int j = 0; int num = 0; while (j < fieldNames.Length) { if (fieldNames[j] != null) { hashtable[fieldNames[j]] = fieldValues[j]; num++; } j++; } MemberInfo[] serializableMembers = FormatterServices.GetSerializableMembers(serObj.GetType()); for (int k = 0; k < serializableMembers.Length; k++) { string name = serializableMembers[k].Name; if (!hashtable.Contains(name)) { object[] customAttributes = serializableMembers[k].GetCustomAttributes(typeof(OptionalFieldAttribute), false); if (customAttributes == null || customAttributes.Length == 0) { throw new SerializationException(Environment.GetResourceString("Serialization_MissingMember", new object[] { serializableMembers[k], serObj.GetType(), typeof(OptionalFieldAttribute).FullName })); } } else { object value = hashtable[name]; FormatterServices.SerializationSetValue(serializableMembers[k], serObj, value); } } } context = ObjectCloneHelper.s_cloneContext; return(serializationInfo); }
internal static SerializationInfo PrepareConstructorArgs(object serObj, string[] fieldNames, object[] fieldValues, out StreamingContext context) { SerializationInfo info = null; if (serObj is ISerializable) { info = new SerializationInfo(serObj.GetType(), s_converter); for (int i = 0; i < fieldNames.Length; i++) { if (fieldNames[i] != null) { info.AddValue(fieldNames[i], fieldValues[i]); } } } else { Hashtable hashtable = new Hashtable(); int index = 0; int num3 = 0; while (index < fieldNames.Length) { if (fieldNames[index] != null) { hashtable[fieldNames[index]] = fieldValues[index]; num3++; } index++; } MemberInfo[] serializableMembers = FormatterServices.GetSerializableMembers(serObj.GetType()); for (int j = 0; j < serializableMembers.Length; j++) { string name = serializableMembers[j].Name; if (!hashtable.Contains(name)) { object[] customAttributes = serializableMembers[j].GetCustomAttributes(typeof(OptionalFieldAttribute), false); if ((customAttributes == null) || (customAttributes.Length == 0)) { throw new SerializationException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Serialization_MissingMember"), new object[] { serializableMembers[j], serObj.GetType(), typeof(OptionalFieldAttribute).FullName })); } } else { object obj2 = hashtable[name]; FormatterServices.SerializationSetValue(serializableMembers[j], serObj, obj2); } } } context = s_cloneContext; return(info); }
internal static SerializationInfo PrepareConstructorArgs(object serObj, string[] fieldNames, object[] fieldValues, out StreamingContext context) { SerializationInfo serializationInfo = (SerializationInfo)null; if (serObj is ISerializable) { serializationInfo = new SerializationInfo(serObj.GetType(), ObjectCloneHelper.s_converter); for (int index = 0; index < fieldNames.Length; ++index) { if (fieldNames[index] != null) { serializationInfo.AddValue(fieldNames[index], fieldValues[index]); } } } else { Hashtable hashtable = new Hashtable(); int index1 = 0; int num = 0; for (; index1 < fieldNames.Length; ++index1) { if (fieldNames[index1] != null) { hashtable[(object)fieldNames[index1]] = fieldValues[index1]; ++num; } } MemberInfo[] serializableMembers = FormatterServices.GetSerializableMembers(serObj.GetType()); for (int index2 = 0; index2 < serializableMembers.Length; ++index2) { string name = serializableMembers[index2].Name; if (!hashtable.Contains((object)name)) { object[] customAttributes = serializableMembers[index2].GetCustomAttributes(typeof(OptionalFieldAttribute), false); if (customAttributes == null || customAttributes.Length == 0) { throw new SerializationException(Environment.GetResourceString("Serialization_MissingMember", (object)serializableMembers[index2], (object)serObj.GetType(), (object)typeof(OptionalFieldAttribute).FullName)); } } else { object obj = hashtable[(object)name]; FormatterServices.SerializationSetValue(serializableMembers[index2], serObj, obj); } } } context = ObjectCloneHelper.s_cloneContext; return(serializationInfo); }
public static object PopulateObjectMembers(object obj, MemberInfo[] members, object[] data) { if (obj == null) { throw new ArgumentNullException("obj"); } if (members == null) { throw new ArgumentNullException("members"); } if (data == null) { throw new ArgumentNullException("data"); } if (members.Length != data.Length) { throw new ArgumentException(Environment.GetResourceString("Argument_DataLengthDifferent")); } for (int i = 0; i < members.Length; i++) { MemberInfo memberInfo = members[i]; if (memberInfo == null) { throw new ArgumentNullException("members", Environment.GetResourceString("ArgumentNull_NullMember", new object[] { i })); } if (data[i] != null) { if (memberInfo.MemberType != MemberTypes.Field) { throw new SerializationException(Environment.GetResourceString("Serialization_UnknownMemberInfo")); } FormatterServices.SerializationSetValue(memberInfo, obj, data[i]); } } return(obj); }
[System.Security.SecurityCritical] // auto-generated internal static SerializationInfo PrepareConstructorArgs(object serObj, string[] fieldNames, object[] fieldValues, out StreamingContext context) { SerializationInfo si = null; if (serObj is ISerializable) { si = new SerializationInfo(serObj.GetType(), s_converter); for (int i = 0; i < fieldNames.Length; i++) { if (fieldNames[i] != null) { si.AddValue(fieldNames[i], fieldValues[i]); } } } else { // We have a case where the from object was ISerializable and to object is not // @ Hashtable fields = new Hashtable(); int incomingFieldIndex = 0; int numIncomingFields = 0; for (; incomingFieldIndex < fieldNames.Length; incomingFieldIndex++) { if (fieldNames[incomingFieldIndex] != null) { fields[fieldNames[incomingFieldIndex]] = fieldValues[incomingFieldIndex]; numIncomingFields++; } } MemberInfo[] mi = FormatterServices.GetSerializableMembers(serObj.GetType()); for (int index = 0; index < mi.Length; index++) { string fieldName = mi[index].Name; if (!fields.Contains(fieldName)) { // If we are missing a field value then it's not necessarily // the end of the world: check whether the field is marked // [OptionalField]. Object [] attrs = mi[index].GetCustomAttributes(typeof(OptionalFieldAttribute), false); if (attrs == null || attrs.Length == 0) { throw new SerializationException(Environment.GetResourceString("Serialization_MissingMember", mi[index], serObj.GetType(), typeof(OptionalFieldAttribute).FullName)); } continue; } object value = fields[fieldName]; FormatterServices.SerializationSetValue(mi[index], serObj, value); } } context = s_cloneContext; return(si); }
internal void CompleteObject(ObjectHolder holder, bool bObjectFullyComplete) { FixupHolderList missingElements = holder.m_missingElements; object obj = null; ObjectHolder objectHolder = null; int num = 0; if (holder.ObjectValue == null) { throw new SerializationException(Environment.GetResourceString("Serialization_MissingObject", new object[] { holder.m_id })); } if (missingElements == null) { return; } if (holder.HasSurrogate || holder.HasISerializable) { SerializationInfo serInfo = holder.m_serInfo; if (serInfo == null) { throw new SerializationException(Environment.GetResourceString("Serialization_InvalidFixupDiscovered")); } if (missingElements != null) { for (int i = 0; i < missingElements.m_count; i++) { if (missingElements.m_values[i] != null && this.GetCompletionInfo(missingElements.m_values[i], out objectHolder, out obj, bObjectFullyComplete)) { object objectValue = objectHolder.ObjectValue; if (this.CanCallGetType(objectValue)) { serInfo.UpdateValue((string)obj, objectValue, objectValue.GetType()); } else { serInfo.UpdateValue((string)obj, objectValue, typeof(MarshalByRefObject)); } num++; missingElements.m_values[i] = null; if (!bObjectFullyComplete) { holder.DecrementFixupsRemaining(this); objectHolder.RemoveDependency(holder.m_id); } } } } } else { for (int j = 0; j < missingElements.m_count; j++) { FixupHolder fixupHolder = missingElements.m_values[j]; if (fixupHolder != null && this.GetCompletionInfo(fixupHolder, out objectHolder, out obj, bObjectFullyComplete)) { if (objectHolder.TypeLoadExceptionReachable) { holder.TypeLoadException = objectHolder.TypeLoadException; if (holder.Reachable) { throw new SerializationException(Environment.GetResourceString("Serialization_TypeLoadFailure", new object[] { holder.TypeLoadException.TypeName })); } } if (holder.Reachable) { objectHolder.Reachable = true; } int fixupType = fixupHolder.m_fixupType; if (fixupType != 1) { if (fixupType != 2) { throw new SerializationException(Environment.GetResourceString("Serialization_UnableToFixup")); } MemberInfo memberInfo = (MemberInfo)obj; if (memberInfo.MemberType != MemberTypes.Field) { throw new SerializationException(Environment.GetResourceString("Serialization_UnableToFixup")); } if (holder.RequiresValueTypeFixup && holder.ValueTypeFixupPerformed) { if (!this.DoValueTypeFixup((FieldInfo)memberInfo, holder, objectHolder.ObjectValue)) { throw new SerializationException(Environment.GetResourceString("Serialization_PartialValueTypeFixup")); } } else { FormatterServices.SerializationSetValue(memberInfo, holder.ObjectValue, objectHolder.ObjectValue); } if (objectHolder.RequiresValueTypeFixup) { objectHolder.ValueTypeFixupPerformed = true; } } else { if (holder.RequiresValueTypeFixup) { throw new SerializationException(Environment.GetResourceString("Serialization_ValueTypeFixup")); } ((Array)holder.ObjectValue).SetValue(objectHolder.ObjectValue, (int[])obj); } num++; missingElements.m_values[j] = null; if (!bObjectFullyComplete) { holder.DecrementFixupsRemaining(this); objectHolder.RemoveDependency(holder.m_id); } } } } this.m_fixupCount -= (long)num; if (missingElements.m_count == num) { holder.m_missingElements = null; } }
private bool DoValueTypeFixup(FieldInfo memberToFix, ObjectHolder holder, object value) { FieldInfo[] array = new FieldInfo[4]; int num = 0; int[] array2 = null; object objectValue = holder.ObjectValue; while (holder.RequiresValueTypeFixup) { if (num + 1 >= array.Length) { FieldInfo[] array3 = new FieldInfo[array.Length * 2]; Array.Copy(array, array3, array.Length); array = array3; } ValueTypeFixupInfo valueFixup = holder.ValueFixup; objectValue = holder.ObjectValue; if (valueFixup.ParentField != null) { FieldInfo parentField = valueFixup.ParentField; ObjectHolder objectHolder = this.FindObjectHolder(valueFixup.ContainerID); if (objectHolder.ObjectValue == null) { break; } if (Nullable.GetUnderlyingType(parentField.FieldType) != null) { array[num] = parentField.FieldType.GetField("value", BindingFlags.Instance | BindingFlags.NonPublic); num++; } array[num] = parentField; holder = objectHolder; num++; } else { holder = this.FindObjectHolder(valueFixup.ContainerID); array2 = valueFixup.ParentIndex; if (holder.ObjectValue == null) { break; } break; } } if (!(holder.ObjectValue is Array) && holder.ObjectValue != null) { objectValue = holder.ObjectValue; } if (num != 0) { FieldInfo[] array4 = new FieldInfo[num]; for (int i = 0; i < num; i++) { FieldInfo fieldInfo = array[num - 1 - i]; SerializationFieldInfo serializationFieldInfo = fieldInfo as SerializationFieldInfo; array4[i] = ((serializationFieldInfo == null) ? fieldInfo : serializationFieldInfo.FieldInfo); } TypedReference typedReference = TypedReference.MakeTypedReference(objectValue, array4); if (memberToFix != null) { ((RuntimeFieldInfo)memberToFix).SetValueDirect(typedReference, value); } else { TypedReference.SetTypedReference(typedReference, value); } } else if (memberToFix != null) { FormatterServices.SerializationSetValue(memberToFix, objectValue, value); } if (array2 != null && holder.ObjectValue != null) { ((Array)holder.ObjectValue).SetValue(objectValue, array2); } return(true); }
private bool DoValueTypeFixup(FieldInfo memberToFix, ObjectHolder holder, object value) { FieldInfo[] sourceArray = new FieldInfo[4]; FieldInfo[] flds = null; int index = 0; int[] indices = null; ValueTypeFixupInfo valueFixup = null; object objectValue = holder.ObjectValue; while (holder.RequiresValueTypeFixup) { if ((index + 1) >= sourceArray.Length) { FieldInfo[] destinationArray = new FieldInfo[sourceArray.Length * 2]; Array.Copy(sourceArray, destinationArray, sourceArray.Length); sourceArray = destinationArray; } valueFixup = holder.ValueFixup; objectValue = holder.ObjectValue; if (valueFixup.ParentField != null) { FieldInfo parentField = valueFixup.ParentField; ObjectHolder holder2 = this.FindObjectHolder(valueFixup.ContainerID); if (holder2.ObjectValue == null) { break; } if (Nullable.GetUnderlyingType(parentField.FieldType) != null) { sourceArray[index] = parentField.FieldType.GetField("value", BindingFlags.NonPublic | BindingFlags.Instance); index++; } sourceArray[index] = parentField; holder = holder2; index++; } else { holder = this.FindObjectHolder(valueFixup.ContainerID); indices = valueFixup.ParentIndex; if (holder.ObjectValue != null) { } break; } } if (!(holder.ObjectValue is Array) && (holder.ObjectValue != null)) { objectValue = holder.ObjectValue; } if (index != 0) { flds = new FieldInfo[index]; for (int i = 0; i < index; i++) { FieldInfo info3 = sourceArray[(index - 1) - i]; SerializationFieldInfo info4 = info3 as SerializationFieldInfo; flds[i] = (info4 == null) ? info3 : info4.FieldInfo; } TypedReference reference = TypedReference.MakeTypedReference(objectValue, flds); if (memberToFix != null) { ((RuntimeFieldInfo)memberToFix).SetValueDirect(reference, value); } else { TypedReference.SetTypedReference(reference, value); } } else if (memberToFix != null) { FormatterServices.SerializationSetValue(memberToFix, objectValue, value); } if ((indices != null) && (holder.ObjectValue != null)) { ((Array)holder.ObjectValue).SetValue(objectValue, indices); } return(true); }
internal void CompleteObject(ObjectHolder holder, bool bObjectFullyComplete) { FixupHolderList missingElements = holder.m_missingElements; object member = null; ObjectHolder holder3 = null; int num = 0; if (holder.ObjectValue == null) { throw new SerializationException(Environment.GetResourceString("Serialization_MissingObject", new object[] { holder.m_id })); } if (missingElements != null) { if (holder.HasSurrogate || holder.HasISerializable) { SerializationInfo serInfo = holder.m_serInfo; if (serInfo == null) { throw new SerializationException(Environment.GetResourceString("Serialization_InvalidFixupDiscovered")); } if (missingElements != null) { for (int i = 0; i < missingElements.m_count; i++) { if ((missingElements.m_values[i] != null) && this.GetCompletionInfo(missingElements.m_values[i], out holder3, out member, bObjectFullyComplete)) { object objectValue = holder3.ObjectValue; if (this.CanCallGetType(objectValue)) { serInfo.UpdateValue((string)member, objectValue, objectValue.GetType()); } else { serInfo.UpdateValue((string)member, objectValue, typeof(MarshalByRefObject)); } num++; missingElements.m_values[i] = null; if (!bObjectFullyComplete) { holder.DecrementFixupsRemaining(this); holder3.RemoveDependency(holder.m_id); } } } } } else { for (int j = 0; j < missingElements.m_count; j++) { MemberInfo info2; FixupHolder fixup = missingElements.m_values[j]; if ((fixup == null) || !this.GetCompletionInfo(fixup, out holder3, out member, bObjectFullyComplete)) { continue; } if (holder3.TypeLoadExceptionReachable) { holder.TypeLoadException = holder3.TypeLoadException; if (holder.Reachable) { throw new SerializationException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Serialization_TypeLoadFailure"), new object[] { holder.TypeLoadException.TypeName })); } } if (holder.Reachable) { holder3.Reachable = true; } switch (fixup.m_fixupType) { case 1: if (holder.RequiresValueTypeFixup) { throw new SerializationException(Environment.GetResourceString("Serialization_ValueTypeFixup")); } break; case 2: info2 = (MemberInfo)member; if (info2.MemberType != MemberTypes.Field) { throw new SerializationException(Environment.GetResourceString("Serialization_UnableToFixup")); } if (!holder.RequiresValueTypeFixup || !holder.ValueTypeFixupPerformed) { goto Label_024C; } if (!this.DoValueTypeFixup((FieldInfo)info2, holder, holder3.ObjectValue)) { throw new SerializationException(Environment.GetResourceString("Serialization_PartialValueTypeFixup")); } goto Label_0260; default: throw new SerializationException(Environment.GetResourceString("Serialization_UnableToFixup")); } ((Array)holder.ObjectValue).SetValue(holder3.ObjectValue, (int[])member); goto Label_0293; Label_024C: FormatterServices.SerializationSetValue(info2, holder.ObjectValue, holder3.ObjectValue); Label_0260: if (holder3.RequiresValueTypeFixup) { holder3.ValueTypeFixupPerformed = true; } Label_0293: num++; missingElements.m_values[j] = null; if (!bObjectFullyComplete) { holder.DecrementFixupsRemaining(this); holder3.RemoveDependency(holder.m_id); } } } this.m_fixupCount -= num; if (missingElements.m_count == num) { holder.m_missingElements = null; } } }
internal void CompleteObject(ObjectHolder holder, bool bObjectFullyComplete) { FixupHolderList fixupHolderList = holder.m_missingElements; object member = (object)null; ObjectHolder holder1 = (ObjectHolder)null; int num = 0; if (holder.ObjectValue == null) { throw new SerializationException(Environment.GetResourceString("Serialization_MissingObject", (object)holder.m_id)); } if (fixupHolderList == null) { return; } if (holder.HasSurrogate || holder.HasISerializable) { SerializationInfo serializationInfo1 = holder.m_serInfo; if (serializationInfo1 == null) { throw new SerializationException(Environment.GetResourceString("Serialization_InvalidFixupDiscovered")); } if (fixupHolderList != null) { for (int index = 0; index < fixupHolderList.m_count; ++index) { if (fixupHolderList.m_values[index] != null && this.GetCompletionInfo(fixupHolderList.m_values[index], out holder1, out member, bObjectFullyComplete)) { object objectValue = holder1.ObjectValue; if (this.CanCallGetType(objectValue)) { SerializationInfo serializationInfo2 = serializationInfo1; string name = (string)member; object obj = objectValue; Type type = obj.GetType(); serializationInfo2.UpdateValue(name, obj, type); } else { serializationInfo1.UpdateValue((string)member, objectValue, typeof(MarshalByRefObject)); } ++num; fixupHolderList.m_values[index] = (FixupHolder)null; if (!bObjectFullyComplete) { holder.DecrementFixupsRemaining(this); holder1.RemoveDependency(holder.m_id); } } } } } else { for (int index = 0; index < fixupHolderList.m_count; ++index) { FixupHolder fixup = fixupHolderList.m_values[index]; if (fixup != null && this.GetCompletionInfo(fixup, out holder1, out member, bObjectFullyComplete)) { if (holder1.TypeLoadExceptionReachable) { holder.TypeLoadException = holder1.TypeLoadException; if (holder.Reachable) { throw new SerializationException(Environment.GetResourceString("Serialization_TypeLoadFailure", (object)holder.TypeLoadException.TypeName)); } } if (holder.Reachable) { holder1.Reachable = true; } switch (fixup.m_fixupType) { case 1: if (holder.RequiresValueTypeFixup) { throw new SerializationException(Environment.GetResourceString("Serialization_ValueTypeFixup")); } ((Array)holder.ObjectValue).SetValue(holder1.ObjectValue, (int[])member); break; case 2: MemberInfo fi = (MemberInfo)member; if (fi.MemberType != MemberTypes.Field) { throw new SerializationException(Environment.GetResourceString("Serialization_UnableToFixup")); } if (holder.RequiresValueTypeFixup && holder.ValueTypeFixupPerformed) { if (!this.DoValueTypeFixup((FieldInfo)fi, holder, holder1.ObjectValue)) { throw new SerializationException(Environment.GetResourceString("Serialization_PartialValueTypeFixup")); } } else { FormatterServices.SerializationSetValue(fi, holder.ObjectValue, holder1.ObjectValue); } if (holder1.RequiresValueTypeFixup) { holder1.ValueTypeFixupPerformed = true; break; } break; default: throw new SerializationException(Environment.GetResourceString("Serialization_UnableToFixup")); } ++num; fixupHolderList.m_values[index] = (FixupHolder)null; if (!bObjectFullyComplete) { holder.DecrementFixupsRemaining(this); holder1.RemoveDependency(holder.m_id); } } } } this.m_fixupCount = this.m_fixupCount - (long)num; if (fixupHolderList.m_count != num) { return; } holder.m_missingElements = (FixupHolderList)null; }
private bool DoValueTypeFixup(FieldInfo memberToFix, ObjectHolder holder, object value) { FieldInfo[] fieldInfoArray1 = new FieldInfo[4]; int length = 0; int[] numArray = (int[])null; object objectValue = holder.ObjectValue; while (holder.RequiresValueTypeFixup) { if (length + 1 >= fieldInfoArray1.Length) { FieldInfo[] fieldInfoArray2 = new FieldInfo[fieldInfoArray1.Length * 2]; Array.Copy((Array)fieldInfoArray1, (Array)fieldInfoArray2, fieldInfoArray1.Length); fieldInfoArray1 = fieldInfoArray2; } ValueTypeFixupInfo valueFixup = holder.ValueFixup; objectValue = holder.ObjectValue; if (valueFixup.ParentField != (FieldInfo)null) { FieldInfo parentField = valueFixup.ParentField; ObjectHolder objectHolder = this.FindObjectHolder(valueFixup.ContainerID); if (objectHolder.ObjectValue != null) { if (Nullable.GetUnderlyingType(parentField.FieldType) != (Type)null) { fieldInfoArray1[length] = parentField.FieldType.GetField("value", BindingFlags.Instance | BindingFlags.NonPublic); ++length; } fieldInfoArray1[length] = parentField; holder = objectHolder; ++length; } else { break; } } else { holder = this.FindObjectHolder(valueFixup.ContainerID); numArray = valueFixup.ParentIndex; if (holder.ObjectValue != null) { break; } break; } } if (!(holder.ObjectValue is Array) && holder.ObjectValue != null) { objectValue = holder.ObjectValue; } if (length != 0) { FieldInfo[] flds = new FieldInfo[length]; for (int index = 0; index < length; ++index) { FieldInfo fieldInfo = fieldInfoArray1[length - 1 - index]; SerializationFieldInfo serializationFieldInfo = fieldInfo as SerializationFieldInfo; flds[index] = (FieldInfo)serializationFieldInfo == (FieldInfo)null ? fieldInfo : (FieldInfo)serializationFieldInfo.FieldInfo; } TypedReference target = TypedReference.MakeTypedReference(objectValue, flds); if (memberToFix != (FieldInfo)null) { memberToFix.SetValueDirect(target, value); } else { TypedReference.SetTypedReference(target, value); } } else if (memberToFix != (FieldInfo)null) { FormatterServices.SerializationSetValue((MemberInfo)memberToFix, objectValue, value); } if (numArray != null && holder.ObjectValue != null) { ((Array)holder.ObjectValue).SetValue(objectValue, numArray); } return(true); }