Skip to content

Instantly share code, notes, and snippets.

@InvaderZim85
Created November 22, 2019 21:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save InvaderZim85/bbfc3fe6100719e050b4debba4c7cfd3 to your computer and use it in GitHub Desktop.
Save InvaderZim85/bbfc3fe6100719e050b4debba4c7cfd3 to your computer and use it in GitHub Desktop.
Custom metadata base
public class MetadataBase<TModule> : MetadataModule<CustomMetadata> where TModule : class
{
protected MetadataBase()
{
AddDescription();
}
private void AddDescription()
{
var metaData = GetCustomMetadata<TModule, RouteDescriptionAttribute>();
foreach (var entry in metaData)
{
Describe[entry.Name] = x => new CustomMetadata(x, entry.Description);
}
}
private static List<TAttribute> GetCustomMetadata<TClass, TAttribute>() where TAttribute : Attribute
{
return (from constructor in typeof(TClass).GetConstructors()
from attribute in constructor.GetCustomAttributes<TAttribute>()
select attribute).ToList();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment