internal ModelDetail(TypeDetail typeDetails) { this.Type = typeDetails.Type; while (typeDetails.InnerTypes.Count == 1) { this.Type = typeDetails.InnerTypes[0]; typeDetails = typeDetails.InnerTypeDetails[0]; } var sourceEntityAttribute = typeDetails.Attributes.Select(x => x as EntityAttribute).Where(x => x != null).FirstOrDefault(); this.IsDataSourceEntity = sourceEntityAttribute != null; if (this.IsDataSourceEntity) { this.DataSourceEntityName = sourceEntityAttribute.StoreName; if (String.IsNullOrWhiteSpace(this.DataSourceEntityName)) { this.DataSourceEntityName = this.Type.Name; } if (!this.DataSourceEntityName.All(x => char.IsLetterOrDigit(x) || x == '_' || x == '`')) { throw new ArgumentException(String.Format("{0}.{1}={2}", nameof(EntityAttribute), nameof(EntityAttribute.StoreName), this.DataSourceEntityName)); } } var modelProperties = new List <ModelPropertyDetail>(); foreach (var member in typeDetails.MemberDetails) { var notSourcePropertyAttribute = member.Attributes.Select(x => x as StoreExcludeAttribute).Where(x => x != null).FirstOrDefault(); if (notSourcePropertyAttribute == null) { var modelPropertyInfo = new ModelPropertyDetail(member, this.IsDataSourceEntity); modelProperties.Add(modelPropertyInfo); } } this.Name = typeDetails.Type.Name; this.Properties = modelProperties.ToArray(); this.propertiesByName = this.Properties.ToDictionary(x => x.Name); this.propertiesByNameLower = this.Properties.ToDictionary(x => x.Name.ToLower()); this.IdentityProperties = this.Properties.Where(x => x.IsIdentity).ToArray(); this.IdentityAutoGeneratedProperties = this.Properties.Where(x => x.IsIdentity && x.IsIdentityAutoGenerated).ToArray(); this.RelatedProperties = this.Properties.Where(x => x.IsRelated).ToArray(); this.RelatedEnumerableProperties = this.Properties.Where(x => x.IsRelated && x.IsEnumerable).ToArray(); this.RelatedNonEnumerableProperties = this.Properties.Where(x => x.IsRelated && !x.IsEnumerable).ToArray(); this.NonAutoGeneratedNonRelationProperties = this.Properties.Where(x => !x.IsIdentityAutoGenerated && !x.IsRelated).ToArray(); this.Creator = typeDetails.Creator; if (this.Creator == null) { throw new Exception($"{Type.Name} must have a parameterless constructor to be a model."); } }
public bool TryGetPropertyLower(string name, out ModelPropertyDetail property) { return(this.propertiesByNameLower.TryGetValue(name, out property)); }