错误CS0738接口实现

发布于 2024-10-06 09:37:35 字数 2790 浏览 1 评论 0原文

我有以下接口:

public delegate void NotifyOnModulesAvailabilityHandler(Lazy[]modules);

public interface IModulesLoader
{
    event NotifyOnModulesAvailabilityHandler NotifyOnModulesAvailability;

    Lazy<UserControl, IModuleMetadata>[] Modules { get; set; }

    void OnImportsSatisfied();
}

我尝试像这样实现这个接口:

public class ModulesLoader : IModulesLoader, IPartImportsSatisfiedNotification
{
    #region Events

    public event NotifyOnModulesAvailabilityHandler NotifyOnModulesAvailability;

    #endregion

    #region Public Contructor

    public ModulesLoader()
    {
        DeploymentCatalogService.Instance.Initialize();

        CompositionInitializer.SatisfyImports(this);

        this.LoadModules();
    }

    #endregion

    #region Properties

    [ImportMany(AllowRecomposition = true)]
    public Lazy<UserControl, IModuleMetadata>[] Modules
    {
        get;
        set;
    }

    #endregion

    #region IPartImportsSatisfiedNotification Members

    public void OnImportsSatisfied()
    {
        var handler = this.NotifyOnModulesAvailability;
        if (handler != null)
        {
            handler(this.Modules);
        }
    }

    #endregion

    #region Private Methods

    private void LoadModules()
    {
        var wc = new WebClient();
        wc.OpenReadCompleted += (s, e) =>
        {
            var streamInfo = e.Result;

            var xElement = XElement.Load(streamInfo);

            var modulesList = from m in xElement.Elements("ModuleInfo")
                              select m;
            if (modulesList.Any())
            {
                foreach (var module in modulesList)
                {
                    var moduleName = module.Attribute("XapFilename").Value;

                    DeploymentCatalogService.Instance.AddXap(moduleName);
                }
            }
        };
        wc.OpenReadAsync(new Uri("ModulesCatalog.xml", UriKind.Relative));
    }

    #endregion

}

我收到以下错误:

错误 1“TunisiaMeeting.Extensibility.Shell.Helpers.Deployment.ModulesLoader”未实现接口成员“TunisiaMeeting.MefBase.Interfaces.IModulesLoader.Modules”。 “TunisiaMeeting.Extensibility.Shell.Helpers.Deployment.ModulesLoader.Modules”无法实现“TunisiaMeeting.MefBase.Interfaces.IModulesLoader.Modules”,因为它没有 'System.Lazy``2[]'。 C:\Imed\TunisiaMeeting\TunisiaMeeting.Extensibility.Shell\Helpers\Deployment\ModulesLoader.cs 18 18 TunisiaMeeting.Extensibility.Shell

我很确定我有相同的返回类型 Lazy[]< /code> 在我的类和我的属性的界面中。

有什么帮助吗?

谢谢大家

I have the following interface:

public delegate void NotifyOnModulesAvailabilityHandler(Lazy[] modules);

public interface IModulesLoader
{
    event NotifyOnModulesAvailabilityHandler NotifyOnModulesAvailability;

    Lazy<UserControl, IModuleMetadata>[] Modules { get; set; }

    void OnImportsSatisfied();
}

I'm tring to implement this interface like this:

public class ModulesLoader : IModulesLoader, IPartImportsSatisfiedNotification
{
    #region Events

    public event NotifyOnModulesAvailabilityHandler NotifyOnModulesAvailability;

    #endregion

    #region Public Contructor

    public ModulesLoader()
    {
        DeploymentCatalogService.Instance.Initialize();

        CompositionInitializer.SatisfyImports(this);

        this.LoadModules();
    }

    #endregion

    #region Properties

    [ImportMany(AllowRecomposition = true)]
    public Lazy<UserControl, IModuleMetadata>[] Modules
    {
        get;
        set;
    }

    #endregion

    #region IPartImportsSatisfiedNotification Members

    public void OnImportsSatisfied()
    {
        var handler = this.NotifyOnModulesAvailability;
        if (handler != null)
        {
            handler(this.Modules);
        }
    }

    #endregion

    #region Private Methods

    private void LoadModules()
    {
        var wc = new WebClient();
        wc.OpenReadCompleted += (s, e) =>
        {
            var streamInfo = e.Result;

            var xElement = XElement.Load(streamInfo);

            var modulesList = from m in xElement.Elements("ModuleInfo")
                              select m;
            if (modulesList.Any())
            {
                foreach (var module in modulesList)
                {
                    var moduleName = module.Attribute("XapFilename").Value;

                    DeploymentCatalogService.Instance.AddXap(moduleName);
                }
            }
        };
        wc.OpenReadAsync(new Uri("ModulesCatalog.xml", UriKind.Relative));
    }

    #endregion

}

I get the following error:

Error 1 'TunisiaMeeting.Extensibility.Shell.Helpers.Deployment.ModulesLoader' does not implement interface member 'TunisiaMeeting.MefBase.Interfaces.IModulesLoader.Modules'. 'TunisiaMeeting.Extensibility.Shell.Helpers.Deployment.ModulesLoader.Modules' cannot implement 'TunisiaMeeting.MefBase.Interfaces.IModulesLoader.Modules' because it does not have the matching return type of 'System.Lazy``2<System.Windows.Controls.UserControl,TunisiaMeeting.MefBase.Interfaces.IModuleMetadata>[]'. C:\Imed\TunisiaMeeting\TunisiaMeeting.Extensibility.Shell\Helpers\Deployment\ModulesLoader.cs 18 18 TunisiaMeeting.Extensibility.Shell

I'm pretty sure I have the same return Type Lazy<UserControl, IModuleMetadata>[] in both my class and my interface for my property.

Any Help please ?

Thank you all

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

铜锣湾横着走 2024-10-13 09:37:35

您尚未显示 UserControlIModuleMetadata 来自何处...我的猜测是您的接口引用了一对类型,而您的实现引用了另一对类型:

  • 确保它们在相同的命名空间中引用相同的类型
  • 确保每种类型只有一份副本(例如,您在类库中没有一份副本,并在其他地方重新声明了它)

You haven't shown where UserControl and IModuleMetadata come from... my guess is that your interface is referring to one pair of types whereas your implementation is referring to a different pair:

  • Make sure they're referring to the same types in the same namespaces
  • Make sure you only have one copy of each type (e.g. that you haven't got one copy in a class library, and redeclared it somewhere else)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文