0
다음 StyleCop 위반을 직면합니다. 이 문제를 어떻게 해결할 수 있습니까?SA1401 필드는 개인 액세스로 선언해야합니다. 속성을 사용하여 필드를 표시하십시오.
경고 SA1401 : CSharp.Maintainability : 필드는 개인 액세스로 선언해야합니다. 속성을 사용하여 필드를 표시하십시오. MonitoringGitLabProjectStatus
내 코드
public class EmailConfig
{
public EmailConfig()
{
this.AmazonClient = new AmazonSimpleEmailServiceClient(this.amazonUserName, this.amazonPassword);
}
protected MailMessage mailMessage = new MailMessage(); //Fields must be declared with private access. Use properties to expose fields
protected RawMessage rawMessage = new RawMessage(); //Fields must be declared with private access. Use properties to expose fields
protected SendRawEmailRequest request = new SendRawEmailRequest(); //Fields must be declared with private access. Use properties to expose fields
protected List<string> mailNotifications = new List<string>(); //Fields must be declared with private access. Use properties to expose fields
protected List<string> additionalNotifications = new List<string>(); //Fields must be declared with private access. Use properties to expose fields
protected List<string> additionalNotificationsinBCC = new List<string>(); //Fields must be declared with private access. Use properties to expose fields
private string amazonUserName = "user name";
private string amazonPassword = "Password";
public AmazonSimpleEmailServiceClient AmazonClient { get; protected set; }
}
public class EmailSenderThread : EmailConfig
{
private Thread msgThread;
public EmailSenderThread(List<string> emailAddresses, List<string> ccemailaddress, List<string> bccemailaddress, string from, string subject, string body, string attachmentFileName)
: base()
{
try
{
this.msgThread = new Thread(new ThreadStart(this.MailSender));
mailMessage.From = new MailAddress(string.IsNullOrEmpty(from) ? "[email protected]" : from);
if (emailAddresses != null)
{
var tomails = emailAddresses;
foreach (string tomail in tomails)
{
if (!string.IsNullOrEmpty(tomail))
{
mailMessage.To.Add(new MailAddress(tomail));
mailNotifications.Add(tomail);
}
}
}
if (ccemailaddress != null)
{
var ccemails = ccemailaddress;
foreach (string ccmail in ccemails)
{
if (!string.IsNullOrEmpty(ccmail))
{
mailMessage.CC.Add(new MailAddress(ccmail));
additionalNotifications.Add(ccmail);
}
}
}
if (bccemailaddress != null)
{
var bccemails = bccemailaddress;
foreach (string bccmail in bccemails)
{
if (!string.IsNullOrEmpty(bccmail))
{
mailMessage.Bcc.Add(new MailAddress(bccmail));
additionalNotificationsinBCC.Add(bccmail);
}
}
}
mailMessage.Subject = subject;
AlternateView htmlView = AlternateView.CreateAlternateViewFromString(body, Encoding.UTF8, "text/html");
if (body != null)
{
mailMessage.AlternateViews.Add(htmlView);
}
if (!string.IsNullOrEmpty(attachmentFileName))
{
var attachment = new Attachment(attachmentFileName);
mailMessage.Attachments.Add(attachment);
}
MemoryStream memoryStream = ConvertMailMessage.ConvertMailMessageToMemoryStream(mailMessage);
rawMessage.WithData(memoryStream);
request.WithRawMessage(this.rawMessage);
request.WithDestinations(this.mailNotifications);
request.WithDestinations(this.additionalNotifications);
request.WithDestinations(this.additionalNotificationsinBCC);
request.WithSource(from);
this.msgThread.Start();
}
catch (Exception ex)
{
Console.WriteLine("Exception in mail sending: {0}", ex);
}
}
나는 내가 StyleCop 위반 faceing 주석 행을 표시합니다.
공용 클래스 EmailSenderThread : EmailConfig에서 개인 약자에 액세스하는 방법을 모르겠습니다. 개인이 보호 된 대신 개인을 변경하면 예외가 발생합니다.
public class EmailSenderThread : EmailConfig. 나는
EmailConfig에 대한 객체를 생성함으로써 오류를 수정하려고 시도했다. 그러나 사용되지 않았습니다.
좋아요. 정확히 내가 필요로하는 것! –