示例#1
0
        public void RegisterAssembly(Assembly assembly)
        {
            foreach (var type in assembly.DefinedTypes)
            {
                var attr = type.GetCustomAttributes <DomainDescriptorAttribute>().FirstOrDefault();

                foreach (var property in type.DeclaredProperties)
                {
                    if (property.PropertyType == typeof(DomainDescription))
                    {
                        var attrDomainDescription = property.GetCustomAttribute <DomainDescriptionAttribute>();

                        var domainDescription = property.GetValue(null, null) as DomainDescription;
                        domainDescription.Key = attrDomainDescription.Key;
                        _domains.Add(attrDomainDescription.Key, domainDescription);
                    }
                }
            }

            foreach (var type in assembly.DefinedTypes)
            {
                var attr = type.GetCustomAttributes <EntityDescriptionAttribute>().FirstOrDefault();
                if (attr != null)
                {
                    var entityDescription = EntityDescription.Create(type.AsType(), attr);
                    entityDescription.Domain = _domains[entityDescription.DomainName];
                    _entities.Add(entityDescription);
                    _entitySummaries.Add(EntitySummary.Create(entityDescription));
                }
            }
            _assemblies.Add(assembly);
        }
示例#2
0
        public static DetailResponse <TModel> Create(TModel model)
        {
            var response = new DetailResponse <TModel>();

            response.Model      = model;
            response.FormFields = new List <string>();
            var viewItems = new Dictionary <string, FormField>();
            var attr      = typeof(TModel).GetTypeInfo().GetCustomAttributes <EntityDescriptionAttribute>().FirstOrDefault();
            var entity    = EntityDescription.Create(typeof(TModel), attr);

            if (model is IFormDescriptor)
            {
                response.FormFields = (model as IFormDescriptor).GetFormFields();
            }

            response.Title = entity.Title;
            response.Help  = entity.UserHelp;

            var properties = typeof(TModel).GetRuntimeProperties();

            foreach (var property in properties)
            {
                var fieldAttributes = property.GetCustomAttributes <FormFieldAttribute>();
                if (fieldAttributes.Any())
                {
                    var camelCaseName = property.Name.Substring(0, 1).ToLower() + property.Name.Substring(1);
                    var field         = FormField.Create(camelCaseName, fieldAttributes.First());
                    var defaultValue  = property.GetValue(model);
                    if (defaultValue != null)
                    {
                        field.DefaultValue = defaultValue.ToString();
                    }

                    viewItems.Add(camelCaseName, field);
                }
            }
            response.View = viewItems;
            return(response);
        }