Ejemplo n.º 1
0
        protected internal override void Initialize(IntermediateSerializer serializer)
        {
            if (base.TargetType.BaseType != null)
            {
                this.baseSerializer = serializer.GetTypeSerializer(base.TargetType.BaseType);
            }
            MemberHelperBase <IntermediateSerializer> .CreateMemberHelpers <ReflectiveSerializerMemberHelper>(serializer, base.TargetType, this.memberHelpers);

            if (CollectionUtils.IsCollection(base.TargetType, false))
            {
                this.collectionHelper = serializer.GetCollectionHelper(base.TargetType);
            }
            object[] customAttributes = base.TargetType.GetCustomAttributes(typeof(ContentSerializerCollectionItemNameAttribute), true);
            if (customAttributes.Length == 1)
            {
                this.collectionItemName = ((ContentSerializerCollectionItemNameAttribute)customAttributes[0]).CollectionItemName;
            }
        }
Ejemplo n.º 2
0
 /// <summary />
 public string GetContentAsXml()
 {
     if (this.contentAsXml == null)
     {
         if (base.Count == 0)
         {
             this.contentAsXml = string.Empty;
         }
         else
         {
             StringBuilder stringBuilder = new StringBuilder();
             using (XmlWriter xmlWriter = XmlWriter.Create(stringBuilder))
             {
                 IntermediateSerializer.Serialize <OpaqueDataDictionary>(xmlWriter, this, null);
             }
             this.contentAsXml = stringBuilder.ToString();
         }
     }
     return(this.contentAsXml);
 }
Ejemplo n.º 3
0
        internal CollectionHelper(IntermediateSerializer serializer, Type type)
        {
            this.targetType = type;
            Type type2 = CollectionUtils.CollectionElementType(type, false);

            if (type2 == null)
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.NotACollectionType, new object[]
                {
                    type
                }));
            }
            this.contentSerializer = serializer.GetTypeSerializer(type2);
            Type type3 = typeof(ICollection <>).MakeGenericType(new Type[]
            {
                type2
            });

            this.countPropertyGetter = ReflectionEmitUtils.GenerateGetter(type3.GetProperty("Count"));
            this.addToCollection     = ReflectionEmitUtils.GenerateAddToCollection(type3, type2);
        }
        /// <summary>Serializes an object into an intermediate XML file.</summary>
        /// <param name="output">The output XML stream.</param>
        /// <param name="value">The object to be serialized.</param>
        /// <param name="referenceRelocationPath">Final name of the output file, used to relative encode external reference filenames.</param>
        public static void Serialize <T>(XmlWriter output, T value, string referenceRelocationPath)
        {
            if (output == null)
            {
                throw new ArgumentNullException("output");
            }
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }
            Uri baseUri = IntermediateSerializer.RelocationPathToUri(referenceRelocationPath);
            IntermediateWriter intermediateWriter = new IntermediateWriter(IntermediateSerializer.SingletonInstance, output, baseUri);

            output.WriteStartElement("XnaContent");
            new XmlNamespaces(intermediateWriter).WriteNamespaces(value);
            ContentSerializerAttribute contentSerializerAttribute = new ContentSerializerAttribute();

            contentSerializerAttribute.ElementName = "Asset";
            intermediateWriter.WriteObject <object>(value, contentSerializerAttribute);
            intermediateWriter.WriteSharedResources();
            intermediateWriter.WriteExternalReferences();
            output.WriteEndElement();
        }
Ejemplo n.º 5
0
 protected internal override void ScanChildren(IntermediateSerializer serializer, ContentTypeSerializer.ChildCallback callback, T[] value)
 {
     this.arrayHelper.ScanElements(callback, value);
 }
Ejemplo n.º 6
0
 protected internal override void Initialize(IntermediateSerializer serializer)
 {
     this.arrayHelper = serializer.GetCollectionHelper(typeof(T[]));
     this.listHelper  = serializer.GetCollectionHelper(typeof(List <T>));
 }
Ejemplo n.º 7
0
 protected internal override void ScanChildren(IntermediateSerializer serializer, ContentTypeSerializer.ChildCallback callback, List <T> value)
 {
     this.collectionHelper.ScanElements(callback, value);
 }
Ejemplo n.º 8
0
 internal IntermediateReader(IntermediateSerializer serializer, XmlReader xmlReader, Uri baseUri)
 {
     this.serializer = serializer;
     this.xmlReader  = xmlReader;
     this.baseUri    = baseUri;
 }
Ejemplo n.º 9
0
 /// <summary>Examines the children of the specified object, passing each to a callback delegate.</summary>
 /// <param name="serializer">The content serializer.</param>
 /// <param name="callback">The method to be called for each examined child.</param>
 /// <param name="value">The object whose children are being scanned.</param>
 protected internal override void ScanChildren(IntermediateSerializer serializer, ContentTypeSerializer.ChildCallback callback, object value)
 {
     this.ScanChildren(serializer, callback, ContentTypeSerializer <T> .CastType(value));
 }
Ejemplo n.º 10
0
 /// <summary>Examines the children of the specified object, passing each to a callback delegate.</summary>
 /// <param name="serializer">The content serializer.</param>
 /// <param name="callback">The method to be called for each examined child.</param>
 /// <param name="value">The strongly typed object whose children are being scanned.</param>
 protected internal virtual void ScanChildren(IntermediateSerializer serializer, ContentTypeSerializer.ChildCallback callback, T value)
 {
 }
Ejemplo n.º 11
0
 /// <summary>Retrieves and caches any nested type serializers and allows reflection over the target data type.</summary>
 /// <param name="serializer">The content serializer.</param>
 protected internal virtual void Initialize(IntermediateSerializer serializer)
 {
 }
Ejemplo n.º 12
0
 protected internal override void Initialize(IntermediateSerializer serializer)
 {
     this.underlyingTypeSerializer        = serializer.GetTypeSerializer(typeof(T));
     this.underlyingFormat                = new ContentSerializerAttribute();
     this.underlyingFormat.FlattenContent = true;
 }