Created
November 22, 2019 21:44
-
-
Save InvaderZim85/bbfc3fe6100719e050b4debba4c7cfd3 to your computer and use it in GitHub Desktop.
Custom metadata base
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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