Пример #1
0
        private static void WriteResource(HttpContext context, StreamWriter writer, TypeMappingConfiguration type)
        {
            var url = context.Request.Url;
            // TODO: find a better way to define when it's local or remote
            var domain  = (context.Request["local"] == "1") ? string.Empty : string.Format("//{0}\\:{1}", url.Host, url.Port);
            var baseUrl = domain + VirtualPathUtility.ToAbsolute("~/");

            writer.WriteLine("ro.factory('{0}', function($resource) {{ return $resource('{1}api/{0}/:id/:methodName/:index', {{id:'@id'}}, {{", type.UnderlineType.PartialName(), baseUrl);
            writer.WriteLine("'all': {method:'GET', isArray:true}, ");
            writer.WriteLine("'get': {method:'GET'}, ");
            writer.WriteLine("'insert': {method:'POST'}, ");
            writer.WriteLine("'update': {method:'PUT'}, ");
            writer.WriteLine("'delete': {method:'DELETE'}, ");

            var typeMapping = ModelMappingManager.MappingFor(type.UnderlineType);

            // write the instance methods
            foreach (var instanceMethod in typeMapping.InstanceMethods)
            {
                WriteMethod(writer, instanceMethod);
            }

            // write the static methods
            foreach (var staticMethod in typeMapping.StaticMethods)
            {
                WriteMethod(writer, staticMethod, true);
            }

            writer.WriteLine("})});");
            writer.WriteLine("");
        }
Пример #2
0
        protected ActionResult DeleteInstanceOf(Type modelType, object key, Func <ActionResult> onSuccess, Func <Exception, ActionResult> onException, Func <ActionResult> onNotFound)
        {
            var mapping = ModelMappingManager.MappingFor(modelType);

            using (var repository = mapping.Configuration.Repository())
            {
                try
                {
                    var descriptor = new ModelDescriptor(ModelMappingManager.MappingFor(modelType));
                    var instance   = repository.Find(GetKeyValues(key, descriptor));

                    if (instance == null)
                    {
                        return(onNotFound());
                    }

                    repository.Remove(instance);
                    repository.SaveChanges();
                }
                catch (Exception ex)
                {
                    HandleException(ex);
                    return(onException(ex));
                }
                return(onSuccess());
            }
        }
Пример #3
0
        protected ActionResult DeleteInstanceOf(Type modelType, object key, Func <ActionResult> onSuccess, Func <Exception, ActionResult> onException, Func <ActionResult> onNotFound)
        {
            using (var context = ModelAssemblies.GetContext(modelType))
            {
                try
                {
                    var set        = context.Set(modelType);
                    var descriptor = new ModelDescriptor(ModelMappingManager.FindByType(modelType));
                    var instance   = set.Find(Convert.ChangeType(key, descriptor.KeyProperty.PropertyType));

                    if (instance == null)
                    {
                        return(onNotFound());
                    }

                    set.Remove(instance);
                    context.SaveChanges();
                }
                catch (Exception ex)
                {
                    HandleException(ex);
                    return(onException(ex));
                }
                return(onSuccess());
            }
        }
Пример #4
0
        public ActionResult Index(Type modelType, int page = 1, int?size = null)
        {
            ViewBag.Exceptions = Exceptions;

            var query = GetQueryById(modelType) ?? GetDefaultQueryOf(modelType);

            return(CacheableView("Index", query, () =>
            {
                var items = query.Execute(true);
                var count = items.Count();
                var quantity = size.HasValue ? size.Value : query.Paging ? query.PageSize : count;
                var fetched = items.Skip((page - 1) * quantity).Take(quantity);

                var mapping = ModelMappingManager.MappingFor(fetched.ElementType);
                var descriptor = new ModelDescriptor(mapping);

                return new ModelCollection(modelType, descriptor, fetched)
                {
                    PageCount = quantity > 0 ? (int)Math.Ceiling((decimal)count / quantity) : count,
                    PageNumber = page,
                    PageSize = quantity
                };
            },
                                 settings => settings.VaryByParam = "page;size"));
        }
