-
-
Save Cyberlane/9dbcc37fff85777716f1 to your computer and use it in GitHub Desktop.
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 IEnumerable<LinkModel> GetMainLinks(IRouteCache routeCache) | |
{ | |
return routeCache.SelectMany(routes => | |
{ | |
return routes.Value | |
.Where(route => route.Item1 == 0 && | |
route.Item2.Method == "GET" && | |
route.Item2.Name != string.Empty) | |
.Select(route => new LinkModel | |
{ | |
Link = route.Item2.Path, | |
Text = route.Item2.Name | |
}); | |
}); | |
} |
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 HomeMetadataModule : MetadataModule<MetadataModel> | |
{ | |
public HomeMetadataModule() | |
{ | |
Describe["/"] = _ => new MetadataModel | |
{ | |
Index = 1 | |
}; | |
} | |
} |
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 MetadataModel | |
{ | |
public int Index { get; set; } | |
} |
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 MetadataRouteProvider : IRouteMetadataProvider | |
{ | |
public Type GetMetadataType(INancyModule module, RouteDescription routeDescription) | |
{ | |
return typeof (MetadataModel); | |
} | |
public object GetMetadata(INancyModule module, RouteDescription routeDescription) | |
{ | |
var moduleType = module.GetType(); | |
var moduleName = moduleType.FullName; | |
var parts = moduleName.Split('.').ToArray(); | |
if (parts[0] != GetType().FullName.Split('.')[0]) return null; | |
if (parts[parts.Length - 2] != "Modules") return null; | |
parts[parts.Length - 2] = "Metadata"; | |
parts[parts.Length - 1] = ReplaceModuleWithMetadataModule(parts[parts.Length - 1]); | |
var metadataModuleName = string.Join(".", parts); | |
var type = Type.GetType(metadataModuleName); | |
return type == null ? null : TinyIoCContainer.Current.Resolve(type); | |
} | |
private string ReplaceModuleWithMetadataModule(string moduleName) | |
{ | |
var i = moduleName.LastIndexOf("Module", StringComparison.Ordinal); | |
return moduleName.Substring(0, i) + "MetadataModule"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment