コード例 #1
0
 public static GettextMetadataProvider InstallGettextMetadataProviderWrapper(ModelMetadataProvider provider = null)
 {
     var impl = provider ?? ModelMetadataProviders.Current;
     var gettext = new GettextMetadataProvider(impl);
     ModelMetadataProviders.Current = gettext;
     return gettext;
 }
コード例 #2
0
        public ModelMetadataProviderProxy(IEnumerable<IVirtualMetadataProvider> virtualProviders, ModelMetadataProvider defaultProvider)
        {
            this.defaultProvider = (defaultProvider ?? new EmptyModelMetadataProvider());

            this._VirtualProviders = new List<IVirtualMetadataProvider>();
            this._VirtualProviders.AddRange(virtualProviders);
        }
コード例 #3
0
ファイル: BaseBinderTest.cs プロジェクト: brocksamson/Evil
        public void Init()
        {
            _httpContext = MockRepository.GenerateMock<HttpContextBase>();
            _requestContext = new RequestContext(_httpContext, new RouteData());
            _controllerContext = new ControllerContext(_requestContext, new FakeController());
            _valueProvider = MockRepository.GenerateMock<IValueProvider>();
            _metadataProvider = MockRepository.GenerateMock<ModelMetadataProvider>();

            _bindingContext = CreateBindingContext(PropertyName, ModelType);
        }
コード例 #4
0
 private static ModelMetadata FromModel(
     ViewDataDictionary viewData,
     ModelMetadataProvider metadataProvider
     )
 {
     return(viewData.ModelMetadata
            ?? GetMetadataFromProvider(
                null,
                typeof(string),
                null,
                null,
                null,
                metadataProvider
                ));
 }
コード例 #5
0
        public ModelMetadata(ModelMetadataProvider provider, Type containerType, Func <object> modelAccessor, Type modelType, string propertyName)
        {
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }
            if (modelType == null)
            {
                throw new ArgumentNullException("modelType");
            }

            Provider = provider;

            _containerType = containerType;
            _isRequired    = !TypeHelpers.TypeAllowsNullValue(modelType);
            _modelAccessor = modelAccessor;
            _modelType     = modelType;
            _propertyName  = propertyName;
        }
コード例 #6
0
        public EasyModelMetaData(ModelMetadataProvider provider, Type containerType, Func<object> modelAccessor, Type modelType, string propertyName)
            : base(provider, containerType, modelAccessor, modelType, propertyName)
        {
            if (containerType != null)
            {
                DataConfigureAttribute custAttribute = DataConfigureAttribute.GetAttribute(containerType);
                if (custAttribute != null)
                {
                    if (custAttribute.MetaData.HtmlTags.ContainsKey(propertyName))
                    {
                        this.HtmlTag = custAttribute.MetaData.HtmlTags[propertyName];

                        this.DisplayFormatString = this.HtmlTag.ValueFormat;
                        if (!string.IsNullOrEmpty(this.HtmlTag.DisplayName))
                        {
                            this.DisplayName = this.HtmlTag.DisplayName;
                        }
                        else
                        {
                            this.DisplayName = this.HtmlTag.Name;
                        }
                        this.EditFormatString = this.HtmlTag.ValueFormat;
                        this.IsReadOnly = this.HtmlTag.IsReadOnly;
                        this.IsRequired = this.HtmlTag.IsRequired;
                        this.Order = this.HtmlTag.OrderIndex;
                        this.ShowForDisplay = this.HtmlTag.IsShowForDisplay;
                        this.ShowForEdit = this.HtmlTag.IsShowForEdit;
                        this.TemplateHint = this.HtmlTag.TemplateName;
                    }
                    if (custAttribute.MetaData.PropertyDataConfig.ContainsKey(propertyName))
                    {
                        this.PropertyData = custAttribute.MetaData.PropertyDataConfig[propertyName];
                    }

                }
            }
        }
