public override IYamlSerializable TryCreate(SerializerContext context, ITypeDescriptor typeDescriptor)
        {
            if (CanVisit(typeDescriptor.Type))
                return this;

            return null;
        }
        public override IYamlSerializable TryCreate(SerializerContext context, ITypeDescriptor typeDescriptor)
        {
            if (CanVisit(typeDescriptor.Type))
            {
                return(this);
            }

            return(null);
        }
        /// <inheritdoc/>
        public override IYamlSerializable TryCreate(SerializerContext context, ITypeDescriptor typeDescriptor)
        {
            // Accepts any type inheriting from AssetComposite
            if (typeof(AssetComposite).IsAssignableFrom(typeDescriptor.Type))
            {
                return(this);
            }

            // Accepts any type known as asset part type for the current asset type.
            if (localContext.Value != null && localContext.Value.References.Any(x => x.ReferenceableType.IsAssignableFrom(typeDescriptor.Type)))
            {
                return(this);
            }

            return(null);
        }
 public override IYamlSerializable TryCreate(SerializerContext context, ITypeDescriptor typeDescriptor)
 {
     var type = typeDescriptor.Type;
     return CanVisit(type) ? this : null;
 }
 public override IYamlSerializable TryCreate(SerializerContext context, ITypeDescriptor typeDescriptor)
 {
     var type = typeDescriptor.Type;
     return type == typeof(SettingsProfile) ? this : null;
 }
 public IYamlSerializable TryCreate(SerializerContext context, ITypeDescriptor typeDescriptor)
 {
     return typeDescriptor.Type == typeof(AssetName) ? this : null;
 }
 public override IYamlSerializable TryCreate(SerializerContext context, ITypeDescriptor typeDescriptor)
 {
     var type = typeDescriptor.Type;
     return type == typeof(EntityComponentCollection) ? this : null;
 }
Exemple #8
0
        /// <summary>
        /// Deserializes an object from the specified <see cref="EventReader" /> with an expected specific type.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <param name="expectedType">The expected type, maybe null.</param>
        /// <param name="existingObject">An existing object, may be null.</param>
        /// <param name="contextSettings">The context settings.</param>
        /// <param name="context">The context used to deserialize the object.</param>
        /// <returns>A deserialized object.</returns>
        /// <exception cref="System.ArgumentNullException">reader</exception>
        public object Deserialize(EventReader reader, Type expectedType, object existingObject, SerializerContextSettings contextSettings, out SerializerContext context)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            var hasStreamStart   = reader.Allow <StreamStart>() != null;
            var hasDocumentStart = reader.Allow <DocumentStart>() != null;

            context = null;

            object result = null;

            if (!reader.Accept <DocumentEnd>() && !reader.Accept <StreamEnd>())
            {
                context = new SerializerContext(this, contextSettings)
                {
                    Reader = reader
                };
                result = context.ReadYaml(existingObject, expectedType);
            }

            if (hasDocumentStart)
            {
                reader.Expect <DocumentEnd>();
            }

            if (hasStreamStart)
            {
                reader.Expect <StreamEnd>();
            }

            return(result);
        }
 public IYamlSerializable TryCreate(SerializerContext context, ITypeDescriptor typeDescriptor)
 {
     return CanVisit(typeDescriptor.Type) ? this : null;
 }
Exemple #10
0
 /// <summary>
 /// Deserializes an object from the specified string. with an expected specific type.
 /// </summary>
 /// <typeparam name="T">The expected type</typeparam>
 /// <param name="fromText">From text.</param>
 /// <param name="existingObject">The object to deserialize into.</param>
 /// <param name="context">The context used to deserialize this object.</param>
 /// <returns>A deserialized object.</returns>
 /// <exception cref="System.ArgumentNullException">stream</exception>
 /// Note: These need a different name, because otherwise they will conflict with existing Deserialize(string,Type). They are new so the difference should not matter
 public T DeserializeInto <T>(string fromText, T existingObject, out SerializerContext context)
 {
     return((T)Deserialize(fromText, typeof(T), existingObject, out context));
 }
