Beispiel #1
0
        private void WriteObjectString(
            XmlWriter writer, string property, object source, TypeSerializationInfo entry)
        {
            if (property != null)
            {
                WriteStartElement(writer, CustomSerializationStrings.Properties);
                WriteAttribute(writer, CustomSerializationStrings.NameAttribute, property);
            }
            else
            {
                if (_firstcall)
                {
                    WriteStartElement(writer, CustomSerializationStrings.PSObjectTag);
                    _firstcall = false;
                }
                else
                {
                    WriteStartElement(writer, CustomSerializationStrings.Properties);
                }
            }

            if (!_notypeinformation)
            {
                WriteAttribute(writer, CustomSerializationStrings.TypeAttribute, source.GetType().ToString());
            }

            writer.WriteString(source.ToString());
            writer.WriteEndElement();
        }
        private void HandlePSObjectAsString(PSObject source, string property, int depth)
        {
            Dbg.Assert(source != null, "caller should validate the information");

            bool   hasNotes = PSObjectHasNotes(source);
            string value    = GetStringFromPSObject(source);

            if (value != null)
            {
                TypeSerializationInfo pktInfo = KnownTypes.GetTypeSerializationInfo(value.GetType());
                Dbg.Assert(pktInfo != null, "TypeSerializationInfo should be present for string");
                if (hasNotes)
                {
                    WritePrimitiveTypePSObjectWithNotes(source, value, pktInfo, property, depth);
                }
                else
                {
                    WriteOnePrimitiveKnownType(_writer, property, source.BaseObject, pktInfo);
                }
            }
            else
            {
                if (hasNotes)
                {
                    WritePrimitiveTypePSObjectWithNotes(source, null, null, property, depth);
                }
                else
                {
                    WriteNull(property);
                }
            }
        }
        /// <summary>
        /// Serializes an PSObject whose baseobject is of primitive type.
        /// and which has notes.
        /// </summary>
        /// <param name="source">
        /// Source from which notes are written.
        /// </param>
        /// <param name="primitive">
        /// primitive object which is written as base object. In most cases it
        /// is same source.ImmediateBaseObject. When PSObject is serialized as string,
        /// it can be different. <see cref="HandlePSObjectAsString"/> for more info.
        /// </param>
        /// <param name="pktInfo">
        /// TypeSerializationInfo for the primitive.
        /// </param>
        /// <param name="property"></param>
        /// <param name="depth"></param>
        private void WritePrimitiveTypePSObjectWithNotes(
            PSObject source,
            object primitive,
            TypeSerializationInfo pktInfo,
            string property,
            int depth)
        {
            Dbg.Assert(source != null, "caller should validate the parameter");

            //Write start of PSObject. Since baseobject is primitive known
            //type, we do not need TypeName information.
            WriteStartOfPSObject(source, property, source.ToStringFromDeserialization != null);

            if (pktInfo != null)
            {
                WriteOnePrimitiveKnownType(_writer, null, primitive, pktInfo);
            }

            //Serialize instanceMembers
            PSMemberInfoCollection <PSMemberInfo> instanceMembers = source.InstanceMembers;

            if (instanceMembers != null)
            {
                WriteMemberInfoCollection(instanceMembers, depth, true);
            }

            _writer.WriteEndElement();
        }
Beispiel #4
0
        internal static TypeSerializationInfo GetTypeSerializationInfo(Type type)
        {
            TypeSerializationInfo xdInfo = (TypeSerializationInfo)KnownTypes._knownTableKeyType[(object)type.FullName];

            if (xdInfo == null && typeof(XmlDocument).IsAssignableFrom(type))
            {
                xdInfo = KnownTypes._xdInfo;
            }
            return(xdInfo);
        }
Beispiel #5
0
        internal static TypeSerializationInfo GetTypeSerializationInfo(Type type)
        {
            TypeSerializationInfo info = (TypeSerializationInfo)_knownTableKeyType[type.FullName];

            if ((info == null) && typeof(XmlDocument).IsAssignableFrom(type))
            {
                info = _xdInfo;
            }
            return(info);
        }
        private bool HandlePrimitiveKnownType(object source, string property)
        {
            TypeSerializationInfo typeSerializationInfo = KnownTypes.GetTypeSerializationInfo(source.GetType());

            if (typeSerializationInfo != null)
            {
                this.WriteOnePrimitiveKnownType(this._writer, property, source, typeSerializationInfo);
                return(true);
            }
            return(false);
        }