コード例 #7
0
ファイル: Query.cs プロジェクト: paultyng/GoogleVisualization
        public Query(Type elementType, string query, ModelMetadataProvider provider)
        {
            if (elementType == null) throw new ArgumentNullException("elementType");
            if (provider == null) throw new ArgumentNullException("provider");

            _elementType = elementType;
            _provider = provider;

            if (string.IsNullOrWhiteSpace(query)) query = string.Empty;

            _originalQuery = query;

            var grammar = new QueryLanguageGrammar();
            var language = new LanguageData(grammar);
            var parser = new Parser(language);
            var tree = parser.Parse(query);

            if (tree.Status == ParseTreeStatus.Parsed)
            {
                AssertEmpty(tree.Root.ChildNodes[2]); //groupBy
                AssertEmpty(tree.Root.ChildNodes[3]); //pivot
                AssertEmpty(tree.Root.ChildNodes[9]); //options

                _limit = ProcessIntNode(tree.Root.ChildNodes[5]);
                _offset = ProcessIntNode(tree.Root.ChildNodes[6]);

                //TODO: when handling pivot, need to rework this
                var metadata = provider.GetMetadataForType((Func<object>)null, elementType);
                var properties = metadata.Properties.ToList();

                if (tree.Root.ChildNodes[0].ChildNodes.Count == 0
                    || (tree.Root.ChildNodes[0].ChildNodes.Count == 2 && tree.Root.ChildNodes[0].ChildNodes[1].Token != null && tree.Root.ChildNodes[0].ChildNodes[1].Token.Value == "*")) //select *
                {
                    //select of all columns of elementType, just a pass through of all the columns
                    _outputType = elementType;
                    _selectStar = true;
                    _columns = MetadataToColumns(properties.OrderBy(p => p.Order));
                }
                else
                {
                    _selectStar = false;

                    //create custom output type unless select contains all columns just reordered...
                    var selectList = tree.Root.ChildNodes[0].ClauseList();

                    if (!selectList.Any(e => !string.Equals(e.Term.Name, "identifier", StringComparison.Ordinal)))
                    {
                        //all identifiers, so just pass through current type for simplicity, no projection, exclude columns on client side
                        _outputType = elementType;

                        var selectListJoin = selectList.Join(properties, i => i.ToPropertyName(), p => p.PropertyName, (i,p) => p).ToList();

                        if (selectListJoin.Count != selectList.Count) throw new QueryParseException("Some of the identifiers passed in the select clause do not exist.");

                        _columns = MetadataToColumns(selectListJoin);
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }

                    //populate columns list
                }

                var labelList = tree.Root.ChildNodes[7].ClauseList();

                var labelListJoin = from l in labelList
                                    join c in _columns on l.ChildNodes[0].ToPropertyName() equals c.Name
                                    select new { l, c };

                foreach (var j in labelListJoin)
                {
                    j.c.Label = (string)j.l.ChildNodes[1].Token.Value;
                }

                var formatList = tree.Root.ChildNodes[8].ClauseList();

                var formatListJoin = from f in formatList
                                     join c in _columns on f.ChildNodes[0].ToPropertyName() equals c.Name
                                     select new { f, c };

                foreach (var j in formatListJoin)
                {
                    j.c.Label = (string)j.f.ChildNodes[1].Token.Value;
                }

                //TODO: handle where
                AssertEmpty(tree.Root.ChildNodes[1]); //where

                var orderByList = tree.Root.ChildNodes[4].ClauseList();

                var orderByListJoin = from o in orderByList
                                      join p in properties on o.ChildNodes[0].ToPropertyName() equals p.PropertyName into propertyGroup
                                      from p in propertyGroup.DefaultIfEmpty()
                                      select new { o, p };

                foreach (var o in orderByListJoin)
                {
                    if (o.p == null) throw new NotImplementedException("Can only order by identifiers.");

                    var ascending = true;

                    if (o.o.ChildNodes.Count == 2)
                    {
                        ascending = !string.Equals((string)o.o.ChildNodes[1].Token.Value, "desc", StringComparison.OrdinalIgnoreCase);
                    }

                    if (_orderBy == null)
                    {
                        if (ascending)
                        {
                            _orderBy = data => data.OrderBy(o.p.PropertyName);
                        }
                        else
                        {
                            _orderBy = data => data.OrderByDescending(o.p.PropertyName);
                        }
                    }
                    else
                    {
                        if (ascending)
                        {
                            _orderBy = data => _orderBy(data.OrderBy(o.p.PropertyName));
                        }
                        else
                        {
                            _orderBy = data => _orderBy(data.OrderByDescending(o.p.PropertyName));
                        }
                    }
                }
            }
            else
            {
                throw new QueryParseException("Query parsing resulted in an error.");
            }
        }
