/// <summary>
        /// Serialize the data type description to XML
        /// </summary>
        /// <returns>Serialized data type descriptor</returns>
        public XElement ToXml()
        {
            var element = new XElement("DataTypeDescriptor",
                                       new XAttribute("dataTypeId", this.DataTypeId),
                                       new XAttribute("name", this.Name),
                                       new XAttribute("namespace", this.Namespace),
                                       this.Title != null ? new XAttribute("title", this.Title) : null,
                                       new XAttribute("isCodeGenerated", this.IsCodeGenerated),
                                       new XAttribute("cachable", this.Cachable),
                                       new XAttribute("searchable", this.Searchable),
                                       this.LabelFieldName != null ? new XAttribute("labelFieldName", this.LabelFieldName) : null,
                                       !string.IsNullOrEmpty(this.InternalUrlPrefix) ? new XAttribute("internalUrlPrefix", this.InternalUrlPrefix) : null,
                                       this.TypeManagerTypeName != null ? new XAttribute("typeManagerTypeName", this.TypeManagerTypeName) : null,
                                       !string.IsNullOrEmpty(this.BuildNewHandlerTypeName) ? new XAttribute("buildNewHandlerTypeName", this.BuildNewHandlerTypeName) : null);


            element.Add(new[]
            {
                new XElement("DataAssociations",
                             DataAssociations.Select(da => da.ToXml())),
                new XElement("DataScopes",
                             DataScopes.Select(dsi => new XElement("DataScopeIdentifier", new XAttribute("name", dsi)))),
                new XElement("KeyPropertyNames",
                             KeyPropertyNames.Select(name => new XElement("KeyPropertyName", new XAttribute("name", name)))),
                VersionKeyPropertyNames.Any()
                    ? new XElement("VersionKeyPropertyNames",
                                   VersionKeyPropertyNames.Select(name => new XElement("VersionKeyPropertyName", new XAttribute("name", name))))
                    : null,
                new XElement("SuperInterfaces",
                             SuperInterfaces.Select(su => new XElement("SuperInterface", new XAttribute("type", TypeManager.SerializeType(su))))),
                new XElement("Fields", Fields.Select(f => f.ToXml()))
            });

            if (Indexes.Any())
            {
                element.Add(new XElement("Indexes", Indexes.Select(i => i.ToXml())));
            }

            return(element);
        }
Example #2
0
        /// <summary>
        /// Adds an interface the data type should inherit from
        /// </summary>
        /// <param name="interfaceType"></param>
        /// <param name="addInheritedFields"></param>
        internal void AddSuperInterface(Type interfaceType, bool addInheritedFields)
        {
            if (_superInterfaces.Contains(interfaceType) || interfaceType == typeof(IData))
            {
                return;
            }

            _superInterfaces.Add(interfaceType);

            if (addInheritedFields)
            {
                foreach (PropertyInfo propertyInfo in interfaceType.GetProperties())
                {
                    if (propertyInfo.Name == nameof(IPageData.PageId) && interfaceType == typeof(IPageData))
                    {
                        continue;
                    }

                    DataFieldDescriptor dataFieldDescriptor = ReflectionBasedDescriptorBuilder.BuildFieldDescriptor(propertyInfo, true);

                    this.Fields.Add(dataFieldDescriptor);
                }
            }

            foreach (string propertyName in interfaceType.GetKeyPropertyNames())
            {
                if (KeyPropertyNames.Contains(propertyName))
                {
                    continue;
                }

                PropertyInfo property = ReflectionBasedDescriptorBuilder.FindProperty(interfaceType, propertyName);

                if (DynamicTypeReflectionFacade.IsKeyField(property))
                {
                    this.KeyPropertyNames.Add(propertyName, false);
                }
            }

            foreach (string propertyName in interfaceType.GetVersionKeyPropertyNames())
            {
                if (VersionKeyPropertyNames.Contains(propertyName))
                {
                    continue;
                }

                ReflectionBasedDescriptorBuilder.FindProperty(interfaceType, propertyName);

                this.VersionKeyPropertyNames.Add(propertyName, false);
            }

            foreach (var dataScopeIdentifier in DynamicTypeReflectionFacade.GetDataScopes(interfaceType))
            {
                if (!this.DataScopes.Contains(dataScopeIdentifier))
                {
                    this.DataScopes.Add(dataScopeIdentifier);
                }
            }

            var superInterfaces = interfaceType.GetInterfaces().Where(t => typeof(IData).IsAssignableFrom(t));

            foreach (Type superSuperInterfaceType in superInterfaces)
            {
                AddSuperInterface(superSuperInterfaceType, addInheritedFields);
            }
        }