Ejemplo n.º 1
0
 public HandleNewReferenceMethodGenerator(Type type, SwapList objectsForSurrogates, bool disableStamping, bool treatCollectionAsUserObject, bool generatePreSerializationCallback, bool generatePostSerializationCallback)
     : base(type, "HandleNewReference", disableStamping, treatCollectionAsUserObject, OpCodes.Ldarg_0)
 {
     this.objectsForSurrogates              = objectsForSurrogates;
     this.generatePreSerializationCallback  = generatePreSerializationCallback;
     this.generatePostSerializationCallback = generatePostSerializationCallback;
 }
Ejemplo n.º 2
0
        public ObjectWriter(Stream stream, Serializer.WriteMethods writeMethods, Action <object> preSerializationCallback = null,
                            Action <object> postSerializationCallback   = null, SwapList surrogatesForObjects = null, SwapList objectsForSurrogates = null,
                            bool treatCollectionAsUserObject            = false, bool useBuffering = true, bool disableStamping = false,
                            ReferencePreservation referencePreservation = ReferencePreservation.Preserve)
        {
            this.treatCollectionAsUserObject = treatCollectionAsUserObject;
            this.objectsForSurrogates        = objectsForSurrogates;
            this.referencePreservation       = referencePreservation;
            this.preSerializationCallback    = preSerializationCallback;
            this.postSerializationCallback   = postSerializationCallback;
            this.writeMethods         = writeMethods;
            this.surrogatesForObjects = surrogatesForObjects ?? new SwapList();

            parentObjects          = new Dictionary <object, object>();
            postSerializationHooks = new List <Action>();
            types      = new IdentifiedElementsDictionary <TypeDescriptor>(this);
            Methods    = new IdentifiedElementsDictionary <MethodDescriptor>(this);
            Assemblies = new IdentifiedElementsDictionary <AssemblyDescriptor>(this);
            Modules    = new IdentifiedElementsDictionary <ModuleDescriptor>(this);
            writer     = new PrimitiveWriter(stream, useBuffering);
            if (referencePreservation == ReferencePreservation.Preserve)
            {
                identifier = new ObjectIdentifier();
            }
            touchTypeMethod      = disableStamping ? (Func <Type, int>)TouchAndWriteTypeIdWithSimpleStamp : TouchAndWriteTypeIdWithFullStamp;
            objectsWrittenInline = new HashSet <int>();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Serializer"/> class.
        /// </summary>
        /// <param name='settings'>
        /// Serializer's settings, can be null or not given, in that case default settings are
        /// used.
        /// </param>
        public Serializer(Settings settings = null)
        {
            if (settings == null)
            {
                settings = new Settings(); // default settings
            }
            this.settings = settings;

            objectsForSurrogates = new SwapList();
            surrogatesForObjects = new SwapList();
            recipes = new Dictionary <Type, Recipe>();

            if (settings.SupportForIXmlSerializable)
            {
                ForObject <System.Xml.Serialization.IXmlSerializable>().SetSurrogate(x => new SurrogateForIXmlSerializable(x));
                ForSurrogate <SurrogateForIXmlSerializable>().SetObject(x => x.Restore());
            }

            ForObject(typeof(ReadOnlyCollection <>)).SetSurrogateGenericType(typeof(SurrogateForReadOnlyCollection <>));
            ForSurrogate(typeof(SurrogateForReadOnlyCollection <>)).SetObject(x => ((ISurrogateRestorer)x).Restore());

            AddRecipeFor(
                (regex, writer) =>
            {
                writer.Write(regex.ToString());
                writer.Write((long)regex.Options);
                writer.Write(regex.MatchTimeout);
            },
                reader => new Regex(reader.ReadString(), (RegexOptions)reader.ReadInt64(), reader.ReadTimeSpan())
                );
        }
Ejemplo n.º 4
0
        public ObjectReader(Stream stream,
                            Serializer.ReadMethods readMethods,
                            SwapList objectsForSurrogates,
                            IDictionary <Type, Recipe> recipes,
                            Action <object> postDeserializationCallback,
                            bool treatCollectionAsUserObject,
                            VersionToleranceLevel versionToleranceLevel,
                            bool useBuffering,
                            bool disableStamping,
                            ReferencePreservation referencePreservation,
                            bool forceStampVerification)
        {
            this.readMethods = readMethods;
            this.postDeserializationCallback = postDeserializationCallback;
            this.treatCollectionAsUserObject = treatCollectionAsUserObject;
            this.referencePreservation       = referencePreservation;
            this.objectsForSurrogates        = objectsForSurrogates;
            this.recipes = recipes;

            VersionToleranceLevel = versionToleranceLevel;
            types      = new List <TypeDescriptor>();
            Methods    = new IdentifiedElementsList <MethodDescriptor>(this);
            Assemblies = new IdentifiedElementsList <AssemblyDescriptor>(this);
            Modules    = new IdentifiedElementsList <ModuleDescriptor>(this);
            HashCodeBasedWaitingValues   = new Dictionary <int, (object Dictionary, object Value)>();
            latePostDeserializationHooks = new List <Action>();

            reader = new PrimitiveReader(stream, useBuffering);
            surrogatesWhileReading = new OneToOneMap <int, object>();

            readTypeMethod         = disableStamping ? (Func <TypeDescriptor>)ReadSimpleTypeDescriptor : ReadFullTypeDescriptor;
            ForceStampVerification = forceStampVerification;
        }
        public ObjectReader(Stream stream, Serializer.ReadMethods readMethods, SwapList objectsForSurrogates = null, Action <object> postDeserializationCallback = null,
                            bool treatCollectionAsUserObject            = false,
                            VersionToleranceLevel versionToleranceLevel = 0, bool useBuffering = true, bool disableStamping = false,
                            ReferencePreservation referencePreservation = ReferencePreservation.Preserve,
                            bool forceStampVerification = false)
        {
            this.readMethods = readMethods;
            this.postDeserializationCallback = postDeserializationCallback;
            this.treatCollectionAsUserObject = treatCollectionAsUserObject;
            this.referencePreservation       = referencePreservation;
            this.objectsForSurrogates        = objectsForSurrogates ?? new SwapList();

            VersionToleranceLevel = versionToleranceLevel;
            types      = new List <TypeDescriptor>();
            Methods    = new IdentifiedElementsList <MethodDescriptor>(this);
            Assemblies = new IdentifiedElementsList <AssemblyDescriptor>(this);
            Modules    = new IdentifiedElementsList <ModuleDescriptor>(this);
            latePostDeserializationHooks = new List <Action>();

            reader = new PrimitiveReader(stream, useBuffering);
            surrogatesWhileReading = new OneToOneMap <int, object>();

            readTypeMethod         = disableStamping ? (Func <TypeDescriptor>)ReadSimpleTypeDescriptor : ReadFullTypeDescriptor;
            ForceStampVerification = forceStampVerification;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Antmicro.Migrant.Serializer"/> class.
        /// </summary>
        /// <param name='settings'>
        /// Serializer's settings, can be null or not given, in that case default settings are
        /// used.
        /// </param>
        public Serializer(Settings settings = null)
        {
            if (settings == null)
            {
                settings = new Settings(); // default settings
            }
            this.settings = settings;

            objectsForSurrogates = new SwapList();
            surrogatesForObjects = new SwapList();

            if (settings.SupportForISerializable)
            {
                ForObject <System.Runtime.Serialization.ISerializable>().SetSurrogate(x => new SurrogateForISerializable(x));
                ForSurrogate <SurrogateForISerializable>().SetObject(x => x.Restore());
                ForObject <Delegate>().SetSurrogate <Func <Delegate, object> >(null); //because Delegate implements ISerializable but we support it directly.
            }

            if (settings.SupportForIXmlSerializable)
            {
                ForObject <System.Xml.Serialization.IXmlSerializable>().SetSurrogate(x => new SurrogateForIXmlSerializable(x));
                ForSurrogate <SurrogateForIXmlSerializable>().SetObject(x => x.Restore());
            }

            ForObject(typeof(Hashtable)).SetSurrogate(x => new SurrogateForHashtable((Hashtable)x));
            ForSurrogate <SurrogateForHashtable>().SetObject(x => x.Restore());

            ForObject(typeof(ReadOnlyCollection <>)).SetSurrogateGenericType(typeof(SurrogateForReadOnlyCollection <>));
            ForSurrogate(typeof(SurrogateForReadOnlyCollection <>)).SetObject(x => ((ISurrogateRestorer)x).Restore());

            ForObject(typeof(Dictionary <,>)).SetSurrogateGenericType(typeof(SurrogateForDictionary <,>));
            ForSurrogate(typeof(SurrogateForDictionary <,>)).SetObject(x => ((ISurrogateRestorer)x).Restore());

            ForObject(typeof(HashSet <>)).SetSurrogateGenericType(typeof(SurrogateForHashSet <>));
            ForSurrogate(typeof(SurrogateForHashSet <>)).SetObject(x => ((ISurrogateRestorer)x).Restore());
        }
Ejemplo n.º 7
0
 public CompletedGenerator(Type type, SwapList objectsForSurrogates, bool disableStamping, bool treatCollectionAsUserObject, bool callPostDeserializationCallback)
     : base(type, "ObjectCompleted", disableStamping, treatCollectionAsUserObject, OpCodes.Ldarg_1, OpCodes.Ldarg_0)
 {
     this.objectsForSurrogates            = objectsForSurrogates;
     this.callPostDeserializationCallback = callPostDeserializationCallback;
 }
Ejemplo n.º 8
0
 public SurrogateObjectIfNeededMethodGenerator(Type type, SwapList surrogatesForObjects, bool disableStamping, bool treatCollectionAsUserObject)
     : base(type, "SurrogateObjectIfNeeded", disableStamping, treatCollectionAsUserObject, OpCodes.Ldarg_0)
 {
     this.surrogatesForObjects = surrogatesForObjects;
 }
 public static void Init()
 {
     _localizables = new SwapList <ILocalizer>(defaultCollectionSize);
 }