Пример #5
0
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            var modelType  = ModelBinders.Binders[typeof(Type)].BindModel(controllerContext, bindingContext) as Type;
            var index      = int.Parse(controllerContext.RouteData.Values["index"].ToString());
            var actionName = (string)controllerContext.RouteData.Values["action"];

            var mapping = GetMethodMapping(controllerContext, modelType, actionName, index);

            var method = new Method(new MethodDescriptor(mapping, controllerContext.GetActionDescriptor(actionName)));

            foreach (var parameter in method.Parameters)
            {
                var result = bindingContext.ValueProvider.GetValue(parameter.Name);
                if (result != null)
                {
                    if (!parameter.IsModel)
                    {
                        parameter.Value = result.ConvertTo(parameter.MemberType);
                    }
                    else
                    {
                        var context    = ModelAssemblies.GetContext(parameter.MemberType);
                        var descriptor = new ModelDescriptor(ModelMappingManager.FindByType(parameter.MemberType));
                        var value      = result.ConvertTo(descriptor.KeyProperty.PropertyType);
                        parameter.Value = context.Set(parameter.MemberType).Find(value);
                    }
                }
            }
            return(method);
        }
Пример #6
0
        public ActionResult Execute(Type modelType, string methodName, int index, string key = null)
        {
            var typeMapping = ModelMappingManager.FindByType(modelType);
            var methods     = key != null ? typeMapping.InstanceMethods : typeMapping.StaticMethods;
            var mapping     = methods.FirstOrDefault(m => m.MethodName.Equals(methodName, StringComparison.InvariantCultureIgnoreCase) && m.Index == index);

            if (mapping == null)
            {
                throw new RunningObjectsException(string.Format("No method found with name {2} at index {0} for type {1}", index, modelType.PartialName(), methodName));
            }

            var method = new Method(new MethodDescriptor(mapping, ControllerContext.GetActionDescriptor(RunningObjectsAction.Execute)));

            return(method.Parameters.Any()
                       ? View(method)
                       : ExecuteMethodOf
                   (
                       modelType,
                       method,
                       () => OnSuccess(modelType)(null),
                       OnSuccessWithReturn(method),
                       OnException(method),
                       HttpNotFound,
                       key
                   ));
        }
Пример #7
0
        private static MethodMapping GetMappingFor(Type type, MethodBase method, string methodName, int index)
        {
            var typeMapping = ModelMappingManager.MappingFor(type);
            var methods     = typeMapping.StaticMethods;

            return(methods.FirstOrDefault(m => m.Method == method && m.MethodName == methodName && m.Index == index));
        }
Пример #8
0
        protected ActionResult EditInstanceOf(Type modelType, Model model, Func <object, ActionResult> onSuccess, Func <Exception, ActionResult> onException, Func <ActionResult> onNotFound)
        {
            var mapping = ModelMappingManager.MappingFor(modelType);

            using (var repository = mapping.Configuration.Repository())
            {
                try
                {
                    if (model.Instance == null)
                    {
                        return(onNotFound());
                    }

                    var updated = repository.Update(model.Instance);
                    if (updated == null)
                    {
                        return(onNotFound());
                    }

                    repository.SaveChanges();
                    return(onSuccess(updated));
                }
                catch (Exception ex)
                {
                    HandleException(ex);
                    return(onException(ex));
                }
            }
        }
Пример #9
0
        protected object ParseResult(Method model, object @return)
        {
            if (@return != null)
            {
                var method = model.Descriptor.Method as MethodInfo;
                if (method != null && method.ReturnType != typeof(void))
                {
                    var collectionType = method.ReturnType.GetInterface("IEnumerable`1");
                    if (collectionType != null)
                    {
                        var returnType = collectionType.GetGenericArguments()[0];
                        if (returnType != null && ModelMappingManager.Exists(returnType))
                        {
                            var mapping    = ModelMappingManager.MappingFor(returnType);
                            var descriptor = new ModelDescriptor(mapping);
                            return(new ModelCollection(returnType, descriptor, (IEnumerable)@return));
                        }
                    }

                    if (method.ReturnType == typeof(Redirect))
                    {
                        return(@return);
                    }
                }
            }
            return(null);
        }
Пример #10
0
        protected Query.Query GetDefaultQueryOf(Type modelType)
        {
            var mapping = ModelMappingManager.MappingFor(modelType);
            var source  = mapping.Configuration.Repository().All();

            return(QueryParser.Parse(modelType, source));
        }
Пример #11
0
        internal static object GetModelValue(ValueProviderResult result, Type memberType)
        {
            var memberMapping = ModelMappingManager.MappingFor(memberType);
            var descriptor    = new ModelDescriptor(memberMapping);
            var value         = result.ConvertTo(descriptor.KeyProperty.PropertyType);

            return(memberMapping.Configuration.Repository().Find(value));
        }
