private static ModelMetadata ParseModel(DatabaseMetadata database, Type type) { var model = new ModelMetadata { Database = database, CsType = type, CsTypeName = type.Name, Attributes = type.GetCustomAttributes(false) }; model.Properties = type .GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) .Select(x => ParseProperty(x, model)) .Where(x => x.CsName != "EqualityContract") .ToList(); return(model); }
private static IEnumerable <string> DatabaseFileContents(DatabaseMetadata database, string dbName, FileFactorySettings settings) { if (settings.UseCache) { yield return($"{tab}[UseCache]"); } yield return($"{tab}[Name(\"{database.Name}\")]"); yield return($"{tab}public interface {dbName} : IDatabaseModel"); yield return(tab + "{"); foreach (var t in database.Tables.OrderBy(x => x.DbName)) { yield return($"{tab}{tab}DbRead<{t.DbName}> {t.DbName} {{ get; }}"); } yield return(tab + "}"); }
public static DatabaseMetadata ParseDatabase(Type type) { var database = new DatabaseMetadata(type.Name); foreach (var attribute in type.GetCustomAttributes(false)) { if (attribute is NameAttribute nameAttribute) { database.Name = nameAttribute.Name; } if (attribute is UseCacheAttribute useCache) { database.UseCache = useCache.UseCache; } if (attribute is CacheLimitAttribute cacheLimit) { database.CacheLimits.Add((cacheLimit.LimitType, cacheLimit.Amount)); } } database.Models = type .GetProperties(BindingFlags.Instance | BindingFlags.Public) .Select(GetTableType) .Select(x => ParseModel(database, x)) .ToList(); database.Tables = database .Models.Select(ParseTable) .ToList(); database.Relations = ParseRelations(database) .ToList(); return(database); }