mirror of
https://github.com/Radarr/Radarr
synced 2024-12-24 17:01:38 +00:00
New Helper (Html Extension) for displaying the DescriptionAttribute.
This commit is contained in:
parent
ee00ef8c17
commit
975d8bc679
2 changed files with 29 additions and 0 deletions
28
NzbDrone.Web/Helpers/DescriptionExtension.cs
Normal file
28
NzbDrone.Web/Helpers/DescriptionExtension.cs
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Web;
|
||||||
|
using System.Web.Mvc;
|
||||||
|
|
||||||
|
namespace NzbDrone.Web.Helpers
|
||||||
|
{
|
||||||
|
public static class DescriptionExtension
|
||||||
|
{
|
||||||
|
public static MvcHtmlString DescriptionFor<TModel, TValue>(this HtmlHelper<TModel> html, Expression<Func<TModel, TValue>> expression)
|
||||||
|
{
|
||||||
|
var memberEx = expression.Body as MemberExpression;
|
||||||
|
|
||||||
|
if (memberEx == null)
|
||||||
|
throw new ArgumentException("Body not a member-expression.");
|
||||||
|
|
||||||
|
string name = memberEx.Member.Name;
|
||||||
|
|
||||||
|
var attributes = TypeDescriptor.GetProperties(typeof(TModel))[name].Attributes;
|
||||||
|
var desc = (DescriptionAttribute)attributes[typeof(DescriptionAttribute)];
|
||||||
|
|
||||||
|
return new MvcHtmlString(desc.Description);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -224,6 +224,7 @@
|
||||||
<Compile Include="Global.asax.cs">
|
<Compile Include="Global.asax.cs">
|
||||||
<DependentUpon>Global.asax</DependentUpon>
|
<DependentUpon>Global.asax</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="Helpers\DescriptionExtension.cs" />
|
||||||
<Compile Include="Helpers\HtmlPrefixScopeExtensions.cs" />
|
<Compile Include="Helpers\HtmlPrefixScopeExtensions.cs" />
|
||||||
<Compile Include="Helpers\IsCurrentActionHelper.cs" />
|
<Compile Include="Helpers\IsCurrentActionHelper.cs" />
|
||||||
<Compile Include="Models\AccountModels.cs" />
|
<Compile Include="Models\AccountModels.cs" />
|
||||||
|
|
Loading…
Reference in a new issue