Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ScreenModel"/> class.
        /// </summary>
        /// <param name="definition">The definition.</param>
        /// <exception cref="System.ArgumentException">Required container property is not present in the screen definition</exception>
        public ScreenModel(UIControlDefinitionModel definition, ProjectModel projectOwner)
            : base(projectOwner, null, definition)
        {
            System.Diagnostics.Debug.Assert(definition != null, "Screen definition can't be null");
            //System.Diagnostics.Debug.Assert(!string.IsNullOrEmpty(definition.Name) && (definition.Name.Equals("screen", StringComparison.OrdinalIgnoreCase) || definition.Name.Equals("view", StringComparison.OrdinalIgnoreCase)), "definition must be for screen or view");
            System.Diagnostics.Debug.Assert(projectOwner != null, "Project owner can't be null");

            this.ParentProject = projectOwner;
            string containerPropertyName = "items";

            if (!string.IsNullOrEmpty(definition.ContainerProperty))
            {
                containerPropertyName = definition.ContainerProperty;
            }
            containerAttribute = this.ControlDefinition.AllAttributes.FirstOrDefault(a => a.Name == containerPropertyName);
            //if (containerAttribute == null)
            //{
            //    throw new ArgumentException("Required container property is not present in the screen definition");
            //}
        }
        /// <summary>
        /// Serializes the attribute value.
        /// </summary>
        /// <param name="baseElement">The base element.</param>
        /// <param name="key">The key.</param>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        private void SerializeAttributeValue(XElement baseElement, AttributeModel key)
        {
            string value      = string.Empty;
            object typedValue = mAttributes[key];

            if (typedValue != null)
            {
                switch (key.AttributeType.ToLowerInvariant())
                {
                case "collection":     // only collections are special cases
                {
                    TrulyObservableCollection <UIControlInstanceModel> collection = typedValue as TrulyObservableCollection <UIControlInstanceModel>;
                    if (collection.Count > 0)
                    {
                        AddToXMLChildElementsByID(baseElement, key.Name, collection);
                    }
                }
                break;

                default:
                {
                    AttributeValueConverter valueConverter = new AttributeValueConverter();
                    value = valueConverter.Convert(typedValue, typeof(string), key.AttributeType, System.Globalization.CultureInfo.InvariantCulture) as string;
                }
                break;
                }
            }
            else
            {
                value = string.Empty;
            }

            if (!string.IsNullOrEmpty(value))
            {
                baseElement.SetAttributeValue(key.Name.ToLowerInvariant(), value);
            }
        }