/// <summary> /// Initializes the <see cref="PublicProperties"/> and <see cref="PrivateProperties"/> lists from the given new <see cref="MemoryProperty"/> objects as well as parent data. Then checks the property lists against all <see cref="DataContract"/>s and expected conditions. /// </summary> /// <param name="newPublic">The new public <see cref="MemoryProperty"/> objects to add to the <see cref="DataType"/>.</param> /// <param name="newPrivate">The new private <see cref="MemoryProperty"/> objects to add to the <see cref="DataType"/>.</param> public void InitializeProperties(IEnumerable <MemoryProperty> newPublic, IEnumerable <MemoryProperty> newPrivate) { PublicProperties = new List <MemoryProperty>(); PrivateProperties = new List <MemoryProperty>(); if (ParentType != null) { PublicProperties.AddRange(ParentType.PublicProperties); PrivateProperties.AddRange(ParentType.PrivateProperties); } PublicProperties.AddRange(newPublic); PrivateProperties.AddRange(newPrivate); //// Get any properties that have duplicate paths. var allProperties = PublicProperties.Concat(PrivateProperties); var duplicates = allProperties.Where(p => allProperties.Count(a => a.Key == p.Key) > 1); if (duplicates.Any()) { throw new TypePropertyException($"One or more property keys are used more than once in the same enclosing type {this.TypeName}: {string.Join(",", duplicates.Select(d => d.Key).Distinct())}."); } //// Get any DataContracts that are missing properties on the type. var unfulfilled = InheritedContracts.Where(c => !c.GetProperties().All(p => PublicProperties.Contains(p))); if (unfulfilled.Any()) { throw new TypePropertyException($"One or more DataContracts are missing required properties on type {this.TypeName}: {string.Join(",", unfulfilled.Select(u => u.TypeName))}."); } }
/// <summary> /// Creates a <see cref="DataType"/> and initializes properties and inheritance. /// </summary> /// <param name="typeName">The name of the <see cref="DataType"/>.</param> /// <param name="publicProperties">A collection of <see cref="MemoryProperty"/> items that a <see cref="DataObject"/> of this <see cref="DataType"/> would publicly have available.</param> /// <param name="privateProperties">A collection of <see cref="MemoryProperty"/> items that a <see cref="DataObject"/> of this <see cref="DataType"/> would privately have available.</param> /// <param name="inheritedContracts">A collection of <see cref="DataContract"/>s that this <see cref="DataType"/> supports.</param> /// <param name="parentType">The parent <see cref="DataType"/> of this <see cref="DataType"/>, from which this type inherits all properties and fulfilled <see cref="DataContract"/>s.</param> public DataType(Namespace typeName, IEnumerable <MemoryProperty> publicProperties, IEnumerable <MemoryProperty> privateProperties, IEnumerable <DataContract> inheritedContracts = null, DataType parentType = null) : this(typeName) { if (inheritedContracts != null) { InheritedContracts.AddRange(inheritedContracts); } ParentType = parentType; InitializeProperties(publicProperties, privateProperties); }
/// <inheritdoc/> public bool Is(IType other) { if (other == this) { return(true); } else if (InheritedContracts.Any(c => c.Is(other))) { return(true); } else if (ParentType != null && ParentType.Is(other)) { return(true); } else { return(false); } }