Beispiel #1
0
        public virtual void Parse([NotNull] XElement element)
        {
            Debug.ArgumentNotNull(element, nameof(element));

            // TODO: store properties in derrived classes - like MvcModel
            var className     = ClassName;
            var propertyNames = new Dictionary <string, string>();

            foreach (var templateField in TemplateSections.SelectMany(s => s.Fields))
            {
                propertyNames[templateField.Id] = templateField.PropertyName;
            }

            TemplateSections.Clear();

            Name      = element.GetAttributeValue("name");
            ClassName = Name.GetSafeCodeIdentifier();

            foreach (var sectionElement in element.Elements())
            {
                var templateSection = ShapeCreator.CreateTemplateSection(ShapeCreator);
                TemplateSections.Add(templateSection);

                templateSection.Parse(sectionElement);
            }

            if (!string.IsNullOrEmpty(className))
            {
                ClassName = className;
            }

            foreach (var templateField in TemplateSections.SelectMany(s => s.Fields))
            {
                string propertyName;
                if (propertyNames.TryGetValue(templateField.Id, out propertyName))
                {
                    templateField.PropertyName = propertyName;
                }
            }
        }
Beispiel #2
0
        public virtual void Load([NotNull] XElement element)
        {
            Assert.ArgumentNotNull(element, nameof(element));

            TemplateSections.Clear();

            ItemUri templateUri;

            ItemUri.TryParse(element.GetAttributeValue("templateuri"), out templateUri);

            TemplateUri = templateUri;
            Name        = element.GetAttributeValue("templatename");
            ClassName   = element.GetAttributeValue("classname");

            foreach (var sectionElement in element.Elements())
            {
                var section = ShapeCreator.CreateTemplateSection(ShapeCreator);

                section.Load(sectionElement);

                TemplateSections.Add(section);
            }
        }