2014-04-05 2 views
0
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; 
     } 
    } 

Я называю этот метод следующим образом:Определите метод с аргументом из

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`" 
      { 

      } 

что не так?

ответ

1

Доступ к статическому методу, передаваемому экземпляром.

Вы должны использовать:

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

} 
Смежные вопросы