File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change
1
+ using Microsoft . AspNetCore . Razor . TagHelpers ;
2
+ using System ;
3
+ using System . Linq ;
4
+ using System . Reflection ;
5
+
6
+ namespace Our . Umbraco . TagHelpers
7
+ {
8
+ /// <summary>
9
+ /// Used to print out the current version of the Assembly Name
10
+ /// Only Assemblies loaded into the Current AppDomain can be looked up
11
+ /// </summary>
12
+ [ HtmlTargetElement ( "our-version" ) ]
13
+ public class VersionTagHelper : TagHelper
14
+ {
15
+ /// <summary>
16
+ /// Name of assembly to lookup minus the .dll extension
17
+ /// 'Our.Umbraco.TagHelpers'
18
+ /// </summary>
19
+ [ HtmlAttributeName ( "assembly" ) ]
20
+ public string AssemblyName { get ; set ; } = string . Empty ;
21
+
22
+ public override void Process ( TagHelperContext context , TagHelperOutput output )
23
+ {
24
+ output . TagName = "" ;
25
+
26
+ // If no Assembly name set on attribute
27
+ // Then use the
28
+ if ( string . IsNullOrEmpty ( AssemblyName ) )
29
+ {
30
+ var siteAssembly = Assembly . GetEntryAssembly ( ) ;
31
+ var version = siteAssembly ? . GetName ( ) . Version ;
32
+ output . Content . SetHtmlContent ( version . ToString ( ) ) ;
33
+ return ;
34
+ }
35
+
36
+ var allAssemblies = AppDomain . CurrentDomain . GetAssemblies ( ) ;
37
+ var findAssembly = allAssemblies . SingleOrDefault ( x => x . GetName ( ) . Name == AssemblyName ) ;
38
+ if ( findAssembly == null )
39
+ {
40
+ output . SuppressOutput ( ) ;
41
+ return ;
42
+ }
43
+ output . Content . SetHtmlContent ( findAssembly . GetName ( ) . Version . ToString ( ) ) ;
44
+ }
45
+ }
46
+ }
You can’t perform that action at this time.
0 commit comments