Пример #12
0
        protected Query.Query GetQueryById(Type modelType)
        {
            var mapping = ModelMappingManager.MappingFor(modelType);
            var source  = mapping.Configuration.Repository().All();

            return(source != null
                ? QueryParser.Parse(modelType, source, Request["q"])
                : QueryParser.Empty(modelType));
        }
Пример #13
0
        public static IRepository <T> Repository <T>(this Type type) where T : class
        {
            var mapping = ModelMappingManager.MappingFor(type);

            if (mapping != null)
            {
                return(mapping.Configuration.Repository() as IRepository <T>);
            }
            return(null);
        }
Пример #14
0
        private static MethodMapping GetMethodMapping(ControllerContext controllerContext, Type modelType, int index)
        {
            var values        = controllerContext.RouteData.Values;
            var methodName    = values["methodName"].ToString();
            var typeMapping   = ModelMappingManager.MappingFor(modelType);
            var methods       = values.ContainsKey("key") ? typeMapping.InstanceMethods : typeMapping.StaticMethods;
            var methodsOfName = methods.Where(m => m.MethodName.Equals(methodName, StringComparison.InvariantCultureIgnoreCase));

            return(methodsOfName.FirstOrDefault(m => m.Index == index));
        }
Пример #15
0
        private IQueryable GetAppliedQuery()
        {
            if (Source != null)
            {
                if (Filter != null)
                {
                    Source = Filter.Apply(Source);
                }

                if (Where != null)
                {
                    RunningObjectsSetup.Configuration.Query.ParseKeywords(this);
                    Source = (Parameters != null && Parameters.Any())
                                 ? Source.Where(Where.Expression, Parameters)
                                 : Source.Where(Where.Expression);
                }

                if (OrderBy != null && OrderBy.Elements.Any())
                {
                    var orderBy = OrderBy.Elements.Aggregate(string.Empty, (current, element) => current + (element.Key + " " + element.Value + ","));
                    Source = Source.OrderBy(orderBy.Substring(0, orderBy.Length - 1));
                }
                else
                {
                    var mapping    = ModelMappingManager.MappingFor(ModelType);
                    var descriptor = new ModelDescriptor(mapping);

                    if (descriptor.Properties.Any())
                    {
                        var orderedProperty = descriptor.KeyProperty ??
                                              (descriptor.TextProperty ?? descriptor.Properties.FirstOrDefault());
                        if (orderedProperty != null)
                        {
                            Source = Source.OrderBy(orderedProperty.Name + " Asc");
                        }
                    }
                }

                if (Skip.HasValue)
                {
                    Source = Source.Skip(Skip.Value);
                }

                if (Take.HasValue)
                {
                    Source = Source.Take(Take.Value);
                }

                if (Select != null && Select.Properties.Any())
                {
                    Source = Source.Select(string.Format("new({0})", Select));
                }
            }
            return(Source);
        }
        public virtual ActionResult View(Type modelType, object key)
        {
            var mapping    = ModelMappingManager.FindByType(modelType);
            var descriptor = new ModelDescriptor(mapping);
            var instance   = GetInstanceOf(modelType, key, descriptor);

            if (instance == null)
            {
                return(HttpNotFound());
            }
            return(Json(instance, JsonRequestBehavior.AllowGet));
        }
Пример #17
0
        public ActionResult Edit(Type modelType, object key)
        {
            var mapping    = ModelMappingManager.FindByType(modelType);
            var descriptor = new ModelDescriptor(mapping);
            var instance   = GetInstanceOf(modelType, key, descriptor);

            if (instance == null)
            {
                return(HttpNotFound());
            }
            return(View(new Model(modelType, descriptor, instance)));
        }
        private void ApplyPolicies(ActionExecutingContext filterContext, ISecurityPolicyContainer <object> container)
        {
            var context = new SecurityPolicyContext
            {
                ControllerContext = filterContext.Controller.ControllerContext
            };

            if (Builder.IsAuthenticationConfigured)
            {
                var authentication = Builder.Authentication <Object>();
                context.IsAuthenticated  = authentication.IsAuthenticated();
                context.CurrentUserRoles = authentication.GetRoles();
            }

            if (container.Policies.Any(policy => !policy.Authorize(context)))
            {
                if (Builder.IsAuthenticationConfigured)
                {
                    var authentication = Builder.Authentication <Object>();
                    if (!authentication.IsAuthenticated())
                    {
                        var mapping = ModelMappingManager.MappingFor(authentication.Type);
                        var method  = mapping.StaticMethods.FirstOrDefault(m => m.Name == authentication.LoginWith().Name);
                        if (method != null)
                        {
                            var route = new
                            {
                                action     = "Execute",
                                controller = "Presentation",
                                methodName = method.MethodName,
                                index      = method.Index,
                                modelType  = mapping.ModelType.PartialName(),
                                redirectTo = filterContext.HttpContext.Request.Url.ToString()
                            };
                            filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(route));
                        }
                        else
                        {
                            filterContext.Result = new HttpNotFoundResult();
                        }
                    }
                    else
                    {
                        filterContext.Result = new HttpNotFoundResult();
                    }
                }
                else
                {
                    filterContext.Result = new HttpUnauthorizedResult();
                }
            }
        }