Exemple #11
0
 /// <summary>
 /// Deserializes an object from the specified <see cref="EventReader" /> with an expected specific type.
 /// </summary>
 /// <typeparam name="T">The expected type</typeparam>
 /// <param name="reader">The reader.</param>
 /// <param name="existingObject">The object to deserialize into.</param>
 /// <param name="context">The context used to deserialize this object.</param>
 /// <returns>A deserialized object.</returns>
 /// <exception cref="System.ArgumentNullException">reader</exception>
 public T DeserializeInto <T>(EventReader reader, T existingObject, out SerializerContext context)
 {
     return((T)Deserialize(reader, typeof(T), existingObject, null, out context));
 }
Exemple #12
0
 /// <summary>
 /// Deserializes an object from the specified <see cref="EventReader" /> with an expected specific type.
 /// </summary>
 /// <typeparam name="T">The expected type</typeparam>
 /// <param name="reader">The reader.</param>
 /// <param name="context">The context used to deserialize this object.</param>
 /// <returns>A deserialized object.</returns>
 /// <exception cref="System.ArgumentNullException">reader</exception>
 public T Deserialize <T>(EventReader reader, out SerializerContext context)
 {
     return((T)Deserialize(reader, typeof(T), null, null, out context));
 }
Exemple #13
0
 /// <summary>
 /// Deserializes an object from the specified string. with an expected specific type.
 /// </summary>
 /// <typeparam name="T">The expected type</typeparam>
 /// <param name="fromText">From text.</param>
 /// <param name="context">The context.</param>
 /// <returns>A deserialized object.</returns>
 /// <exception cref="System.ArgumentNullException">stream</exception>
 public T Deserialize <T>(string fromText, out SerializerContext context)
 {
     return((T)Deserialize(fromText, typeof(T), null, out context));
 }
Exemple #14
0
 /// <summary>
 /// Deserializes an object from the specified string. with an expected specific type.
 /// </summary>
 /// <param name="fromText">From text.</param>
 /// <param name="expectedType">The expected type.</param>
 /// <param name="existingObject">The object to deserialize into. If null (the default) then a new object will be created</param>
 /// <param name="context">The context used to deserialize this object.</param>
 /// <returns>A deserialized object.</returns>
 /// <exception cref="System.ArgumentNullException">stream</exception>
 public object Deserialize(string fromText, Type expectedType, object existingObject, out SerializerContext context)
 {
     if (fromText == null)
     {
         throw new ArgumentNullException("fromText");
     }
     return(Deserialize(new StringReader(fromText), expectedType, existingObject, null, out context));
 }
Exemple #15
0
 /// <summary>
 /// Deserializes an object from the specified <see cref="TextReader" /> with an expected specific type.
 /// </summary>
 /// <param name="reader">The reader.</param>
 /// <param name="expectedType">The expected type.</param>
 /// <param name="existingObject">The object to deserialize into. If null (the default) then a new object will be created</param>
 /// <param name="contextSettings">The context settings.</param>
 /// <param name="context">The context used to deserialize this object.</param>
 /// <returns>A deserialized object.</returns>
 /// <exception cref="System.ArgumentNullException">reader</exception>
 public object Deserialize(TextReader reader, Type expectedType, object existingObject, SerializerContextSettings contextSettings, out SerializerContext context)
 {
     if (reader == null)
     {
         throw new ArgumentNullException("reader");
     }
     return(Deserialize(new EventReader(new Parser(reader)), expectedType, existingObject, contextSettings, out context));
 }
Exemple #16
0
        /// <summary>
        /// Deserializes an object from the specified <see cref="Stream" /> with an expected specific type.
        /// </summary>
        /// <param name="stream">The stream.</param>
        /// <param name="expectedType">The expected type.</param>
        /// <param name="contextSettings">The context settings.</param>
        /// <param name="context">The context used to deserialize this object.</param>
        /// <returns>A deserialized object.</returns>
        /// <exception cref="System.ArgumentNullException">stream</exception>
        public object Deserialize(Stream stream, Type expectedType, SerializerContextSettings contextSettings, out SerializerContext context)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            return(Deserialize(new StreamReader(stream), expectedType, null, contextSettings, out context));
        }