2010-11-10 77 views
0

我面临的情况是,ASPX母版页的代码隐藏文件和不使用母版的常规ASPX页面的代码隐藏文件实现接口。实施完全一样。如何共享接口实现

是否有可能让两个代码隐藏共享实现而不是每个都有其相同实现的副本?如果是,我应该如何处理?

非常感谢您的任何见解。

约翰

回答

2

如何使用组成,其上两,法师和ASPX页面必须实现该接口的类的参考?

public interface IFace 
{ 
    int MyProperty { get; set; } 
    void MyMethod(string pVariable); 
} 

[Serializable] 
public class ClassA:IFace 
{ 
    public ClassA() 
    { 

    } 

    #region IFace Members 

    public int MyProperty 
    { 
     get 
     { 
      throw new NotImplementedException(); 
     } 
     set 
     { 
      throw new NotImplementedException(); 
     } 
    } 

    public void MyMethod(string pVariable) 
    { 
     throw new NotImplementedException(); 
    } 

    #endregion 
} 

public partial class MasterPage : System.Web.UI.MasterPage 
{ 
    private ClassA IntefaceImplementor = new ClassA(); 
    protected void Page_Load(object sender, EventArgs e) 
    { 

    } 
} 

public partial class _Default : System.Web.UI.Page 
{ 

    private ClassA InterfaceImplementor = new ClassA(); 
    protected void Page_Load(object sender, EventArgs e) 
    { 

    } 
} 
+0

这就是我的想法。任何细节? – John 2010-11-10 17:30:56