And*_*ves 4 c# immutability visual-studio sonarqube
我在旧项目中的类遇到问题,我不知道如何重构这部分,我从 sonarcube 收到以下错误消息:
Use an immutable collection or reduce the accessibility of the field(s) 'CreateContactMapping'.Why is this an issue?
Run Code Online (Sandbox Code Playgroud)
这是一段代码
Use an immutable collection or reduce the accessibility of the field(s) 'CreateContactMapping'.Why is this an issue?
Run Code Online (Sandbox Code Playgroud)
如何最好地解决这个问题?
小智 13
一种解决方案可能是更改Dictionary为,然后在初始化字典后ImmutableDictionary运行。.ToImmutableDictionary()
public static readonly ImmutableDictionary<string, Func<UpdateContactServiceRequest, object>> UpdateContactMapping =
new Dictionary<string, Func<UpdateContactServiceRequest, object>>
{
{ "firstname", req => req.FirstName },
{ "lastname", req => req.LastName },
{ "full_name", req => req.FullName },
{ "email", req => req.Email },
{ "phone", req => req.Phone },
{ "date_of_birth", req => req.BirthDate },
{ "job_title", req => req.JobTitle },
{ "occupation", req => req.Occupation },
{ "renda", req => req.MonthlyIncome },
{ "lifecyclestage", req => req.LifeCycleStage },
{ "hs_lead_status", req => req.LeadStatus },
{ "ali_email_validated", req => req.EmailValidated },
{ "ali_sms_token_validated", req => req.CellphoneValidated },
{ "id_da_proposta_atual", req => req.CurrentProposalId },
{ "contact_type", req => req.ContactType }
}.ToImmutableDictionary();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5715 次 |
| 最近记录: |