本文整理汇总了C#中System.Runtime.Serialization.SerializationInfo.SetType方法的典型用法代码示例。如果您正苦于以下问题:C# SerializationInfo.SetType方法的具体用法?C# SerializationInfo.SetType怎么用?C# SerializationInfo.SetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Runtime.Serialization.SerializationInfo
的用法示例。
在下文中一共展示了SerializationInfo.SetType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SerializeEncoder
// ISerializable implementation. called during serialization.
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
{
SerializeEncoder(info);
info.AddValue("encoding", this.m_encoding);
info.AddValue("charLeftOver", this.charLeftOver);
info.SetType(typeof(Encoding.DefaultEncoder));
}
示例2: Restore
public object Restore()
{
var type = Type.GetType(assemblyQualifiedName);
var ctor = type.GetConstructor(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, new [] {
typeof(SerializationInfo),
typeof(StreamingContext)
}, null);
var serializationInfo = new SerializationInfo(type, new FormatterConverter());
serializationInfo.SetType(type);
for(var i = 0; i < keys.Length; i++)
{
serializationInfo.AddValue(keys[i], values[i]);
}
var streamingContext = new StreamingContext(StreamingContextStates.Clone);
var result = ctor.Invoke(new object[] { serializationInfo, streamingContext });
var onDeserialization = result as IDeserializationCallback;
if(onDeserialization != null)
{
onDeserialization.OnDeserialization(this);
}
return result;
}
示例3: SetType
public void SetType ()
{
SerializationInfo sinfo = new SerializationInfo (typeof (DateTime), new FormatterConverter ());
Type point_type = typeof (Point);
sinfo.SetType (point_type);
Assert.AreEqual (point_type.FullName, sinfo.FullTypeName, "#A0");
Assert.AreEqual (point_type.Assembly.FullName, sinfo.AssemblyName, "#A1");
#if NET_4_0
Assert.AreEqual (point_type, sinfo.ObjectType, "#A2");
Assert.AreEqual (false, sinfo.IsAssemblyNameSetExplicit, "#A3");
Assert.AreEqual (false, sinfo.IsFullTypeNameSetExplicit, "#A4");
sinfo.FullTypeName = "Point2";
sinfo.AssemblyName = "NewAssembly";
Type datetime_type = typeof (DateTime);
sinfo.SetType (datetime_type);
Assert.AreEqual (datetime_type.FullName, sinfo.FullTypeName, "#B0");
Assert.AreEqual (datetime_type.Assembly.FullName, sinfo.AssemblyName, "#B1");
Assert.AreEqual (datetime_type, sinfo.ObjectType, "#B2");
Assert.AreEqual (false, sinfo.IsAssemblyNameSetExplicit, "#B3");
Assert.AreEqual (false, sinfo.IsFullTypeNameSetExplicit, "#B4");
#endif
}
示例4: ArgumentException
void ISerializationSurrogate.GetObjectData(object obj, SerializationInfo info, StreamingContext context)
{
IDictionary<DependencyProperty, object> store = obj as IDictionary<DependencyProperty, object>;
if (store == null)
throw new ArgumentException("obj");
ArrayList properties = new ArrayList();
ArrayList values = new ArrayList();
foreach (KeyValuePair<DependencyProperty, object> kvp in store)
{
if (!kvp.Key.DefaultMetadata.IsNonSerialized)
{
if (kvp.Key.IsKnown)
properties.Add(kvp.Key.KnownIndex);
else
properties.Add(kvp.Key);
values.Add(kvp.Value);
}
}
info.AddValue("keys", properties.ToArray());
info.AddValue("values", values.ToArray());
info.SetType(typeof(DependencyStoreRef));
}
示例5: GetDelegateSerializationInfo
internal static DelegateSerializationHolder.DelegateEntry GetDelegateSerializationInfo(SerializationInfo info, Type delegateType, object target, MethodInfo method, int targetIndex)
{
if (method == null)
{
throw new ArgumentNullException("method");
}
if (!method.IsPublic || (method.DeclaringType != null && !method.DeclaringType.IsVisible))
{
new ReflectionPermission(ReflectionPermissionFlag.MemberAccess).Demand();
}
Type baseType = delegateType.BaseType;
if (baseType == null || (baseType != typeof(Delegate) && baseType != typeof(MulticastDelegate)))
{
throw new ArgumentException(Environment.GetResourceString("Arg_MustBeDelegate"), "type");
}
if (method.DeclaringType == null)
{
throw new NotSupportedException(Environment.GetResourceString("NotSupported_GlobalMethodSerialization"));
}
DelegateSerializationHolder.DelegateEntry delegateEntry = new DelegateSerializationHolder.DelegateEntry(delegateType.FullName, delegateType.Module.Assembly.FullName, target, method.ReflectedType.Module.Assembly.FullName, method.ReflectedType.FullName, method.Name);
if (info.MemberCount == 0)
{
info.SetType(typeof(DelegateSerializationHolder));
info.AddValue("Delegate", delegateEntry, typeof(DelegateSerializationHolder.DelegateEntry));
}
if (target != null)
{
string text = "target" + targetIndex;
info.AddValue(text, delegateEntry.target);
delegateEntry.target = text;
}
string name = "method" + targetIndex;
info.AddValue(name, method);
return delegateEntry;
}
示例6:
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue(EncoderNLSSurrogate.EncodingKey, m_encoding);
info.AddValue(EncoderNLSSurrogate.DecoderFallbackKey, m_fallback);
info.AddValue(EncoderNLSSurrogate.CharLeftOverKey, charLeftOver);
info.SetType(typeof(EncoderNLSSurrogate));
}
示例7: GetSerializationInfo
public static void GetSerializationInfo(
SerializationInfo info,
String name,
RuntimeType reflectedClass,
String signature,
String signature2,
MemberTypes type,
Type[] genericArguments)
{
if (info == null)
throw new ArgumentNullException(nameof(info));
Contract.EndContractBlock();
String assemblyName = reflectedClass.Module.Assembly.FullName;
String typeName = reflectedClass.FullName;
info.SetType(typeof(MemberInfoSerializationHolder));
info.AddValue("Name", name, typeof(String));
info.AddValue("AssemblyName", assemblyName, typeof(String));
info.AddValue("ClassName", typeName, typeof(String));
info.AddValue("Signature", signature, typeof(String));
info.AddValue("Signature2", signature2, typeof(String));
info.AddValue("MemberType", (int)type);
info.AddValue("GenericArguments", genericArguments, typeof(Type[]));
}
示例8: GetAssemblyData
public static void GetAssemblyData (Assembly instance, SerializationInfo info, StreamingContext ctx)
{
info.AddValue ("Data", instance.FullName);
info.AddValue ("UnityType", (int) UnityType.Assembly);
info.AddValue ("AssemblyName", instance.FullName);
info.SetType (typeof (UnitySerializationHolder));
}
示例9: GetSerializationInfo
private void GetSerializationInfo(SerializationInfo info, string name, Type reflectedClass, string signature, MemberTypes type, Type[] genericArguments)
{
if (info == null)
{
throw new ArgumentNullException("info");
}
AssemblyName asmname = reflectedClass.Assembly.GetName();
asmname.Version = new Version(_version, 0, 0, 0);
string fullName = asmname.ToString();
string str2 = reflectedClass.FullName;
Type t = typeof(int).Assembly.GetType("System.Reflection.MemberInfoSerializationHolder");
info.SetType(t);
for (int i = 0; i < genericArguments.Length; ++i)
{
genericArguments[i] = new FakeType(genericArguments[i], _version);
}
// This is here to prevent a de-serialization bug
if (genericArguments.Length > 0)
{
info.AddValue("DUMMY", genericArguments[0]);
}
info.AddValue("GenericArguments", genericArguments, typeof(Type[]));
info.AddValue("Name", name, typeof(string));
info.AddValue("AssemblyName", fullName, typeof(string));
info.AddValue("ClassName", str2, typeof(string));
info.AddValue("Signature", signature, typeof(string));
info.AddValue("MemberType", (int)type);
}
示例10: ArgumentException
void ISerializationSurrogate.GetObjectData(object obj, SerializationInfo info, StreamingContext context)
{
if (!obj.GetType().IsGenericType || obj.GetType().GetGenericTypeDefinition() != typeof(Dictionary<,>))
throw new ArgumentException(SR.GetString(SR.Error_InvalidArgumentValue), "obj");
Type[] args = obj.GetType().GetGenericArguments();
if (args.Length != 2)
throw new ArgumentException(SR.GetString(SR.Error_InvalidArgumentValue), "obj");
PropertyInfo keysProperty = obj.GetType().GetProperty("Keys");
if (keysProperty == null)
throw new NullReferenceException("keysProperty");
ArrayList keys = new ArrayList(keysProperty.GetValue(obj, null) as ICollection);
PropertyInfo valuesProperty = obj.GetType().GetProperty("Values");
if (valuesProperty == null)
throw new NullReferenceException("valuesProperty");
ArrayList values = new ArrayList(valuesProperty.GetValue(obj, null) as ICollection);
if (keys.Count == 1)
{
info.AddValue("key", keys[0]);
info.AddValue("value", values[0]);
}
else if (keys.Count > 1)
{
info.AddValue("keys", keys.ToArray());
info.AddValue("values", values.ToArray());
}
info.AddValue("keyType", args[0]);
info.AddValue("valueType", args[1]);
info.SetType(typeof(DictionaryRef));
}
示例11: GetObjectData
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
// WOS 127340: Request.Headers and Response.Headers are no longer serializable
base.GetObjectData(info, context);
// create an instance of HttpValueCollection since HttpHeaderCollection is tied to the request
info.SetType(typeof(HttpValueCollection));
}
示例12:
void ISerializationSurrogate.GetObjectData(object obj, SerializationInfo info, StreamingContext context)
{
var gp = (GraphicsPath)obj;
info.SetType(typeof(GraphicsPathRef));
info.AddValue("FillMode", (int)gp.FillMode);
info.AddValue("PathData", gp.PathPoints);
info.AddValue("PathTypes", gp.PathTypes);
}
示例13:
/// <summary>
/// Populates the provided SerializationInfo with the data needed to serialize the object.
/// </summary>
/// <param name="obj">The object to serialize.</param>
/// <param name="info">The SerializationInfo to populate with data.</param>
/// <param name="context">The destination for this serialization.</param>
void ISerializationSurrogate.GetObjectData(Object obj, SerializationInfo info, StreamingContext context)
{
var brush = (HatchBrush)obj;
info.SetType(typeof(HatchBrushRef));
info.AddValue("HatchStyle", brush.HatchStyle);
info.AddValue("ForegroundColor", brush.ForegroundColor);
info.AddValue("BackgroundColor", brush.BackgroundColor);
}
示例14:
void ISerializationSurrogate.GetObjectData(object obj, SerializationInfo info, StreamingContext context)
{
object[] items = ((Queue)obj).ToArray();
if (items.Length == 1)
info.AddValue("item", items[0]);
else
info.AddValue("items", items);
info.SetType(typeof(QRef));
}
示例15: ArgumentException
void ISerializationSurrogate.GetObjectData(object obj, SerializationInfo info, StreamingContext context)
{
XmlDocument doc = obj as XmlDocument;
if (doc == null)
throw new ArgumentException(SR.GetString(SR.Error_InvalidArgumentValue), "obj");
info.AddValue("innerXml", doc.InnerXml);
info.SetType(typeof(XmlDocumentReference));
}