0
app.config 파일에 key가 없을 때 컴파일 오류가 발생하도록 PostSharp 애스펙트를 만들었지 만 CompileTimeValidate 메소드에서 Checking 할 때 ConfigurationManager.AppSettings.HasKeys()가 "false"를 반환합니다. 나를 도와 줄 수 있니? 감사!Postsharp - App Settings 구성 확인
[Serializable]
public class ConfigurationValueRequiredAttribute : MethodInterceptionAspect
{
// Method invoked at build time. It validates that the aspect has been applied to an acceptable method.
public override bool CompileTimeValidate(MethodBase method)
{
bool valid = true;
if (string.IsNullOrEmpty(ConfigurationManager.AppSettings["Test"]))
{
Message.Write(SeverityType.Error, "CUSTOM02", "Test not exists!");
valid = false;
}
return valid;
}
}
키를 확인하면 어떻게됩니까? app.config가 컴파일 시간에로드 될 것이라고 생각하지 않습니다. app.config를 수동으로로드하거나 app.config를 XML로로드하고 키가 존재하는지 확인하기 위해 일부 xpath를 수행 할 수 있습니다. – Michael