Esempio n. 1
1
 // 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));
 }
        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;
        }
		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
		}
        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));
        }
        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);
        }
Esempio n. 6
0
 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));
 }
		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));
		}
 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));
 }
		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;
		}
        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));
        }
        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[]));
        }
Esempio n. 12
0
 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);
 }
Esempio n. 13
0
 /// <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);
 }
 public void GetObjectData(object obj, SerializationInfo info, StreamingContext ctx)
 {
     if (!obj.GetType().IsCOMObject)
     {
         throw new NotSupportedException();
     }
     info.SetType(typeof(ComObjRef));
     info.AddValue("buffer", ComponentServices.GetDCOMBuffer(obj));
 }
        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));
        }
 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));
 }
		public static void Serialize(SerializationInfo info, String name, Type klass, String signature, MemberTypes type, Type[] genericArguments)
		{
			info.SetType( typeof(MemberInfoSerializationHolder));

			info.AddValue("AssemblyName", klass.Module.Assembly.FullName, typeof(String));
			info.AddValue("ClassName", klass.FullName, typeof(String));

			info.AddValue("Name", name, typeof(String));
			info.AddValue("Signature", signature, typeof(String));
			info.AddValue("MemberType",(int)type);
			info.AddValue("GenericArguments", genericArguments, typeof (Type[]));
		}
	// Serialize a unity object.
	public static void Serialize(SerializationInfo info,
								 MemberTypes memberType,
								 String name, String signature,
								 Type containingType)
			{
				info.SetType(typeof(MemberInfoSerializationHolder));
				info.AddValue("Name", name);
				info.AddValue("AssemblyName", containingType.Assembly.FullName);
				info.AddValue("ClassName", containingType.FullName);
				info.AddValue("Signature", signature);
				info.AddValue("MemberType", (int)memberType);
			}
        [System.Security.SecurityCritical]  // auto-generated
        internal static DelegateEntry GetDelegateSerializationInfo(
            SerializationInfo info, Type delegateType, Object target, MethodInfo method, int targetIndex)
        {
            // Used for MulticastDelegate

            if (method == null) 
                throw new ArgumentNullException("method");
            Contract.EndContractBlock();
    
            if (!method.IsPublic || (method.DeclaringType != null && !method.DeclaringType.IsVisible))
                new ReflectionPermission(ReflectionPermissionFlag.MemberAccess).Demand();
    
            Type c = delegateType.BaseType;

            if (c == null || (c != typeof(Delegate) && c != typeof(MulticastDelegate)))
                throw new ArgumentException(Environment.GetResourceString("Arg_MustBeDelegate"),"type");

            if (method.DeclaringType == null)
                throw new NotSupportedException(Environment.GetResourceString("NotSupported_GlobalMethodSerialization"));

            DelegateEntry de = new 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",de,typeof(DelegateEntry));
            }

            // target can be an object so it needs to be added to the info, or else a fixup is needed
            // when deserializing, and the fixup will occur too late. If it is added directly to the
            // info then the rules of deserialization will guarantee that it will be available when
            // needed

            if (target != null)
            {
                String targetName = "target" + targetIndex;
                info.AddValue(targetName, de.target);
                de.target = targetName;
            }

            // Due to a number of additions (delegate signature binding relaxation, delegates with open this or closed over the
            // first parameter and delegates over generic methods) we need to send a deal more information than previously. We can
            // get this by serializing the target MethodInfo. We still need to send the same information as before though (the
            // DelegateEntry above) for backwards compatibility. And we want to send the MethodInfo (which is serialized via an
            // ISerializable holder) as a top-level child of the info for the same reason as the target above -- we wouldn't have an
            // order of deserialization guarantee otherwise.
            String methodInfoName = "method" + targetIndex;
            info.AddValue(methodInfoName, method);

            return de;
        }
        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            ISerializable s = (ISerializable)_t;

            info.AddValue("UnityType", 4);
            info.AddValue("Data", _t.FullName);

            AssemblyName name = _t.Assembly.GetName();
            name.Version = new Version(_version, 0, 0, 0);
            info.AddValue("AssemblyName", name.ToString());

            info.SetType(Type.GetType("System.UnitySerializationHolder"));
        }
 void ISerializationSurrogate.GetObjectData(object obj, SerializationInfo info, StreamingContext context)
 {
     object[] objArray = ((Queue) obj).ToArray();
     if (objArray.Length == 1)
     {
         info.AddValue("item", objArray[0]);
     }
     else
     {
         info.AddValue("items", objArray);
     }
     info.SetType(typeof(QRef));
 }
 internal void CompleteSerialization(object serializedObject, SerializationInfo info, StreamingContext context)
 {
     this.m_serializedStates = null;
     EventHandler<SafeSerializationEventArgs> serializeObjectState = this.SerializeObjectState;
     if (serializeObjectState != null)
     {
         SafeSerializationEventArgs e = new SafeSerializationEventArgs(context);
         serializeObjectState(serializedObject, e);
         this.m_serializedStates = e.SerializedStates;
         info.AddValue("CLR_SafeSerializationManager_RealType", serializedObject.GetType(), typeof(RuntimeType));
         info.SetType(typeof(SafeSerializationManager));
     }
 }
