當前位置: 首頁>>代碼示例>>C#>>正文


C# SerializationInfo.SetType方法代碼示例

本文整理匯總了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));
 }
開發者ID:kouvel,項目名稱:coreclr,代碼行數:8,代碼來源:EncoderNLS.cs

示例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;
        }
開發者ID:rogeralsing,項目名稱:Migrant,代碼行數:25,代碼來源:SurrogateForISerializable.cs

示例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
		}
開發者ID:KonajuGames,項目名稱:SharpLang,代碼行數:25,代碼來源:SerializationInfoTest.cs

示例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));
        }
開發者ID:krytht,項目名稱:DotNetReferenceSource,代碼行數:26,代碼來源:DependencyStoreSurrogate.cs

示例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;
		}
開發者ID:ChristianWulf,項目名稱:CSharpKDMDiscoverer,代碼行數:35,代碼來源:DelegateSerializationHolder.cs

示例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));
 }
開發者ID:naamunds,項目名稱:corefx,代碼行數:7,代碼來源:EncoderNLS.cs

示例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[]));
        }
開發者ID:kouvel,項目名稱:coreclr,代碼行數:25,代碼來源:MemberInfoSerializationHolder.cs

示例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));
		}
開發者ID:jack-pappas,項目名稱:mono,代碼行數:7,代碼來源:UnitySerializationHolder.cs

示例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);
        }
開發者ID:matthiaskaiser,項目名稱:ExploitRemotingService,代碼行數:35,代碼來源:FakeMethod.cs

示例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));
        }
開發者ID:iskiselev,項目名稱:JSIL.NetFramework,代碼行數:35,代碼來源:DictionarySurrogate.cs

示例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));
 }
開發者ID:Alister742,項目名稱:ParseKit,代碼行數:7,代碼來源:HttpHeaderCollection.cs

示例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);
 }
開發者ID:PedroMaitan,項目名稱:sharpmap,代碼行數:8,代碼來源:Surrogates.Helper.cs

示例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);
 }
開發者ID:geobabbler,項目名稱:SharpMap,代碼行數:14,代碼來源:Surrogates.Brushes.cs

示例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));
 }
開發者ID:krytht,項目名稱:DotNetReferenceSource,代碼行數:9,代碼來源:QueueSurrogate.cs

示例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));
        }
開發者ID:nlh774,項目名稱:DotNetReferenceSource,代碼行數:9,代碼來源:XmlDocumentSurrogate.cs


注:本文中的System.Runtime.Serialization.SerializationInfo.SetType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。