コード例 #8
0
 public GenericsModelMetadataProvider(ModelMetadataProvider delegatingProvider, ModelMetadataMappings mappings = null)
 {
     _delegatingProvider = delegatingProvider;
     _mappings = mappings ?? ConfigurationHolder.MetadataMappings;
 }
コード例 #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ExtendedModelMetadata"/> class.
 /// </summary>
 /// <param name="provider">The provider.</param>
 /// <param name="containerType">Type of the container.</param>
 /// <param name="modelAccessor">The model accessor.</param>
 /// <param name="modelType">Type of the model.</param>
 /// <param name="propertyName">Name of the property.</param>
 /// <param name="metadata">The metadata.</param>
 public ExtendedModelMetadata(ModelMetadataProvider provider, Type containerType, Func<object> modelAccessor, Type modelType, string propertyName, ModelMetadataItem metadata)
     : base(provider, containerType, modelAccessor, modelType, propertyName)
 {
     Metadata = metadata;
 }
コード例 #10
0
 //[SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", Justification = "This is an extension method")]
 internal static MvcHtmlString DisplayNameForInternal <TModel, TValue>(this HtmlHelper <IEnumerable <TModel> > html, Expression <Func <TModel, TValue> > expression, ModelMetadataProvider metadataProvider)
 {
     return(DisplayNameHelper(ModelMetadata.FromLambdaExpression(expression, new ViewDataDictionary <TModel>()),
                              ExpressionHelper.GetExpressionText(expression)));
 }
コード例 #11
0
        internal static ModelMetadata FromLambdaExpression <TParameter, TValue>(Expression <Func <TParameter, TValue> > expression,
                                                                                ViewDataDictionary <TParameter> viewData,
                                                                                ModelMetadataProvider metadataProvider)
        {
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }
            if (viewData == null)
            {
                throw new ArgumentNullException("viewData");
            }

            string propertyName    = null;
            Type   containerType   = null;
            bool   legalExpression = false;

            // Need to verify the expression is valid; it needs to at least end in something
            // that we can convert to a meaningful string for model binding purposes

            switch (expression.Body.NodeType)
            {
            case ExpressionType.ArrayIndex:
                // ArrayIndex always means a single-dimensional indexer; multi-dimensional indexer is a method call to Get()
                legalExpression = true;
                break;

            case ExpressionType.Call:
                // Only legal method call is a single argument indexer/DefaultMember call
                legalExpression = ExpressionHelper.IsSingleArgumentIndexer(expression.Body);
                break;

            case ExpressionType.MemberAccess:
                // Property/field access is always legal
                MemberExpression memberExpression = (MemberExpression)expression.Body;
                propertyName    = memberExpression.Member is PropertyInfo ? memberExpression.Member.Name : null;
                containerType   = memberExpression.Expression.Type;
                legalExpression = true;
                break;

            case ExpressionType.Parameter:
                // Parameter expression means "model => model", so we delegate to FromModel
                return(FromModel(viewData, metadataProvider));
            }

            if (!legalExpression)
            {
                throw new InvalidOperationException(MvcResources.TemplateHelpers_TemplateLimitations);
            }

            TParameter    container     = viewData.Model;
            Func <object> modelAccessor = () =>
            {
                try
                {
                    return(CachedExpressionCompiler.Process(expression)(container));
                }
                catch (NullReferenceException)
                {
                    return(null);
                }
            };

            return(GetMetadataFromProvider(modelAccessor, typeof(TValue), propertyName, container, containerType, metadataProvider));
        }
コード例 #12
0
 /// <summary>
 ///  Construtor
 /// </summary>
 /// <param name="innerProvider">Provedor modificado com as customizações</param>
 public ExtendModelMetadataProvider(ModelMetadataProvider innerProvider)
 {
     _innerProvider = innerProvider;
 }