Beispiel #7
0
        /// <summary>
        /// Serializes Primitive Known Types.
        /// </summary>
        /// <returns>
        /// true if source is handled, else false.
        /// </returns>
        private bool HandlePrimitiveKnownType(object source, string property)
        {
            Dbg.Assert(source != null, "caller should validate the parameter");

            //Check if source is of primitive known type
            TypeSerializationInfo pktInfo = KnownTypes.GetTypeSerializationInfo(source.GetType());

            if (pktInfo != null)
            {
                WriteOnePrimitiveKnownType(_writer, property, source, pktInfo);
                return(true);
            }
            return(false);
        }
        private bool HandlePrimitiveKnownTypePSObject(object source, string property, int depth)
        {
            bool     flag = false;
            PSObject obj2 = source as PSObject;

            if ((obj2 != null) && !obj2.immediateBaseObjectIsEmpty)
            {
                object immediateBaseObject = obj2.ImmediateBaseObject;
                TypeSerializationInfo typeSerializationInfo = KnownTypes.GetTypeSerializationInfo(immediateBaseObject.GetType());
                if (typeSerializationInfo != null)
                {
                    this.WriteOnePrimitiveKnownType(this._writer, property, immediateBaseObject, typeSerializationInfo);
                    flag = true;
                }
            }
            return(flag);
        }
Beispiel #9
0
        /// <summary>
        /// Serializes PSObject whose base objects are of primitive known type
        /// </summary>
        /// <param name="source"></param>
        /// <param name="property"></param>
        /// <param name="depth"></param>
        /// <returns>
        /// true if source is handled, else false.
        /// </returns>
        private bool HandlePrimitiveKnownTypePSObject(object source, string property, int depth)
        {
            Dbg.Assert(source != null, "caller should validate the parameter");

            bool     sourceHandled = false;
            PSObject moSource      = source as PSObject;

            if (moSource != null && !moSource.immediateBaseObjectIsEmpty)
            {
                //Check if baseObject is primitive known type
                object baseObject             = moSource.ImmediateBaseObject;
                TypeSerializationInfo pktInfo = KnownTypes.GetTypeSerializationInfo(baseObject.GetType());
                if (pktInfo != null)
                {
                    WriteOnePrimitiveKnownType(_writer, property, baseObject, pktInfo);
                    sourceHandled = true;
                }
            }
            return(sourceHandled);
        }
        private void WritePrimitiveTypePSObjectWithNotes(PSObject source, object primitive, TypeSerializationInfo pktInfo, string property, int depth)
        {
            this.WriteStartOfPSObject(source, property, source.ToStringFromDeserialization != null);
            if (pktInfo != null)
            {
                this.WriteOnePrimitiveKnownType(this._writer, null, primitive, pktInfo);
            }
            PSMemberInfoCollection <PSMemberInfo> instanceMembers = source.InstanceMembers;

            if (instanceMembers != null)
            {
                this.WriteMemberInfoCollection(instanceMembers, depth, true);
            }
            this._writer.WriteEndElement();
        }
 private void WriteObjectString(XmlWriter writer, string property, object source, TypeSerializationInfo entry)
 {
     if (property != null)
     {
         WriteStartElement(writer, "Property");
         WriteAttribute(writer, "Name", property.ToString());
     }
     else if (this.firstcall)
     {
         WriteStartElement(writer, "Object");
         this.firstcall = false;
     }
     else
     {
         WriteStartElement(writer, "Property");
     }
     if (!this._notypeinformation)
     {
         WriteAttribute(writer, "Type", source.GetType().ToString());
     }
     writer.WriteString(source.ToString());
     writer.WriteEndElement();
 }
 private void WriteOnePrimitiveKnownType(XmlWriter writer, string property, object source, TypeSerializationInfo entry)
 {
     this.WriteObjectString(writer, property, source, entry);
 }
 private void WriteObjectString(XmlWriter writer, string property, object source, TypeSerializationInfo entry)
 {
     if (property != null)
     {
         WriteStartElement(writer, "Property");
         WriteAttribute(writer, "Name", property.ToString());
     }
     else if (this.firstcall)
     {
         WriteStartElement(writer, "Object");
         this.firstcall = false;
     }
     else
     {
         WriteStartElement(writer, "Property");
     }
     if (!this._notypeinformation)
     {
         WriteAttribute(writer, "Type", source.GetType().ToString());
     }
     writer.WriteString(source.ToString());
     writer.WriteEndElement();
 }
