1
1
// Copyright (c) Microsoft Corporation.
2
2
// Licensed under the MIT License.
3
3
4
- using System . Collections ;
5
- using System . Management . Automation ;
4
+ using System . Reflection ;
6
5
using PSRule . Definitions ;
7
6
8
7
namespace PSRule . Pipeline ;
9
8
9
+ #nullable enable
10
+
10
11
/// <summary>
11
12
/// A PSRule source containing one or more source files.
12
13
/// </summary>
13
14
public sealed class Source
14
15
{
15
16
internal bool Dependency ;
16
17
17
- internal readonly ModuleInfo Module ;
18
+ internal readonly ModuleInfo ? Module ;
18
19
19
20
internal Source ( string path , SourceFile [ ] file )
20
21
{
@@ -34,53 +35,20 @@ internal Source(ModuleInfo module, SourceFile[] file, bool dependency)
34
35
SetSource ( ) ;
35
36
}
36
37
37
- internal sealed class ModuleInfo
38
+ internal sealed class ModuleInfo ( string path , string name , string version , string ? projectUri , string ? guid , string ? companyName , string ? prerelease , Assembly [ ] assemblies )
38
39
{
39
- private const string FIELD_PRERELEASE = "Prerelease" ;
40
- private const string FIELD_PSDATA = "PSData" ;
41
40
private const string PRERELEASE_SEPARATOR = "-" ;
42
41
43
- public readonly string Path ;
44
- public readonly string Name ;
45
- public readonly string Version ;
46
- public readonly string ProjectUri ;
47
- public readonly string Guid ;
48
- public readonly string CompanyName ;
42
+ public readonly string Path = path ;
43
+ public readonly string Name = name ;
44
+ public readonly string Version = version ;
45
+ public readonly string FullVersion = string . IsNullOrEmpty ( prerelease ) ? version : string . Concat ( version , PRERELEASE_SEPARATOR , prerelease ) ;
49
46
50
- public ModuleInfo ( PSModuleInfo info )
51
- {
52
- Path = info . ModuleBase ;
53
- Name = info . Name ;
54
- Version = info . Version ? . ToString ( ) ;
55
- ProjectUri = info . ProjectUri ? . ToString ( ) ;
56
- Guid = info . Guid . ToString ( ) ;
57
- CompanyName = info . CompanyName ;
58
- if ( TryPrivateData ( info , FIELD_PSDATA , out var psData ) && psData . ContainsKey ( FIELD_PRERELEASE ) )
59
- Version = string . Concat ( Version , PRERELEASE_SEPARATOR , psData [ FIELD_PRERELEASE ] . ToString ( ) ) ;
60
- }
47
+ public readonly Assembly [ ] Assemblies = assemblies ;
61
48
62
- public ModuleInfo ( string path , string name , string version , string projectUri , string guid , string companyName , string prerelease )
63
- {
64
- Path = path ;
65
- Name = name ;
66
- Version = version ;
67
- ProjectUri = projectUri ;
68
- Guid = guid ;
69
- CompanyName = companyName ;
70
- if ( ! string . IsNullOrEmpty ( prerelease ) )
71
- Version = string . Concat ( version , PRERELEASE_SEPARATOR , prerelease ) ;
72
- }
73
-
74
- private static bool TryPrivateData ( PSModuleInfo info , string propertyName , out Hashtable value )
75
- {
76
- value = null ;
77
- if ( info . PrivateData is Hashtable privateData && privateData . ContainsKey ( propertyName ) && privateData [ propertyName ] is Hashtable data )
78
- {
79
- value = data ;
80
- return true ;
81
- }
82
- return false ;
83
- }
49
+ public readonly string ? ProjectUri = projectUri ;
50
+ public readonly string ? Guid = guid ;
51
+ public readonly string ? CompanyName = companyName ;
84
52
}
85
53
86
54
/// <summary>
@@ -107,3 +75,5 @@ private void SetSource()
107
75
File [ i ] . Source = this ;
108
76
}
109
77
}
78
+
79
+ #nullable restore
0 commit comments