Question

public  class ArgParseHelper
    {
        /// <summary>
        /// Constant for GuardMode "Report"
        /// </summary>
        private const string c_ModeReport = "REPORT";

        /// <summary>
        /// Constant for GuardMode "Enforce"
        /// </summary>
        private const string c_ModeEnforce = "ENFORCE";

        public static bool TryGetSecurityGuardModeValue(string securityMode, out SecurityGuardMode securityGuardMode)
        {
            securityGuardMode = securityGuardMode = SecurityGuardMode.Enforce;
            if (c_ModeEnforce.Equals(securityMode, StringComparison.OrdinalIgnoreCase))
            {
                return true;
            }
            else if (c_ModeReport.Equals(securityMode, StringComparison.OrdinalIgnoreCase))
            {
                securityGuardMode = SecurityGuardMode.Report;
                return true;
            }
            return false;
        }
    }

I call this method as following :

SecurityGuardMode  guardModeService;
ArgParseHelper m_GuardArgParseHelper = new GuardArgParseHelper();
if (m_GuardArgParseHelper.TryGetSecurityGuardModeValue(value, out guardModeService))

//<-compilation error "`cannot be accessed with an instance reference; qualify it with a type name instead`"
            {

            }

what is wrong?

Was it helpful?

Solution

You are accessing a static method passing by an instance.

You must use:

// Us the class name ArgParseHelper (where the static method is defined) not one
// of its instances
if (ArgParseHelper.TryGetSecurityGuardModeValue(..)) {

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top