From d1caaff5d8c9ab41f53d17e7d29cb34b27e0370d Mon Sep 17 00:00:00 2001 From: xtqqczze Date: Mon, 23 Nov 2020 02:54:03 +0000 Subject: [PATCH] Fix CA1822: Mark members as static part 7 https://docs.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1822 --- .../ConfigProvider.cs | 68 +++++++++---------- .../CurrentConfigurations.cs | 4 +- 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/Microsoft.WSMan.Management/ConfigProvider.cs b/src/Microsoft.WSMan.Management/ConfigProvider.cs index 7054766373d..859793af016 100644 --- a/src/Microsoft.WSMan.Management/ConfigProvider.cs +++ b/src/Microsoft.WSMan.Management/ConfigProvider.cs @@ -1033,7 +1033,7 @@ protected override void SetItem(string path, object value) pluginConfiguration.UpdateOneConfiguration( ".", WSManStringLiterals.ConfigRunAsPasswordName, - this.GetStringFromSecureString(runAsCredentials.Password)); + GetStringFromSecureString(runAsCredentials.Password)); } } @@ -1050,7 +1050,7 @@ protected override void SetItem(string path, object value) AssertError(helper.GetResourceMsgFromResourcetext("SetItemOnRunAsPasswordNoRunAsUser"), false); } - value = this.GetStringFromSecureString(value); + value = GetStringFromSecureString(value); } pluginConfiguration.UpdateOneConfiguration(".", ChildName, value.ToString()); @@ -2290,7 +2290,7 @@ private void NewItemPluginOrPluginChild(object sessionobj, string path, string h /// /// /// - private PSObject GetItemPSObjectWithTypeName(string Name, string TypeNameOfElement, object Value, string[] keys, string ExtendedTypeName, WsManElementObjectTypes WSManElementObjectType, PSObject input = null) + private static PSObject GetItemPSObjectWithTypeName(string Name, string TypeNameOfElement, object Value, string[] keys, string ExtendedTypeName, WsManElementObjectTypes WSManElementObjectType, PSObject input = null) { PSObject mshObject = null; if (WSManElementObjectType.Equals(WsManElementObjectTypes.WSManConfigElement)) @@ -2410,7 +2410,7 @@ private void SetItemListenerOrClientCertificate(object sessionObj, string Resour /// /// /// - private string GetInputStringForCreate(string ResourceURI, Hashtable value, string host) + private static string GetInputStringForCreate(string ResourceURI, Hashtable value, string host) { string putstr = string.Empty; string nilns = string.Empty; @@ -2523,7 +2523,7 @@ private string GetHostName(string path) return sHostname; } - private string GetRootNodeName(string ResourceURI) + private static string GetRootNodeName(string ResourceURI) { string tempuri = string.Empty; if (ResourceURI.Contains('?')) @@ -2542,7 +2542,7 @@ private string GetRootNodeName(string ResourceURI) return tempuri; } - private string EscapeValuesForXML(string value) + private static string EscapeValuesForXML(string value) { StringBuilder esc_str = new StringBuilder(); for (int i = 0; i <= value.Length - 1; i++) @@ -2585,7 +2585,7 @@ private string EscapeValuesForXML(string value) return esc_str.ToString(); } - private bool IsItemContainer(XmlNodeList nodes) + private static bool IsItemContainer(XmlNodeList nodes) { bool result = false; if (nodes.Count != 0) @@ -2935,7 +2935,7 @@ private bool ContainResourceValue(object sessionobj, string ResourceURI, string #endregion "WsMan linking Operations" - private string GetURIWithFilter(string uri, Hashtable cmdlinevalues) + private static string GetURIWithFilter(string uri, Hashtable cmdlinevalues) { StringBuilder sburi = new StringBuilder(uri); if (cmdlinevalues != null) @@ -2960,7 +2960,7 @@ private string GetURIWithFilter(string uri, Hashtable cmdlinevalues) return sburi.ToString(); } - private string GetFilterString(Hashtable cmdlinevalues, string[] pkey) + private static string GetFilterString(Hashtable cmdlinevalues, string[] pkey) { StringBuilder filter = new StringBuilder(); foreach (string key in pkey) @@ -2979,7 +2979,7 @@ private string GetFilterString(Hashtable cmdlinevalues, string[] pkey) return filter.ToString(); } - private bool IsPKey(string value, string ResourceURI) + private static bool IsPKey(string value, string ResourceURI) { bool result = false; if (ResourceURI.Contains(WSManStringLiterals.containerListener)) @@ -2998,7 +2998,7 @@ private bool IsPKey(string value, string ResourceURI) return result; } - private bool CheckPkeysArray(Hashtable values, string value, string[] pkeys) + private static bool CheckPkeysArray(Hashtable values, string value, string[] pkeys) { bool result = false; if (values != null) @@ -3239,7 +3239,7 @@ private PSObject BuildHostLevelPSObjectArrayList(object objSessionObject, string /// /// /// - private PSObject ConvertToPSObject(XmlNode xmlnode) + private static PSObject ConvertToPSObject(XmlNode xmlnode) { PSObject mshObject = new PSObject(); foreach (XmlNode node in xmlnode.ChildNodes) @@ -3275,7 +3275,7 @@ private PSObject ConvertToPSObject(XmlNode xmlnode) return mshObject; } - private string SetXPathString(string uri) + private static string SetXPathString(string uri) { string parent = uri.Substring(uri.LastIndexOf(WSManStringLiterals.WinrmPathSeparator.ToString(), StringComparison.OrdinalIgnoreCase) + 1); if (parent.Equals(WSManStringLiterals.containerWinrs, StringComparison.OrdinalIgnoreCase)) @@ -3307,7 +3307,7 @@ private string SetXPathString(string uri) return parent; } - private string SetSchemaPath(string uri) + private static string SetSchemaPath(string uri) { string schemapath = string.Empty; uri = uri.Remove(0, WinrmRootName[0].Length); @@ -3334,7 +3334,7 @@ private string SetSchemaPath(string uri) /// /// /// - private string NormalizePath(string path, string host) + private static string NormalizePath(string path, string host) { string uri = string.Empty; if (path.StartsWith(host, StringComparison.OrdinalIgnoreCase)) @@ -3660,7 +3660,7 @@ private string GetCorrectCaseOfName(string ChildName, string hostname, string pa return result; } - private ArrayList RemoveItemfromResourceArray(ArrayList resourceArray, string ChildName, string type, string property) + private static ArrayList RemoveItemfromResourceArray(ArrayList resourceArray, string ChildName, string type, string property) { if (resourceArray != null) { @@ -4519,7 +4519,7 @@ private void GetChildItemsOrNames(string path, ProviderMethods methodname, bool /// /// /// - private int GetPluginNames(XmlDocument xmlPlugins, out PSObject PluginNames, out string CurrentPluginName, string path) + private static int GetPluginNames(XmlDocument xmlPlugins, out PSObject PluginNames, out string CurrentPluginName, string path) { PluginNames = new PSObject(); CurrentPluginName = string.Empty; @@ -4627,7 +4627,7 @@ private void StartWSManService(bool force) /// /// /// - private bool IsPathLocalMachine(string host) + private static bool IsPathLocalMachine(string host) { bool hostfound = false; // Check is Localhost @@ -4684,7 +4684,7 @@ private bool IsPathLocalMachine(string host) #region Plugin private functions - private void GenerateObjectNameAndKeys(Hashtable InputAttributes, string ResourceURI, string ContainerItem, out string ItemName, out string[] keys) + private static void GenerateObjectNameAndKeys(Hashtable InputAttributes, string ResourceURI, string ContainerItem, out string ItemName, out string[] keys) { StringBuilder sbHashKey = new StringBuilder(); string keysColumns = string.Empty; @@ -4717,7 +4717,7 @@ private void GenerateObjectNameAndKeys(Hashtable InputAttributes, string Resourc keys = keysColumns.Split('|'); } - private void ProcessCertMappingObjects(XmlDocument xmlCerts, out Hashtable Certcache, out Hashtable Keyscache) + private static void ProcessCertMappingObjects(XmlDocument xmlCerts, out Hashtable Certcache, out Hashtable Keyscache) { Hashtable lCache = new Hashtable(); Hashtable kCache = new Hashtable(); @@ -4775,7 +4775,7 @@ private void ProcessCertMappingObjects(XmlDocument xmlCerts, out Hashtable Certc Keyscache = kCache; } - private void ProcessListenerObjects(XmlDocument xmlListeners, out Hashtable listenercache, out Hashtable Keyscache) + private static void ProcessListenerObjects(XmlDocument xmlListeners, out Hashtable listenercache, out Hashtable Keyscache) { Hashtable lCache = new Hashtable(); Hashtable kCache = new Hashtable(); @@ -4836,7 +4836,7 @@ private void ProcessListenerObjects(XmlDocument xmlListeners, out Hashtable list Keyscache = kCache; } - private PSObject ProcessPluginConfigurationLevel(XmlDocument xmldoc, bool setRunasPasswordAsSecureString = false) + private static PSObject ProcessPluginConfigurationLevel(XmlDocument xmldoc, bool setRunasPasswordAsSecureString = false) { PSObject objConfiglvl = null; @@ -4877,7 +4877,7 @@ private PSObject ProcessPluginConfigurationLevel(XmlDocument xmldoc, bool setRun return objConfiglvl; } - private ArrayList ProcessPluginResourceLevel(XmlDocument xmldoc, out ArrayList arrSecurity) + private static ArrayList ProcessPluginResourceLevel(XmlDocument xmldoc, out ArrayList arrSecurity) { ArrayList Resources = null; ArrayList nSecurity = null; @@ -4963,7 +4963,7 @@ private ArrayList ProcessPluginResourceLevel(XmlDocument xmldoc, out ArrayList a return Resources; } - private ArrayList ProcessPluginInitParamLevel(XmlDocument xmldoc) + private static ArrayList ProcessPluginInitParamLevel(XmlDocument xmldoc) { ArrayList InitParamLvl = null; if (xmldoc != null) @@ -5001,7 +5001,7 @@ private ArrayList ProcessPluginInitParamLevel(XmlDocument xmldoc) return InitParamLvl; } - private ArrayList ProcessPluginSecurityLevel(ArrayList arrSecurity, XmlDocument xmlSecurity, string UniqueResourceID, string ParentResourceUri) + private static ArrayList ProcessPluginSecurityLevel(ArrayList arrSecurity, XmlDocument xmlSecurity, string UniqueResourceID, string ParentResourceUri) { // ArrayList SecurityLvl = null; if (xmlSecurity != null) @@ -5063,7 +5063,7 @@ private ArrayList ProcessPluginSecurityLevel(ArrayList arrSecurity, XmlDocument ///List of Securities ///List of initialization parameters. /// An Configuration XML, ready to send to server. - private string ConstructPluginXml(PSObject objinputparam, string ResourceURI, string host, string Operation, ArrayList resources, ArrayList securities, ArrayList initParams) + private static string ConstructPluginXml(PSObject objinputparam, string ResourceURI, string host, string Operation, ArrayList resources, ArrayList securities, ArrayList initParams) { StringBuilder sbvalues = new StringBuilder(); sbvalues.Append(" /// Value to append. - private string GetStringFromSecureString(object propertyValue) + private static string GetStringFromSecureString(object propertyValue) { SecureString value = propertyValue as SecureString; string passwordValueToAdd = string.Empty; @@ -5206,7 +5206,7 @@ private string GetStringFromSecureString(object propertyValue) return passwordValueToAdd; } - private string ConstructResourceXml(PSObject objinputparams, ArrayList resources, ArrayList securities) + private static string ConstructResourceXml(PSObject objinputparams, ArrayList resources, ArrayList securities) { StringBuilder sbvalues = new StringBuilder(string.Empty); if (objinputparams == null && resources == null) @@ -5293,7 +5293,7 @@ private string ConstructResourceXml(PSObject objinputparams, ArrayList resources return sbvalues.ToString(); } - private string ConstructSecurityXml(PSObject objinputparams, ArrayList securities, string strResourceIdentity) + private static string ConstructSecurityXml(PSObject objinputparams, ArrayList securities, string strResourceIdentity) { // StringBuilder sbvalues = new StringBuilder(string.Empty); @@ -5320,7 +5320,7 @@ private string ConstructSecurityXml(PSObject objinputparams, ArrayList securitie return sbvalues.ToString(); } - private void AddSecurityProperties( + private static void AddSecurityProperties( PSMemberInfoCollection properties, StringBuilder sbValues) { @@ -5345,7 +5345,7 @@ private void AddSecurityProperties( sbValues.Append(""); } - private string ConstructInitParamsXml(PSObject objinputparams, ArrayList initparams) + private static string ConstructInitParamsXml(PSObject objinputparams, ArrayList initparams) { // // @@ -5397,7 +5397,7 @@ private string ConstructInitParamsXml(PSObject objinputparams, ArrayList initpar return sbvalues.ToString(); } - private string ConstructCapabilityXml(object[] capabilities) + private static string ConstructCapabilityXml(object[] capabilities) { StringBuilder sbvalues = new StringBuilder(string.Empty); foreach (object cap in capabilities) @@ -5413,7 +5413,7 @@ private string ConstructCapabilityXml(object[] capabilities) return sbvalues.ToString(); } - private bool IsValueOfParamList(string name, string[] paramcontainer) + private static bool IsValueOfParamList(string name, string[] paramcontainer) { bool result = false; foreach (string value in paramcontainer) diff --git a/src/Microsoft.WSMan.Management/CurrentConfigurations.cs b/src/Microsoft.WSMan.Management/CurrentConfigurations.cs index 783bfe1ef0b..0129554c30b 100644 --- a/src/Microsoft.WSMan.Management/CurrentConfigurations.cs +++ b/src/Microsoft.WSMan.Management/CurrentConfigurations.cs @@ -131,7 +131,7 @@ public void RemoveOneConfiguration(string pathToNodeFromRoot) { if (nodeToRemove is XmlAttribute) { - this.RemoveAttribute(nodeToRemove as XmlAttribute); + RemoveAttribute(nodeToRemove as XmlAttribute); } } else @@ -217,7 +217,7 @@ public string GetOneConfiguration(string pathFromRoot) /// Removes the attribute from OwnerNode. /// /// Attribute to Remove. - private void RemoveAttribute(XmlAttribute attributeToRemove) + private static void RemoveAttribute(XmlAttribute attributeToRemove) { XmlElement ownerElement = attributeToRemove.OwnerElement; ownerElement.RemoveAttribute(attributeToRemove.Name);