Commit Graph

9 Commits

Author SHA1 Message Date
Ryan Nowak 90cef3b9ca Refactor of the model metadata provider
Separates the MMP into two phases:
1). Creation of the ModelMetadata, discovery of properties and attributes
(reflection) is part of the MMP
2). Lookup of details based on attributes is now part of another phase,
and has its results cached.

Users can now implements and register an IFooMetadataProvider to customize
a single aspect of metadata (see how data annotations does it).
2015-03-05 13:19:10 -08:00
Ryan Nowak 9d5364cf9b Removing ModelMetadata.Model 2015-02-23 19:56:59 -08:00
Doug Bunting 8eb63271b5 Make HTML helper parameter names consistent
- #944
- name `string` expression name and `Expression<Func<TModel, TResult>>`
  parameters "expression"
 - single special case is `GenerateIdFromName(string fullName)` since every
   other expression name is relative to the current
   `ViewData,TemplateInfo.HtmlFieldPrefix` value
 - applied from `IHtmlHelper` and `IHtmlGenerator` on up
- name `IHtmlHelper` and `IHtmlHelper<TModel>` parameters "htmlHelper"
- rename `TProperty` and `TValue` type parameters to `TResult`

nits:
- clean up abbreviated names in `CachedExpressionCompiler`
- change `ObjectToDictionary()`'s parameter name to `value`
- use `nameof` more to make renaming (and refactoring) easier in the future
- rewrap parameters and arguments to avoid long lines and orphans
2015-02-17 17:53:53 -08:00
Ryan Nowak 7c961e3ce8 TODO removal
For each of these TODOs:

- If there's an active bug tracking the work, and the TODO provides
  something of value, I left it and standardized the formatting. I also
  added comments to the bug.

- If the comment provided no value (implement feature X when we do feature
  X), I deleted it with impunity.

- If the comment was stale (won't fix or just out of date), then we
  removed it uncerimoniously.

There was a single TODO that was actually actionable, so I enabled that
test.
2014-11-20 15:01:35 -08:00
Doug Bunting c89bca5924 Adjust tests to handle new `ViewDataDictionary` invariants
- ensure `ViewDataDictionary` constructors are not passed a `null` or
  `Mock.Of<IModelMetadataProvider>()` instance
 - `ViewDataDictionary` constructors always use the `IModelMetadataProvider`
- `viewData.ModelMetadata` now never `null`
- `ViewDataDictionary<int>.Model` no longer throws if read before it's written
- `ViewDataDictionary.ModelMetadata` now copied to new instances in fewer cases
 - e.g. don't use unusual `object` datatype with customized `ModelMetadata`
2014-10-29 19:18:59 -07:00
Doug Bunting dd5da33a62 Sanitize "id" attributes for HTML 4.0.1
- #704 part 2 of 2
- change `@Html.Id()` to sanitize return value; was identical to `@Html.Name()`

Copied `TagBuilder.CreateSanitizedId()` and `TagBuilder.Html401IdUtil` from MVC 5.2
- except this `CreateSanitizedId()` returns a valid identifier if first `char` is not a letter
 - e.g. "[0].Name"

nits:
- expand variable names, use lots of `var`, put `public` members first
- add doc comments for `CreateSanitizedId()`

Note users will be able to apply different sanitization once we fix #1188.
2014-10-17 16:12:45 -07:00
dougbu 56d66c090e Make HTML helper `null` handling consistent
- #874 lines 3, 4, and 6
- correct `Value()` to treat a `null` expression name the same as `string.Empty`
- add missing `[NotNull]` attributes in `EditorExtensions` and for `GenerateIdFromName()`
- consistently pass `null` for default expression names to the helpers
 - for example, from extension methods
- add test cases using `null` for expression name

nits:
- correct summary XML comment for `HtmlHelper` class
- use named parameters and prefer interface (not extension) methods in changed calls
- use `string.Empty` instead of `""` in a few tests
2014-08-06 16:04:56 -07:00
dougbu 126ee116cf Remove useless `.ToString()` calls in tests 2014-08-01 21:06:23 -07:00
dougbu 3746e44dc3 Add more `ModelMetadata` and HTML helper tests
- add `CachedDataAnnotationsMetadataAttributesTest`
- add `CachedDataAnnotationsModelMetadataTest`
- confirm more default property values in `ModelMetadataTest`
- confirm use of `DisplayName` in `ModelMetadataTest`
- add `HtmlHelperDisplayNameExtensionsTest`
- add `HtmlHelperLabelExtensionsTest`
- add `HtmlHelperNameExtensionsTest`
2014-07-24 18:32:35 -07:00