Пример #19
0
        public ActionResult Edit(Type modelType, object key)
        {
            var mapping    = ModelMappingManager.MappingFor(modelType);
            var descriptor = new ModelDescriptor(mapping);
            var instance   = GetInstanceOf(modelType, key, descriptor);

            if (instance == null)
            {
                return(HttpNotFound());
            }
            var model = new Model(modelType, descriptor, instance);

            return(!IsChildAction ? (ActionResult)View(model) : PartialView(model));
        }
Пример #20
0
        public ActionResult Create(Type modelType, int index)
        {
            var typeMapping = ModelMappingManager.FindByType(modelType);
            var mapping     = typeMapping.Constructors.FirstOrDefault(m => m.Index == index);

            if (mapping == null)
            {
                throw new RunningObjectsException(string.Format("No constructor found at index {0} for type {1}", index, modelType.PartialName()));
            }

            var descriptor = new MethodDescriptor(mapping, ControllerContext.GetActionDescriptor(RunningObjectsAction.Create));

            return(View(new Method(descriptor)));
        }
Пример #21
0
        public static IEnumerable <SelectListItem> GetSelectListItems(this Member member, ControllerContext controllerContext, object selectedValue)
        {
            var items = new List <SelectListItem> {
                new SelectListItem()
            };

            if (member.IsModel)
            {
                var actionName = controllerContext.RouteData.Values["action"].ToString();
                var action     = (RunningObjectsAction)Enum.Parse(typeof(RunningObjectsAction), actionName);
                var result     = member.Query(controllerContext).Execute();

                var mapping           = ModelMappingManager.MappingFor(result.ElementType);
                var elementDescriptor = new ModelDescriptor(mapping);
                foreach (object item in result)
                {
                    var listItem = new SelectListItem();
                    var value    = elementDescriptor.KeyProperty.GetValue(item);
                    listItem.Value = value != null?value.ToString() : item.ToString();

                    if (elementDescriptor.TextProperty != null)
                    {
                        var textProperty = elementDescriptor.TextProperty.GetValue(item);
                        if (textProperty != null)
                        {
                            listItem.Text = textProperty.ToString();
                        }
                    }
                    else
                    {
                        var boxed = item;
                        listItem.Text = boxed == null ? string.Empty : boxed.ToString();
                    }

                    if (selectedValue != null)
                    {
                        var descriptor = new ModelDescriptor(ModelMappingManager.FindByType(member.MemberType));
                        var modelValue = descriptor.KeyProperty.GetValue(selectedValue);
                        if (modelValue != null)
                        {
                            listItem.Selected = listItem.Value == modelValue.ToString();
                        }
                    }

                    items.Add(listItem);
                }
            }
            return(items);
        }
Пример #22
0
        private IQueryable GetAppliedQuery()
        {
            if (Where != null)
            {
                Source = (Parameters != null && Parameters.Count() > 0)
                    ? Source.Where(Where.Expression, Parameters)
                    : Source.Where(Where.Expression);
            }

            if (OrderBy != null && OrderBy.Elements.Any())
            {
                var orderBy = string.Empty;
                foreach (var element in OrderBy.Elements)
                {
                    orderBy += element.Key + " " + element.Value + ",";
                }
                Source = Source.OrderBy(orderBy.Substring(0, orderBy.Length - 1));
            }
            else
            {
                var mapping    = ModelMappingManager.FindByType(ModelType);
                var descriptor = new ModelDescriptor(mapping);
                Source = Source.OrderBy(descriptor.KeyProperty.Name + " Asc");
            }


            if (Skip != null)
            {
                Source = Source.Skip(Skip.Value);
            }

            if (Take != null)
            {
                Source = Source.Take(Take.Value);
            }

            if (!string.IsNullOrEmpty(Include))
            {
                Source = Source.Include(Include);
            }

            var data = (Select != null && Select.Properties.Any())
                           ? Source.Select(string.Format("new({0})", Select))
                           : Source;

            return(data);
        }
