Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="UvmlTemplate"/> class
        /// from the specified XML element.
        /// </summary>
        /// <param name="element">The XML element from which to create the template.</param>
        /// <param name="type">The type of the object being instantiated by the template.</param>
        /// <param name="instantiator">A function which instantiates objects for this template,
        /// or <see langword="null"/> to use the default object instantiator.</param>
        /// <param name="mutators">The template's collection of mutators.</param>
        internal UvmlTemplate(XElement element, Type type, UvmlTemplateInstantiator instantiator, IEnumerable<UvmlMutator> mutators = null)
        {
            Contract.Require(element, nameof(element));
            Contract.Require(type, nameof(type));

            var templatedObjectName = (String)element.Attribute("Name");
            if (String.IsNullOrWhiteSpace(templatedObjectName))
                templatedObjectName = null;

            this.name = templatedObjectName;
            this.instantiator = instantiator ?? CreateDefaultInstantiator(type);
            this.mutators = new List<UvmlMutator>(mutators ?? Enumerable.Empty<UvmlMutator>());

            var classesString = (String)element.Attribute("Class");
            if (!String.IsNullOrWhiteSpace(classesString))
            {
                this.classes = new List<String>(classesString.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="UvmlTemplate"/> class
        /// from the specified XML element.
        /// </summary>
        /// <param name="element">The XML element from which to create the template.</param>
        /// <param name="type">The type of the object being instantiated by the template.</param>
        /// <param name="instantiator">A function which instantiates objects for this template,
        /// or <see langword="null"/> to use the default object instantiator.</param>
        /// <param name="mutators">The template's collection of mutators.</param>
        internal UvmlTemplate(XElement element, Type type, UvmlTemplateInstantiator instantiator, IEnumerable <UvmlMutator> mutators = null)
        {
            Contract.Require(element, nameof(element));
            Contract.Require(type, nameof(type));

            var templatedObjectName = (String)element.Attribute("Name");

            if (String.IsNullOrWhiteSpace(templatedObjectName))
            {
                templatedObjectName = null;
            }

            this.name         = templatedObjectName;
            this.instantiator = instantiator ?? CreateDefaultInstantiator(type);
            this.mutators     = new List <UvmlMutator>(mutators ?? Enumerable.Empty <UvmlMutator>());

            var classesString = (String)element.Attribute("Class");

            if (!String.IsNullOrWhiteSpace(classesString))
            {
                this.classes = new List <String>(classesString.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries));
            }
        }