我没有太多使用 Linq,也没有使用 IEnumberable 类。以下是我遇到的问题的代码和解释。
public class EmailService : IEmailService
{
#region Constructors
#endregion
#region Properties
[ImportMany]
public IEnumerable<IEmailAddressesProvider> AddressProviders { get; set; }
#endregion
这些是我需要在 EmailService 类中使用的属性。这是电子邮件地址提供商的集合。
我需要使用其中存储的内容并将其连接到 ViewModel,就像我在这段代码的下一部分中对这些其他属性所做的那样。
IUserInteractionService uiService = AllianceApp.Container.GetExportedValue<IUserInteractionService>();
IEmailSetupProvider provider = new EmailSetupProvider();
EmailView ev = AllianceApp.Container.GetExportedValue<EmailView>();
ev.ViewModel.ProviderName = AddressProviders;
ev.ViewModel.Provider = provider;
ev.ViewModel.Bcc = bccAddress;
ev.ViewModel.Cc = ccAddress;
ev.ViewModel.ToAddress = toAddress;
ev.ViewModel.Body = body;
ev.ViewModel.Subject = subject;
ev.ViewModel.Attachments = attachments;
return uiService.ShowDialog(ev, RegionNames.MainRegion);
}
它说“地址提供者是我试图创建这个属性的地方。
IEmailAddressesProvider 接口:
public interface IEmailAddressesProvider
{
string ProviderName { get; }
IEnumerable<EmailAddress> GetEmailUsers();
}
GetEmailUsers 方法(以防万一):
[Export(typeof(IEmailAddressesProvider))]
public class EmailAddressProvider : IEmailAddressesProvider
{
#region Private Properties
private static readonly IEncryptionService encryptionService = AllianceApp.Container.GetExportedValue<IEncryptionService>();
#endregion
public string ProviderName
{
get { return "Alliance Users"; }
}
public IEnumerable<EmailAddress> GetEmailUsers()
{
IUserRepository userRepo = AllianceApp.Container.GetExportedValue<IUserRepository>();
IEnumerable<User> users = userRepo.GetAllUsers().Where(a => a.IsDeleted == false).OrderBy(a => a.UserID).AsEnumerable();
List<EmailAddress> AddressList = new List<EmailAddress>();
foreach (var user in users)
{
if (user.DisplayName != null && user.EmailAddress != null && user.DisplayName != string.Empty && user.EmailAddress != string.Empty)
AddressList.Add(new EmailAddress() { DisplayName = encryptionService.DecryptString(user.DisplayName), Email = encryptionService.DecryptString(user.EmailAddress) });
}
AddressList.OrderBy(u => u.DisplayName);
return AddressList;
}
}
ProviderName 专用代码(在 EmailAddressesProvider.cs 中使用):
[Export(typeof(IEmailAddressesProvider))]
public class EmailAddressProvider : IEmailAddressesProvider
{
#region Private Properties
private static readonly IEncryptionService encryptionService = AllianceApp.Container.GetExportedValue<IEncryptionService>();
#endregion
public string ProviderName
{
get { return "Alliance Users"; }
}
}
If you need to see anymore of my code, such as the interfaces or the viewmodel, please let me know. Any help would be appreciated!