private static IEnumerable<EduHubField> ExpandField(EduHubField Field, int FieldCount) { if (FieldCount < 1) throw new ArgumentOutOfRangeException("FieldCount", "FieldCount should not be less than 1"); if (FieldCount > 99) throw new ArgumentOutOfRangeException("FieldCount", "FieldCount should not be greater than 99"); if (FieldCount != 1) { // Array Field for (int i = 1; i <= FieldCount; i++) { yield return new EduHubField( Entity: Field.Entity, Name: $"{Field.Name}{i:00}", Description: Field.Description, Type: Field.Type, TypeDescription: Field.TypeDescription, TypeMaxLength: Field.TypeMaxLength, IsNullable: Field.IsNullable, IsIdentity: Field.IsIdentity, ForeignParentKey: Field.ForeignParentKey); } } else { yield return Field; } }
internal void AddField(EduHubField Field) { fields.Add(Field); }
private static IEnumerable<EduHubField> ParseFields(EduHubEntity Entity, IEnumerator<string> SchemaIterator) { EduHubField field = null; int fieldArraySize = 0; while (SchemaIterator.MoveNext()) { if (!string.IsNullOrWhiteSpace(SchemaIterator.Current) && !TestFieldIgnore.IsMatch(SchemaIterator.Current)) { var commentMatch = TestFieldComment.Match(SchemaIterator.Current); if (commentMatch.Success) { if (field != null) { field.AppendDescription(commentMatch.Groups[1].Value); } } else { var fieldMatch = TestField.Match(SchemaIterator.Current); if (fieldMatch.Success) { if (field != null) { foreach (var expandedField in ExpandField(field, fieldArraySize)) { yield return expandedField; } } string name = fieldMatch.Groups[1].Value.Trim(); string description = fieldMatch.Groups[6].Success ? fieldMatch.Groups[6].Value.Trim() : string.Empty; fieldArraySize = fieldMatch.Groups[4].Success ? int.Parse(fieldMatch.Groups[4].Value) : 1; string type, typeDescription; int typeMaxLength; DetermineFieldType(fieldMatch.Groups[5].Value.ToUpperInvariant(), out type, out typeDescription, out typeMaxLength); Tuple<string, string> foreignParentKey = fieldMatch.Groups[2].Success ? Tuple.Create(fieldMatch.Groups[2].Value, fieldMatch.Groups[3].Value) : null; field = new EduHubField( Entity: Entity, Name: name, Description: description, Type: type, TypeDescription: typeDescription, TypeMaxLength: typeMaxLength, IsNullable: true, IsIdentity: false, ForeignParentKey: foreignParentKey); } else { if (TestFieldDirective.IsMatch(SchemaIterator.Current)) { // End of Fields Declaration (directives started) break; } else { throw new InvalidOperationException("Unexpected schema format"); } } } } } foreach (var expandedField in ExpandField(field, fieldArraySize)) { yield return expandedField; } }