/// <summary> /// Declares 'field' members for a type. /// That is, all fields that apply to this type, either directly or through inheritance. /// </summary> /// <param name="entityType">The type entity.</param> /// <param name="memberGroup">The XSD container that will hold the members.</param> private void AddTypeFields(EffectiveType entityType, XmlSchemaGroupBase memberGroup) { // Example: // <xs:element minOccurs="0" maxOccurs="1" ref="firstName" /> // Define fields applicable to type // This is defining that a given field can appear under a resource of a particular type var fields = from type in _schemaManager.GetAncestors(entityType.Type) from field in _schemaManager.GetDeclaredFields(type) select field; foreach (Entity field in fields) { if (field.Alias == null) { continue; } var fieldElem = new XmlSchemaElement(); fieldElem.RefName = NameUsed(field.Alias.ToQualifiedName()); fieldElem.MaxOccurs = 1; bool required = (_schemaManager.GetBoolFieldValue(field, Aliases2.IsRequired) && _schemaManager.GetStringFieldValue(field, Aliases2.DefaultValue) == null ) || field.Alias == Aliases.Alias; // special case: alias is required in config, but not at runtime fieldElem.MinOccurs = required ? 1 : 0; memberGroup.Items.Add(fieldElem); } }
/// <summary> /// Gets the fields with defaults. /// </summary> /// <param name="type">The type.</param> /// <returns></returns> private IEnumerable <FieldData> GetFieldsWithDefaults(Entity type) { List <FieldData> result; if (!_defaultsOnType.TryGetValue(type, out result)) { Alias defaultValueAlias = Aliases.CoreAlias("defaultValue"); result = (from ancType in SchemaResolver.GetAncestors(type) from field in SchemaResolver.GetDeclaredFields(ancType) let defaultValue = SchemaResolver.GetStringFieldValue(field, defaultValueAlias) where defaultValue != null select new FieldData { Field = field, Value = defaultValue }).ToList( ); _defaultsOnType[type] = result; } return(result); }