Beispiel #14
0
        /// <summary>
        /// Serializes an PSObject whose baseobject is of primitive type
        /// and which has notes.
        /// </summary>
        /// <param name="source">
        /// source from which notes are written
        /// </param>
        /// <param name="primitive">
        /// primitive object which is written as base object. In most cases it
        /// is same source.ImmediateBaseObject. When PSObject is serialized as string,
        /// it can be different. <see cref="HandlePSObjectAsString"/> for more info.
        /// </param>
        /// <param name="pktInfo">
        /// TypeSerializationInfo for the primitive. 
        /// </param>
        /// <param name="property"></param>
        /// <param name="depth"></param>
        private void WritePrimitiveTypePSObjectWithNotes(
            PSObject source,
            object primitive,
            TypeSerializationInfo pktInfo,
            string property,
            int depth)
        {
            Dbg.Assert(source != null, "caller should validate the parameter");

            //Write start of PSObject. Since baseobject is primitive known 
            //type, we do not need TypeName information.
            WriteStartOfPSObject(source, property, source.ToStringFromDeserialization != null);

            if (pktInfo != null)
            {
                WriteOnePrimitiveKnownType(_writer, null, primitive, pktInfo);
            }

            //Serialize instanceMembers
            PSMemberInfoCollection<PSMemberInfo> instanceMembers = source.InstanceMembers;
            if (instanceMembers != null)
            {
                WriteMemberInfoCollection(instanceMembers, depth, true);
            }

            _writer.WriteEndElement();
        }
Beispiel #15
0
        private void WriteObjectString(
            XmlWriter writer, string property, object source, TypeSerializationInfo entry)
        {
            if (property != null)
            {
                WriteStartElement(writer, CustomSerializationStrings.Properties);
                WriteAttribute(writer, CustomSerializationStrings.NameAttribute, property.ToString());
            }
            else
            {
                if (_firstcall)
                {
                    WriteStartElement(writer, CustomSerializationStrings.PSObjectTag);
                    _firstcall = false;
                }
                else
                {
                    WriteStartElement(writer, CustomSerializationStrings.Properties);
                }
            }

            if (!_notypeinformation)
                WriteAttribute(writer, CustomSerializationStrings.TypeAttribute, source.GetType().ToString());

            writer.WriteString(source.ToString());
            writer.WriteEndElement();
        }
Beispiel #16
0
 private object ReadPrimaryKnownType(TypeSerializationInfo pktInfo)
 {
     object obj2 = pktInfo.Deserializer(this);
     this._reader.MoveToContent();
     return obj2;
 }
        /// <summary>
        /// Writes an item or property in Monad namespace.
        /// </summary>
        /// <param name="writer">The XmlWriter stream to which the object is serialized.</param>
        /// <param name="property">name of property. Pass null for item</param>
        /// <param name="source">object to be written</param>
        /// <param name="entry">serialization information about source</param>

        private void WriteOnePrimitiveKnownType(
            XmlWriter writer, string property, object source, TypeSerializationInfo entry)
        {
            WriteObjectString(writer, property, source, entry);
        }
 private void WritePrimitiveTypePSObjectWithNotes(PSObject source, object primitive, TypeSerializationInfo pktInfo, string property, int depth)
 {
     this.WriteStartOfPSObject(source, property, source.ToStringFromDeserialization != null);
     if (pktInfo != null)
     {
         this.WriteOnePrimitiveKnownType(this._writer, null, primitive, pktInfo);
     }
     PSMemberInfoCollection<PSMemberInfo> instanceMembers = source.InstanceMembers;
     if (instanceMembers != null)
     {
         this.WriteMemberInfoCollection(instanceMembers, depth, true);
     }
     this._writer.WriteEndElement();
 }