Files
MTSC/MTSC/Common/Http/Attributes/FromRouteContextResourcesAttribute.cs
T
amacocianandGitHub 4aa1150bba Extend and generalize data binding logic (#14)
Support for custom data binding attributes
2022-02-26 10:37:32 +01:00

26 lines
683 B
C#

using MTSC.Common.Http.RoutingModules;
using System;
namespace MTSC.Common.Http.Attributes
{
public sealed class FromRouteContextResourcesAttribute : RouteDataBindingBaseAttribute
{
public string ResourceKey { get; }
public FromRouteContextResourcesAttribute(string resourceKey)
{
this.ResourceKey = resourceKey;
}
public override object DataBind(HttpRouteBase route, RouteContext routeContext, Type propertyType)
{
if (routeContext.Resources.TryGetValue(this.ResourceKey, out var resource))
{
return resource;
}
return null;
}
}
}