Пример #23
0
        private static void RenderMethod(HtmlHelper htmlHelper, Type modelType, MethodBase method, object key = null)
        {
            var typeMapping = ModelMappingManager.MappingFor(modelType);
            var methods     = method.IsConstructor
                              ? typeMapping.Constructors
                              : method.IsStatic
                                    ? typeMapping.StaticMethods
                                    : typeMapping.InstanceMethods;

            var methodMapping = methods.FirstOrDefault(m => m.Method == method);

            if (methodMapping == null)
            {
                throw new ArgumentNullException(string.Format("The method {0} was not found in type {1}.", method.Name, typeMapping.Name));
            }
            htmlHelper.RenderAction(methodMapping.UnderlineAction.ToString(), "Presentation", LinkExtensions.GetRouteValues(method, key, methodMapping, typeMapping));
        }
Пример #24
0
        protected ActionResult ExecuteMethodOf(Type modelType, Method model, Func <ActionResult> onSuccess, Func <object, ActionResult> onSuccessWithReturn, Func <Exception, ActionResult> onException, Func <ActionResult> onNotFound, string key = null)
        {
            using (var context = ModelAssemblies.GetContext(modelType))
            {
                try
                {
                    object @return;
                    if (!model.Descriptor.Method.IsStatic)
                    {
                        var descriptor = new ModelDescriptor(ModelMappingManager.FindByType(modelType));
                        var set        = context.Set(modelType);
                        var instance   = set.Find(Convert.ChangeType(key, descriptor.KeyProperty.PropertyType));

                        if (instance == null)
                        {
                            return(onNotFound());
                        }

                        @return = model.Invoke(instance);
                        context.SaveChanges();

                        if (@return == instance)
                        {
                            @return = null;
                        }
                    }
                    else
                    {
                        @return = model.Invoke(null);
                    }

                    if (@return != null)
                    {
                        return(onSuccessWithReturn(@return));
                    }
                }
                catch (Exception ex)
                {
                    HandleException(ex);
                    return(onException(ex));
                }

                return(onSuccess());
            }
        }
Пример #25
0
        public static IEnumerable <SelectListItem> GetSelectListItems(this Member member, IQueryable source, object selectedValue)
        {
            var items = new List <SelectListItem> {
                new SelectListItem()
            };

            if (member.IsModel)
            {
                var mapping           = ModelMappingManager.MappingFor(source.ElementType);
                var elementDescriptor = new ModelDescriptor(mapping);
                foreach (object item in source)
                {
                    var listItem = new SelectListItem();
                    var value    = elementDescriptor.KeyProperty.GetValue(item);
                    listItem.Value = value != null?value.ToString() : item.ToString();

                    if (elementDescriptor.TextProperty != null)
                    {
                        var textProperty = elementDescriptor.TextProperty.GetValue(item);
                        if (textProperty != null)
                        {
                            listItem.Text = textProperty.ToString();
                        }
                    }
                    else
                    {
                        var boxed = item;
                        listItem.Text = boxed == null ? string.Empty : boxed.ToString();
                    }

                    if (selectedValue != null)
                    {
                        var descriptor = new ModelDescriptor(ModelMappingManager.MappingFor(member.MemberType));
                        var modelValue = descriptor.KeyProperty.GetValue(selectedValue);
                        if (modelValue != null)
                        {
                            listItem.Selected = listItem.Value == modelValue.ToString();
                        }
                    }

                    items.Add(listItem);
                }
            }
            return(items);
        }
