Example #1
0
        MetaEntity CreateMetaEntity(EntityEntry descriptor)
        {
            var entityType      = descriptor.ClrType;
            var entityAttribute = entityType.GetCustomAttribute <EntityAttribute>() ?? throw new InvalidOperationException();
            var displayName     = entityType.GetCustomAttribute <DisplayNameAttribute>()?.DisplayName ?? entityAttribute.Name;
            var entity          = new MetaEntity()
            {
                Name        = entityAttribute.Name,
                EntityType  = _entityTypes.First(), //TODO FIXME
                DisplayName = displayName,
                ClrType     = entityType,
                Feature     = descriptor.Feature,
                Attributes  = entityType.GetCustomAttributes(),
            };

            var propFilter = BindingFlags.Public
                             | BindingFlags.FlattenHierarchy
                             | BindingFlags.Instance
                             | BindingFlags.GetProperty
                             | BindingFlags.SetProperty;
            var props = descriptor.ClrType.GetProperties(propFilter).
                        Where(x => x.CanRead && x.CanWrite);

            foreach (var propertyInfo in props)
            {
                var metaField = this.LoadPropertyByClr(propertyInfo, _fieldTypes);
                metaField.Entity     = entity;
                metaField.Attributes = propertyInfo.GetCustomAttributes(true).Where(x => x is Attribute).Cast <Attribute>();
                entity.Fields.Add(metaField.Name, metaField);
            }
            return(entity);
        }
 public virtual void VisitEntity(MetaEntity entity)
 {
 }