Esempio n. 23
0
            void ISerializationSurrogate.GetObjectData(object obj, SerializationInfo info, StreamingContext context)
            {
                var aac = (AdjustableArrowCap) obj;
                info.SetType(typeof(AdjustableArrowCapRef));
                info.AddValue("Width", aac.Width);
                info.AddValue("Height", aac.Height);

                info.AddValue("BaseCap", (int)aac.BaseCap);
                info.AddValue("BaseInset", aac.BaseInset);
                info.AddValue("Filled", aac.Filled);
                info.AddValue("MiddleInset", aac.MiddleInset);
                info.AddValue("StrokeJoin", (int)aac.StrokeJoin);
                info.AddValue("WidthScale", aac.WidthScale);
            }
	// Serialize a unity object.
	public static void Serialize(SerializationInfo info, UnityType type,
								 String data, Assembly assembly)
			{
				info.SetType(typeof(UnitySerializationHolder));
				info.AddValue("data", data);
				info.AddValue("UnityType", (int)type);
				if(assembly != null)
				{
					info.AddValue("AssemblyName", assembly.FullName);
				}
				else
				{
					info.AddValue("AssemblyName", String.Empty);
				}
			}
Esempio n. 25
0
 public static void SerializeObject(object obj, SerializationInfo info, StreamingContext context)
 {
     Type t = obj.GetType();
     info.SetType(typeof(DynamicObjectReference));
     info.AddValue("#", t);
     foreach (FieldInfo fi in t.GetFields(ClassHelper.InstanceFlag))
     {
         info.AddValue(fi.Name, fi.GetValue(obj));
     }
     if(obj is DbObjectSmartUpdate) // should be DbObjectModel<T, TKey>
     {
         var pi = t.GetProperty("Id");
         info.AddValue(pi.Name, pi.GetValue(obj, new object[]{}));
     }
 }
        /// <summary>
        /// Populates the provided <see cref="T:System.Runtime.Serialization.SerializationInfo"/> with the data needed to serialize the object.
        /// </summary>
        /// <param name="obj">The object to serialize. 
        ///                 </param><param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo"/> to populate with data. 
        ///                 </param><param name="context">The destination (see <see cref="T:System.Runtime.Serialization.StreamingContext"/>) for this serialization. 
        ///                 </param><exception cref="T:System.Security.SecurityException">The caller does not have the required permission. 
        ///                 </exception>
        public virtual void GetObjectData(object obj, SerializationInfo info, StreamingContext context)
        {
            var session = context.Context as ISerializationSession;
            if(session == null)
                throw new ArgumentException("context does not contain an instance of IInternalSession");

            var internalId = session.InternalIdOfTrackedGraph(obj);

            if(internalId == null)
                throw new InvalidOperationException(
                    string.Format("Graph of type {0} ({1}) is not tracked and therefore cannot be serialised as a reference", obj.GetType(), obj));

            info.SetType(typeof(AggregateProxy));
            info.AddValue(ReferenceInfoKey, internalId);
        }
        public static void GetSerializationInfo (SerializationInfo info, String name, Type reflectedClass, String signature, MemberTypes type) {
            if (info==null) {
                throw new ArgumentNullException("info");
            }

            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("MemberType",(int)type);
        }
Esempio n. 28
0
        // A helper method that returns the SerializationInfo that a class utilizing 
        // UnitySerializationHelper should return from a call to GetObjectData.  It contains
        // the unityType (defined above) and any optional data (used only for the reflection
        // types.)
        internal static void GetUnitySerializationInfo(SerializationInfo info, int unityType, String data, Assembly assem) {
            BCLDebug.Trace("SER", "UnitySerializationHolder: Adding [" , data , "] with type: ", unityType);
            BCLDebug.Assert(info!=null, "[UnitySerializationHolder.GetUnitySerializationInfo]info!=null");
            info.SetType(typeof(UnitySerializationHolder));
            info.AddValue("Data", data, typeof(String));
            info.AddValue("UnityType", unityType);

            String assemName;
            if (assem==null) {
                assemName = String.Empty;
            } else {
                assemName = assem.FullName;
            }

            info.AddValue("AssemblyName", assemName);
        }
Esempio n. 29
0
        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            if (context.State != StreamingContextStates.CrossAppDomain)
            {
                throw new InvalidOperationException("Serialization not supported");
            }

            var identity = new GenericIdentity(Name, AuthenticationType);
            info.SetType(identity.GetType());

            MemberInfo[] members = FormatterServices.GetSerializableMembers(identity.GetType());
            object[] values = FormatterServices.GetObjectData(identity, members);
            for (int i = 0; i < members.Length; i++)
            {
                info.AddValue(members[i].Name, values[i]);
            }
        }
        void ISerializationSurrogate.GetObjectData(object obj, SerializationInfo info, StreamingContext context)
        {
            if (!obj.GetType().IsGenericType || obj.GetType().GetGenericTypeDefinition() != typeof(Queue<>))
                throw new ArgumentException(SR.GetString(SR.Error_InvalidArgumentValue), "obj");

            Type[] args = obj.GetType().GetGenericArguments();
            if (args.Length != 1)
                throw new ArgumentException(SR.GetString(SR.Error_InvalidArgumentValue), "obj");

            ArrayList items = new ArrayList(obj as ICollection);
            if (items.Count == 1)
                info.AddValue("item", items[0]);
            else
                info.AddValue("items", items.ToArray());
            info.AddValue("itemType", args[0]);
            info.SetType(typeof(GenericQRef));
        }
Esempio n. 31
0
 /// <summary>
 /// Sets the SerializationInfo with information about the exception.
 /// </summary>
 /// <param name="info"> The SerializationInfo that holds the serialized object data about
 /// the exception being thrown. </param>
 /// <param name="context"> The StreamingContext that contains contextual information about
 /// the source or destination. </param>
 public void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
 {
     // Save the object state.
     info.SetType(typeof(SerializationHelper));
 }
Esempio n. 32
0
 public override void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
 {
     info.SetType(typeof(DisplayDefaultSerializationHelper));
 }