Пример #26
0
        public static ModelCollection ToModelCollection(this Member member)
        {
            if (member.IsModelCollection)
            {
                var model = member.UnderliningModel;

                var items = (member.Value != null)
                                ? ((IEnumerable)member.Value)
                                : ((IEnumerable)Activator.CreateInstance(typeof(List <>).MakeGenericType(member.UnderliningModel.ModelType)));

                var attr   = member.Attributes.OfType <QueryAttribute>().FirstOrDefault();
                var result = QueryParser.Parse(model.ModelType, items.AsQueryable(), attr).Execute(true);

                var type       = result != null ? result.ElementType : model.ModelType;
                var descriptor = new ModelDescriptor(ModelMappingManager.MappingFor(type));
                return(new ModelCollection(type, descriptor, result));
            }
            return(null);
        }
Пример #27
0
 protected ActionResult CreateInstanceOf(Type modelType, Method method, Func <object, ActionResult> onSuccess, Func <Exception, ActionResult> onException)
 {
     try
     {
         var mapping = ModelMappingManager.MappingFor(modelType);
         using (var repository = mapping.Configuration.Repository())
         {
             var instance = method.Invoke(null);
             repository.Add(instance);
             repository.SaveChanges();
             return(onSuccess(instance));
         }
     }
     catch (Exception ex)
     {
         HandleException(ex);
         return(onException(ex));
     }
 }
Пример #28
0
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            var modelType = ModelBinders.Binders[typeof(Type)].BindModel(controllerContext, bindingContext) as Type;

            var key        = controllerContext.RouteData.Values["key"];
            var mapping    = ModelMappingManager.FindByType(modelType);
            var descriptor = new ModelDescriptor(mapping);

            using (var context = ModelAssemblies.GetContext(modelType))
            {
                var set      = context.Set(modelType);
                var instance = set.Find(Convert.ChangeType(key, descriptor.KeyProperty.PropertyType));

                var model = new Model(modelType, descriptor, instance);
                foreach (var property in model.Properties)
                {
                    var result = bindingContext.ValueProvider.GetValue(property.Name);
                    if (result != null)
                    {
                        if (!property.IsModel)
                        {
                            var converter = TypeDescriptor.GetConverter(property.MemberType);
                            var value     = property.MemberType == typeof(Boolean)
                                            ? result.AttemptedValue.Split(',')[0]
                                            : result.AttemptedValue;

                            property.Value = converter.ConvertFrom(null, CultureInfo.CurrentCulture, value);
                        }
                        else
                        {
                            var propertyTypeMapping = ModelMappingManager.FindByType(property.MemberType);
                            var propertyDescriptor  = new ModelDescriptor(propertyTypeMapping);
                            var propertyValue       = result.ConvertTo(propertyDescriptor.KeyProperty.PropertyType);
                            property.Value = context.Set(property.MemberType).Find(propertyValue);
                        }
                    }
                }
                context.Entry(model.Instance).State = EntityState.Detached;
                return(model);
            }
        }
Пример #29
0
        private static object CreateItem(ModelBindingContext bindingContext, Property property, ValueProviderResult result, int index)
        {
            var item = GetModelValue(result, property.UnderliningModel.ModelType)
                       ?? Activator.CreateInstance(property.UnderliningModel.ModelType);

            var propertyDescriptor = new ModelDescriptor(ModelMappingManager.MappingFor(property.UnderliningModel.ModelType));
            var propertyModel      = new Model(property.UnderliningModel.ModelType, propertyDescriptor, item);

            foreach (var itemProperty in propertyModel.Properties)
            {
                var itemPropertyName = string.Format("{0}[{1}].{2}", property.Name, index, itemProperty.Name);
                var itemResult       = bindingContext.ValueProvider.GetValue(itemPropertyName);
                if (itemResult != null)
                {
                    itemProperty.Value = !itemProperty.IsModel
                                             ? GetNonModelValue(itemResult, itemProperty.MemberType)
                                             : GetModelValue(itemResult, itemProperty.MemberType);
                }
            }
            return(item);
        }
Пример #30
0
        private static Select ParseSelect(Type modelType, QueryAttribute spec)
        {
            var select     = new Select();
            var descriptor = new ModelDescriptor(ModelMappingManager.FindByType(modelType));
            var properties = descriptor.GetProperties().OfType <PropertyDescriptor>();

            select.Properties.AddRange(properties);
            if (!string.IsNullOrEmpty(spec.Select))
            {
                select.Properties.Clear();
                var propertyNames = spec.Select.Split(Select.Separator);
                foreach (var propertyName in propertyNames)
                {
                    var property = properties.FirstOrDefault(p => p.Name == propertyName);
                    if (property != null)
                    {
                        select.Properties.Add(property);
                    }
                }
            }
            return(select);
        }