Esempio n. 1
0
        /// <summary>
        /// Loads an object from the specified XML element.
        /// </summary>
        /// <param name="resolver">A custom <see cref="ObjectLoaderMemberResolutionHandler"/> which allows external
        /// code to optionally resolve deserialized member values.</param>
        /// <param name="type">The type of object to load.</param>
        /// <param name="xml">The XML element that contains the object data.</param>
        /// <param name="culture">The culture information to use when parsing values.</param>
        /// <param name="ignoreMissingMembers">A value indicating whether the object loader
        /// should ignore members which do not exist on the type.</param>
        /// <returns>The object that was loaded.</returns>
        public Object LoadObject(ObjectLoaderMemberResolutionHandler resolver, Type type, XElement xml, CultureInfo culture, Boolean ignoreMissingMembers = false)
        {
            Contract.Require(type, nameof(type));
            Contract.Require(xml, nameof(xml));
            Contract.Require(culture, nameof(culture));

            var state = new ObjectLoaderState(globalAliases, culture, resolver);

            state.IgnoreMissingMembers = ignoreMissingMembers;
            state.ParseClassAliases(null, type);

            var objectElement  = xml;
            var objectInstance = CreateObjectFromRootElement(state, type, objectElement);

            return(PopulateObject(state, objectInstance, objectElement));
        }
Esempio n. 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ObjectLoaderState"/> class.
 /// </summary>
 /// <param name="globalAliases">The registry of global aliases.</param>
 /// <param name="culture">The culture information to use when parsing objects.</param>
 /// <param name="resolver">The custom member resolution handler, if any.</param>
 public ObjectLoaderState(Dictionary <String, String> globalAliases, CultureInfo culture, ObjectLoaderMemberResolutionHandler resolver = null)
 {
     this.globalClassAliases = globalAliases;
     this.culture            = culture;
     this.resolver           = resolver;
 }
Esempio n. 3
0
 /// <summary>
 /// Loads an object from the specified XML element.
 /// </summary>
 /// <typeparam name="T">The type of object to load.</typeparam>
 /// <param name="resolver">A custom <see cref="ObjectLoaderMemberResolutionHandler"/> which allows external
 /// code to optionally resolve deserialized member values.</param>
 /// <param name="xml">The XML element that contains the object data.</param>
 /// <param name="culture">The culture information to use when parsing values.</param>
 /// <param name="ignoreMissingMembers">A value indicating whether the object loader
 /// should ignore members which do not exist on the type.</param>
 /// <returns>The object that was loaded.</returns>
 public T LoadObject <T>(ObjectLoaderMemberResolutionHandler resolver, XElement xml, CultureInfo culture, Boolean ignoreMissingMembers = false) =>
 (T)LoadObject(resolver, typeof(T), xml, culture, ignoreMissingMembers);
Esempio n. 4
0
 /// <summary>
 /// Loads an object from the specified XML element.
 /// </summary>
 /// <param name="resolver">A custom <see cref="ObjectLoaderMemberResolutionHandler"/> which allows external
 /// code to optionally resolve deserialized member values.</param>
 /// <param name="type">The type of object to load.</param>
 /// <param name="xml">The XML element that contains the object data.</param>
 /// <param name="ignoreMissingMembers">A value indicating whether the object loader
 /// should ignore members which do not exist on the type.</param>
 /// <returns>The object that was loaded.</returns>
 public Object LoadObject(ObjectLoaderMemberResolutionHandler resolver, Type type, XElement xml, Boolean ignoreMissingMembers = false) =>
 LoadObject(resolver, type, xml, CultureInfo.InvariantCulture, ignoreMissingMembers);
 /// <summary>
 /// Initializes a new instance of the <see cref="ObjectLoaderState"/> class.
 /// </summary>
 /// <param name="globalAliases">The registry of global aliases.</param>
 /// <param name="culture">The culture information to use when parsing objects.</param>
 /// <param name="resolver">The custom member resolution handler, if any.</param>
 public ObjectLoaderState(Dictionary<String, String> globalAliases, CultureInfo culture, ObjectLoaderMemberResolutionHandler resolver = null)
 {
     this.globalClassAliases = globalAliases;
     this.culture = culture;
     this.resolver = resolver;
 }
 /// <summary>
 /// Loads an object from the specified XML element.
 /// </summary>
 /// <param name="resolver">A custom <see cref="ObjectLoaderMemberResolutionHandler"/> which allows external
 /// code to optionally resolve deserialized member values.</param>
 /// <param name="type">The type of object to load.</param>
 /// <param name="xml">The XML element that contains the object data.</param>
 /// <param name="culture">The culture information to use when parsing values.</param>
 /// <param name="ignoreMissingMembers">A value indicating whether the object loader
 /// should ignore members which do not exist on the type.</param>
 /// <returns>The object that was loaded.</returns>
 public static Object LoadObject(ObjectLoaderMemberResolutionHandler resolver, Type type, XElement xml, CultureInfo culture, Boolean ignoreMissingMembers = false) =>
 xmlSerializer.LoadObject(resolver, type, xml, culture, ignoreMissingMembers);
 /// <summary>
 /// Loads an object from the specified XML element.
 /// </summary>
 /// <typeparam name="T">The type of object to load.</typeparam>
 /// <param name="resolver">A custom <see cref="ObjectLoaderMemberResolutionHandler"/> which allows external
 /// code to optionally resolve deserialized member values.</param>
 /// <param name="xml">The XML element that contains the object data.</param>
 /// <param name="ignoreMissingMembers">A value indicating whether the object loader
 /// should ignore members which do not exist on the type.</param>
 /// <returns>The object that was loaded.</returns>
 public static T LoadObject <T>(ObjectLoaderMemberResolutionHandler resolver, XElement xml, Boolean ignoreMissingMembers = false) =>
 xmlSerializer.LoadObject <T>(resolver, xml, ignoreMissingMembers);