Skip to content

Commit

Permalink
ModelMetadata.GroupName
Browse files Browse the repository at this point in the history
  • Loading branch information
maxtoroq committed Apr 12, 2017
1 parent fab1521 commit 184cf25
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 28 deletions.
13 changes: 0 additions & 13 deletions src/Xcst.AspNet/Compilation/xcst-app.xsl
Expand Up @@ -798,19 +798,6 @@
</if>
</template>

<template match="c:member" mode="src:display-attribute">
<next-match/>
<if test="@group">
<call-template name="src:line-hidden"/>
<call-template name="src:new-line-indented"/>
<text>[</text>
<value-of select="src:global-identifier('System.Web.Mvc.AdditionalMetadata')"/>
<text>("GroupName", </text>
<value-of select="src:verbatim-string(@group)"/>
<text>)]</text>
</if>
</template>

<template match="a:display-name" mode="src:extension-instruction">

<call-template name="xcst:validate-attribs">
Expand Down
20 changes: 20 additions & 0 deletions src/Xcst.AspNet/Framework/CachedModelMetadata.cs
Expand Up @@ -36,6 +36,7 @@ abstract class CachedModelMetadata<TPrototypeCache> : ModelMetadata {
bool _showForEdit;
string _templateHint;
string _watermark;
string _groupName;

bool _convertEmptyStringToNullComputed;
bool _dataTypeNameComputed;
Expand All @@ -55,6 +56,7 @@ abstract class CachedModelMetadata<TPrototypeCache> : ModelMetadata {
bool _showForEditComputed;
bool _templateHintComputed;
bool _watermarkComputed;
bool _groupNameComputed;

public sealed override bool ConvertEmptyStringToNull {
get {
Expand Down Expand Up @@ -319,6 +321,20 @@ abstract class CachedModelMetadata<TPrototypeCache> : ModelMetadata {
}
}

public sealed override string GroupName {
get {
if (!_groupNameComputed) {
_groupName = ComputeGroupName();
_groupNameComputed = true;
}
return _groupName;
}
set {
_groupName = value;
_groupNameComputed = true;
}
}

// Constructor for creating real instances of the metadata class based on a prototype

protected CachedModelMetadata(CachedModelMetadata<TPrototypeCache> prototype, Func<object> modelAccessor)
Expand Down Expand Up @@ -411,6 +427,10 @@ protected CachedModelMetadata(/*CachedDataAnnotations*/ModelMetadataProvider pro
return base.Watermark;
}

protected virtual string ComputeGroupName() {
return base.GroupName;
}

protected sealed override string GetSimpleDisplayText() {
// Rename for consistency
return ComputeSimpleDisplayText();
Expand Down
Expand Up @@ -228,6 +228,13 @@ public CachedDataAnnotationsModelMetadata(CachedDataAnnotationsModelMetadataProv
: base.ComputeWatermark();
}

protected override string ComputeGroupName() {

return (this.PrototypeCache.Display != null) ?
this.PrototypeCache.Display.GetGroupName()
: base.ComputeGroupName();
}

static void ValidateDisplayColumnAttribute(DisplayColumnAttribute displayColumnAttribute, PropertyInfo displayColumnProperty, Type modelType) {

if (displayColumnProperty == null) {
Expand Down
Expand Up @@ -118,10 +118,12 @@ class DataAnnotationsModelMetadataProvider : AssociatedMetadataProvider {
string name = null;

if (display != null) {

result.Description = display.GetDescription();
result.ShortDisplayName = display.GetShortName();
result.Watermark = display.GetPrompt();
result.Order = display.GetOrder() ?? ModelMetadata.DefaultOrder;
result.GroupName = display.GetGroupName();

name = display.GetName();
}
Expand Down
2 changes: 2 additions & 0 deletions src/Xcst.AspNet/Framework/ModelMetadata.cs
Expand Up @@ -197,6 +197,8 @@ public class ModelMetadata {

public virtual string Watermark { get; set; }

public virtual string GroupName { get; set; }

[SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Justification = "This is an appropriate nesting of generic types")]
public static ModelMetadata FromLambdaExpression<TParameter, TValue>(Expression<Func<TParameter, TValue>> expression, ViewDataDictionary<TParameter> viewData) {
return FromLambdaExpression(expression, viewData, metadataProvider: null);
Expand Down
11 changes: 0 additions & 11 deletions src/Xcst.AspNet/Mvc/ModelMetadataExtensions.cs
Expand Up @@ -24,17 +24,6 @@ public static class ModelMetadataExtensions {

const string MemberTemplateKey = "__xcst_member_template";

public static string GroupName(this ModelMetadata metadata) {

string groupName;

if (metadata.AdditionalValues.TryGetValue("GroupName", out groupName)) {
return groupName;
}

return null;
}

/// <summary>
/// Determines whether a property should be shown in a display template, based on its metadata.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions src/Xcst.AspNet/Properties/AssemblyInfo.cs
Expand Up @@ -7,8 +7,8 @@
[assembly: AssemblyTitle("Xcst.AspNet.dll")]
[assembly: AssemblyDescription("Xcst.AspNet.dll")]
[assembly: AssemblyVersion("1.0.0")]
[assembly: AssemblyFileVersion("0.20.0")]
[assembly: AssemblyInformationalVersion("0.20.0")]
[assembly: AssemblyFileVersion("0.21.0")]
[assembly: AssemblyInformationalVersion("0.21.0")]
[assembly: ComVisible(false)]
[assembly: CLSCompliant(true)]
[assembly: PreApplicationStartMethod(typeof(PreApplicationStartCode), nameof(PreApplicationStartCode.Start))]
4 changes: 2 additions & 2 deletions src/Xcst.Web.Mvc/Properties/AssemblyInfo.cs
Expand Up @@ -7,8 +7,8 @@
[assembly: AssemblyTitle("Xcst.Web.Mvc.dll")]
[assembly: AssemblyDescription("Xcst.Web.Mvc.dll")]
[assembly: AssemblyVersion("1.0.0")]
[assembly: AssemblyFileVersion("0.20.0")]
[assembly: AssemblyInformationalVersion("0.20.0")]
[assembly: AssemblyFileVersion("0.21.0")]
[assembly: AssemblyInformationalVersion("0.21.0")]
[assembly: ComVisible(false)]
[assembly: CLSCompliant(true)]
[assembly: PreApplicationStartMethod(typeof(PreApplicationStartCode), nameof(PreApplicationStartCode.Start))]

0 comments on commit 184cf25

Please sign in to comment.