Composite.Data.DynamicTypes.DataTypeDescriptor.Validate C# (CSharp) Метод

Validate() публичный Метод

Validate the data type description or throw an exception.
public Validate ( ) : void
Результат void
        public void Validate()
        {
            try
            {
                if (this.DataTypeId == Guid.Empty) throw new InvalidOperationException("The type descriptor property DataTypeId can not be empty");
                if (string.IsNullOrEmpty(this.Namespace)) throw new InvalidOperationException("The type descriptor property Namespace can not be empty");
                if (string.IsNullOrEmpty(this.Name)) throw new InvalidOperationException("The type descriptor property Name can not be empty");
                if (string.IsNullOrEmpty(this.TypeManagerTypeName)) throw new InvalidOperationException("The type descriptor property TypeManagerTypeName can not be empty");
                if (this.Fields.Count == 0) throw new InvalidOperationException("The type descriptors Fields collection may not be empty");
                if (this.KeyPropertyNames.Count == 0) throw new InvalidOperationException("The type descriptors KeyFieldNames collection may not be empty");
                if (this.DataScopes.Count == 0) throw new InvalidOperationException("The DataScopes list containing the list of data scopes this type must support can not be empty. Please provide at least one data scopes.");
                if (this.DataScopes.Select(f => f.Name).Distinct().Count() != this.DataScopes.Count) throw new InvalidOperationException("The DataScopes list contains redundant data scopes");

                this.KeyPropertyNames.ValidateMembers();
                this.StoreSortOrderFieldNames.ValidateMembers();

                if (this.LabelFieldName != null)
                {
                    if (!this.Fields.Any(f => f.Name == this.LabelFieldName))
                    {
                        throw new InvalidOperationException($"The label field name '{this.LabelFieldName}' is not an existing field");
                    }
                }

                int distinctForeignKeyPropertyNames =
                    (from assDec in this.DataAssociations
                     select assDec.ForeignKeyPropertyName).Distinct().Count();

                if (distinctForeignKeyPropertyNames != this.DataAssociations.Count)
                {
                    throw new InvalidOperationException("Two or more data associations are using the same foreign key field");
                }

                int distinctAssociatedInterfaceType =
                    (from assDec in this.DataAssociations
                     select assDec.AssociatedInterfaceType).Distinct().Count();

                if (distinctAssociatedInterfaceType != this.DataAssociations.Count)
                {
                    throw new InvalidOperationException("Two or more data associations are associated to the same interface type");
                }
            }
            catch (Exception ex)
            {
                string typeName = string.IsNullOrEmpty(this.TypeManagerTypeName) ? this.Name : this.TypeManagerTypeName;
                throw new InvalidOperationException($"Failed to validate data type description for '{typeName}'.", ex);
            }
        }

Usage Example

Пример #1
0
        /// <exclude />
        public void UpdateDataTypeDescriptor(DataTypeDescriptor dataTypeDescriptor, bool flushTheSystem)
        {
            dataTypeDescriptor.Validate();

            DataMetaDataFacade.PersistMetaData(dataTypeDescriptor);

            if (flushTheSystem)
            {
                GlobalEventSystemFacade.FlushTheSystem();
            }
        }
All Usage Examples Of Composite.Data.DynamicTypes.DataTypeDescriptor::Validate