本文整理汇总了C#中ISerializable.GetObjectData方法的典型用法代码示例。如果您正苦于以下问题:C# ISerializable.GetObjectData方法的具体用法?C# ISerializable.GetObjectData怎么用?C# ISerializable.GetObjectData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISerializable
的用法示例。
在下文中一共展示了ISerializable.GetObjectData方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SNKeyPairDerivedClone
public SNKeyPairDerived SNKeyPairDerivedClone(ISerializable inter)
{
SerializationInfo info = new SerializationInfo(typeof(StrongNameKeyPair), new FormatterConverter());
StreamingContext context = new StreamingContext();
inter.GetObjectData(info, context);
return new SNKeyPairDerived(info, context);
}
示例2: SurrogateForISerializable
public SurrogateForISerializable(ISerializable serializable)
{
var serializationInfo = new SerializationInfo(serializable.GetType(), new FormatterConverter());
var streamingContext = new StreamingContext(StreamingContextStates.Clone);
serializable.GetObjectData(serializationInfo, streamingContext);
keys = new string[serializationInfo.MemberCount];
values = new object[serializationInfo.MemberCount];
var i = 0;
foreach(var entry in serializationInfo)
{
keys[i] = entry.Name;
values[i] = entry.Value;
i++;
}
assemblyQualifiedName = serializable.GetType().AssemblyQualifiedName;
}
示例3: SerializeISerializable
private void SerializeISerializable(JsonWriter writer, ISerializable value, JsonISerializableContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
{
if (!JsonTypeReflector.FullyTrusted)
{
throw JsonSerializationException.Create(null, writer.ContainerPath, @"Type '{0}' implements ISerializable but cannot be serialized using the ISerializable interface because the current application is not fully trusted and ISerializable can expose secure data.
To fix this error either change the environment to be fully trusted, change the application to not deserialize the type, add JsonObjectAttribute to the type or change the JsonSerializer setting ContractResolver to use a new DefaultContractResolver with IgnoreSerializableInterface set to true.".FormatWith(CultureInfo.InvariantCulture, value.GetType()), null);
}
contract.InvokeOnSerializing(value, Serializer.Context);
_serializeStack.Add(value);
WriteObjectStart(writer, value, contract, member, collectionContract, containerProperty);
SerializationInfo serializationInfo = new SerializationInfo(contract.UnderlyingType, new FormatterConverter());
value.GetObjectData(serializationInfo, Serializer.Context);
foreach (SerializationEntry serializationEntry in serializationInfo)
{
writer.WritePropertyName(serializationEntry.Name);
SerializeValue(writer, serializationEntry.Value, GetContractSafe(serializationEntry.Value), null, null, member);
}
writer.WriteEndObject();
_serializeStack.RemoveAt(_serializeStack.Count - 1);
contract.InvokeOnSerialized(value, Serializer.Context);
}
示例4: GetMembers
static IObjectMemberInfo[] GetMembers(ISerializable value, Type type)
{
IObjectMemberInfo[] mis = null;
if (value == null)
{
if (serialCache.TryGetValue(type, out mis)) return mis;
// 尝试创建type的实例
value = GetDefaultObject(type) as ISerializable;
}
SerializationInfo info = new SerializationInfo(type, new FormatterConverter());
value.GetObjectData(info, DefaultStreamingContext);
List<IObjectMemberInfo> list = new List<IObjectMemberInfo>();
foreach (SerializationEntry item in info)
{
list.Add(CreateObjectMemberInfo(item.Name, item.ObjectType, item.Value));
}
mis = list.ToArray();
if (!serialCache.ContainsKey(type))
{
lock (serialCache)
{
if (!serialCache.ContainsKey(type)) serialCache.Add(type, mis);
}
}
return mis;
}
示例5: SerializeISerializable
private void SerializeISerializable(JsonWriter writer, ISerializable value, JsonISerializableContract contract)
{
contract.InvokeOnSerializing(value, Serializer.Context);
SerializeStack.Add(value);
writer.WriteStartObject();
SerializationInfo serializationInfo = new SerializationInfo(contract.UnderlyingType, new FormatterConverter());
value.GetObjectData(serializationInfo, Serializer.Context);
foreach (SerializationEntry serializationEntry in serializationInfo)
{
writer.WritePropertyName(serializationEntry.Name);
SerializeValue(writer, serializationEntry.Value, GetContractSafe(serializationEntry.Value), null, null);
}
writer.WriteEndObject();
SerializeStack.RemoveAt(SerializeStack.Count - 1);
contract.InvokeOnSerialized(value, Serializer.Context);
}
示例6: TryGetKeyContainer
static bool TryGetKeyContainer(ISerializable key_pair, out byte [] key, out string key_container)
{
var info = new SerializationInfo (typeof (StrongNameKeyPair), new FormatterConverter ());
key_pair.GetObjectData (info, new StreamingContext ());
key = (byte []) info.GetValue ("_keyPairArray", typeof (byte []));
key_container = info.GetString ("_keyPairContainer");
return key_container != null;
}
示例7: serializeFromISerializable
private void serializeFromISerializable(ISerializable data)
{
m_CustomData = new Dictionary<string,CustomTypedEntry>();
var info = new SerializationInfo(data.GetType(), new FormatterConverter());
StreamingContext streamingContext = new StreamingContext(StreamingContextStates.Persistence);
data.GetObjectData(info, streamingContext);
var senum = info.GetEnumerator();
while(senum.MoveNext())
{
var value = new CustomTypedEntry();
value.TypeIndex = MetaType.GetExistingOrNewMetaTypeIndex( m_Document, senum.ObjectType );
value.Data = m_Document.NativeDataToPortableData( senum.Value );
m_CustomData[senum.Name] = value;
}
}
示例8: WriteJsonISerializable
internal void WriteJsonISerializable(XmlWriterDelegator xmlWriter, ISerializable obj)
{
Type type = obj.GetType();
SerializationInfo info = new SerializationInfo(type, XmlObjectSerializer.FormatterConverter);
obj.GetObjectData(info, base.GetStreamingContext());
if (DataContract.GetClrTypeFullName(type) != info.FullTypeName)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(System.Runtime.Serialization.SR.GetString("ChangingFullTypeNameNotSupported", new object[] { info.FullTypeName, DataContract.GetClrTypeFullName(type) })));
}
base.WriteSerializationInfo(xmlWriter, type, info);
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:11,代码来源:XmlObjectSerializerWriteContextComplexJson.cs
示例9: SerializeISerializable
// Token: 0x06000C07 RID: 3079
// RVA: 0x00047744 File Offset: 0x00045944
private void SerializeISerializable(JsonWriter writer, ISerializable value, JsonISerializableContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
{
if (!JsonTypeReflector.FullyTrusted)
{
string text = "Type '{0}' implements ISerializable but cannot be serialized using the ISerializable interface because the current application is not fully trusted and ISerializable can expose secure data." + Environment.NewLine + "To fix this error either change the environment to be fully trusted, change the application to not deserialize the type, add JsonObjectAttribute to the type or change the JsonSerializer setting ContractResolver to use a new DefaultContractResolver with IgnoreSerializableInterface set to true." + Environment.NewLine;
text = StringUtils.FormatWith(text, CultureInfo.InvariantCulture, value.GetType());
throw JsonSerializationException.Create(null, writer.ContainerPath, text, null);
}
this.OnSerializing(writer, contract, value);
this._serializeStack.Add(value);
this.WriteObjectStart(writer, value, contract, member, collectionContract, containerProperty);
SerializationInfo serializationInfo = new SerializationInfo(contract.UnderlyingType, new FormatterConverter());
value.GetObjectData(serializationInfo, this.Serializer._context);
SerializationInfoEnumerator enumerator = serializationInfo.GetEnumerator();
while (enumerator.MoveNext())
{
SerializationEntry current = enumerator.Current;
JsonContract contractSafe = this.GetContractSafe(current.Value);
if (this.ShouldWriteReference(current.Value, null, contractSafe, contract, member))
{
writer.WritePropertyName(current.Name);
this.WriteReference(writer, current.Value);
}
else if (this.CheckForCircularReference(writer, current.Value, null, contractSafe, contract, member))
{
writer.WritePropertyName(current.Name);
this.SerializeValue(writer, current.Value, contractSafe, null, contract, member);
}
}
writer.WriteEndObject();
this._serializeStack.RemoveAt(this._serializeStack.Count - 1);
this.OnSerialized(writer, contract, value);
}