|
12 | 12 |
|
13 | 13 | using System;
|
14 | 14 | using System.Collections.Generic;
|
| 15 | +using System.Collections.ObjectModel; |
15 | 16 | #if !CORECLR
|
16 | 17 | using System.ComponentModel.Composition;
|
17 | 18 | #endif
|
@@ -41,6 +42,41 @@ public class UseIdenticalMandatoryParametersDSC : IDSCResourceRule
|
41 | 42 | private string fileName;
|
42 | 43 | private IDictionary<string, string> propAttrDict;
|
43 | 44 | private IEnumerable<FunctionDefinitionAst> resourceFunctions;
|
| 45 | + private Func<string, Tuple<string, Version>, Collection<Exception>, List<CimClass>> dscClassImporter; |
| 46 | + |
| 47 | + public UseIdenticalMandatoryParametersDSC() |
| 48 | + { |
| 49 | + var importClassesMethod = typeof(DscClassCache).GetMethod( |
| 50 | + "ImportClasses", |
| 51 | + BindingFlags.Public | BindingFlags.Static); |
| 52 | + if (importClassesMethod != null) |
| 53 | + { |
| 54 | + // In some version of S.M.A ImportClasses classes method takes 4 parameters |
| 55 | + // while in others it takes 3. |
| 56 | + if (importClassesMethod.GetParameters().Count() == 4) |
| 57 | + { |
| 58 | + dscClassImporter = (path, moduleInfo, errors) => |
| 59 | + { |
| 60 | + return importClassesMethod.Invoke( |
| 61 | + null, |
| 62 | + new object[] { path, moduleInfo, errors, false }) as List<CimClass>; |
| 63 | + }; |
| 64 | + } |
| 65 | + else |
| 66 | + { |
| 67 | + dscClassImporter = (path, moduleInfo, errors) => |
| 68 | + { |
| 69 | + return importClassesMethod.Invoke( |
| 70 | + null, |
| 71 | + new object[] { path, moduleInfo, errors}) as List<CimClass>; |
| 72 | + }; |
| 73 | + } |
| 74 | + } |
| 75 | + else |
| 76 | + { |
| 77 | + dscClassImporter = (path, moduleInfo, errors) => null; |
| 78 | + } |
| 79 | + } |
44 | 80 |
|
45 | 81 | /// <summary>
|
46 | 82 | /// AnalyzeDSCResource: Analyzes given DSC Resource
|
@@ -216,21 +252,7 @@ private IDictionary<string, string> GetKeys(string fileName)
|
216 | 252 | isDSCClassCacheInitialized = true;
|
217 | 253 | }
|
218 | 254 |
|
219 |
| - var importClassesMethod = typeof(DscClassCache).GetMethod( |
220 |
| - "ImportClasses", |
221 |
| - BindingFlags.Public | BindingFlags.Static); |
222 |
| - if (importClassesMethod != null) |
223 |
| - { |
224 |
| - var parameters = new List<object>(new object[] { mofFilepath, moduleInfo, errors }); |
225 |
| - |
226 |
| - // In some version of S.M.A ImportClasses classes method takes 4 parameters |
227 |
| - // while in others it takes 3. |
228 |
| - if (importClassesMethod.GetParameters().Count() == 4) |
229 |
| - { |
230 |
| - parameters.Add(false); |
231 |
| - } |
232 |
| - cimClasses = importClassesMethod.Invoke(null, parameters.ToArray()) as List<CimClass>; |
233 |
| - } |
| 255 | + cimClasses = dscClassImporter(mofFilepath, moduleInfo, errors); |
234 | 256 | }
|
235 | 257 | catch
|
236 | 258 | {
|
|
0 commit comments