コード例 #13
0
 public BOVPropertyMetadata(ModelMetadataProvider provider, Type containerType, Func<object> modelAccessor, Type modelType, string propertyName) 
   : base(provider, containerType, modelAccessor, modelType, propertyName)
 {
 }
コード例 #14
0
 public FluentModelMetadata(Metadata metadata , ModelMetadataProvider provider, Func<object> modelAccessor)
     : base(provider, metadata.ContainerType, modelAccessor, metadata.ModelType, metadata.ModelName)
 {
     this.metadata = metadata;
     MetadataMapper.CopyMetadata(metadata,this);
 }
コード例 #15
0
 public GettextMetadataProvider(ModelMetadataProvider implementation)
 {
     if (implementation == null) throw new ArgumentNullException("implementation");
     this.implementation = implementation;
 }
コード例 #16
0
        internal static ModelMetadata FromStringExpression(string expression, ViewDataDictionary viewData, ModelMetadataProvider metadataProvider)
        {
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }
            if (viewData == null)
            {
                throw new ArgumentNullException("viewData");
            }
            if (expression.Length == 0)
            {
                // Empty string really means "model metadata for the current model"
                return(FromModel(viewData, metadataProvider));
            }

            ViewDataInfo  vdi           = viewData.GetViewDataInfo(expression);
            object        container     = null;
            Type          containerType = null;
            Type          modelType     = null;
            Func <object> modelAccessor = null;
            string        propertyName  = null;

            if (vdi != null)
            {
                if (vdi.Container != null)
                {
                    container     = vdi.Container;
                    containerType = vdi.Container.GetType();
                }

                modelAccessor = () => vdi.Value;

                if (vdi.PropertyDescriptor != null)
                {
                    propertyName = vdi.PropertyDescriptor.Name;
                    modelType    = vdi.PropertyDescriptor.PropertyType;
                }
                else if (vdi.Value != null)
                {
                    // We only need to delay accessing properties (for LINQ to SQL)
                    modelType = vdi.Value.GetType();
                }
            }
            else if (viewData.ModelMetadata != null)
            {
                //  Try getting a property from ModelMetadata if we couldn't find an answer in ViewData
                ModelMetadata propertyMetadata = viewData.ModelMetadata.Properties.Where(p => p.PropertyName == expression).FirstOrDefault();
                if (propertyMetadata != null)
                {
                    return(propertyMetadata);
                }
            }

            return(GetMetadataFromProvider(modelAccessor, modelType ?? typeof(string), propertyName, container, containerType, metadataProvider));
        }
コード例 #17
0
 internal static MvcHtmlString DisplayNameInternal(this HtmlHelper html, string expression, ModelMetadataProvider metadataProvider)
 {
     return(DisplayNameHelper(ModelMetadata.FromStringExpression(expression, html.ViewData),
                              expression));
 }
コード例 #18
0
 private static ModelMetadata GetMetadataFromProvider(Func <object> modelAccessor, Type modelType, string propertyName, object container, Type containerType, ModelMetadataProvider metadataProvider)
 {
     metadataProvider = metadataProvider ?? ModelMetadataProviders.Current;
     if (containerType != null && !String.IsNullOrEmpty(propertyName))
     {
         ModelMetadata metadata = metadataProvider.GetMetadataForProperty(modelAccessor, containerType, propertyName);
         if (metadata != null)
         {
             metadata.Container = container;
         }
         return(metadata);
     }
     return(metadataProvider.GetMetadataForType(modelAccessor, modelType));
 }
コード例 #19
0
 internal static MvcHtmlString DisplayNameForInternal <TModel, TValue>(this HtmlHelper <TModel> html, Expression <Func <TModel, TValue> > expression, ModelMetadataProvider metadataProvider)
 {
     return(DisplayNameHelper(ModelMetadata.FromLambdaExpression(expression, html.ViewData),
                              ExpressionHelper.GetExpressionText(expression)));
 }
コード例 #20
0
        public ModelMetadataProviderProxy(IVirtualMetadataProvider virtualProvider, ModelMetadataProvider defaultProvider)
        {
            this.defaultProvider = (defaultProvider ?? new EmptyModelMetadataProvider());

            this.VirtualProviders.Add(virtualProvider);
        }