المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Dynamically load collection manager with an object in different namespace



C# Programming
04-27-2009, 01:26 AM
Based on the code below, how do I dynamically create a Gake.Orchard.Business.PageContent object in the Gake.Data.Base.DataCollection.Retrieve method?

Below is "working" code; however, I don't think I should be explicitly passing in "typeof(typePageContent)", in order to get it to work. I believe I should be able to get that from "typDataObject". The syntax that I'd like to use, is commented out; however, the line "typDataObject typObj = new typDataObject();" created Gake.Orchard.Data.PageContent, when I need it to create Gake.Orchard.Business.PageContent.

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
PageContentCollection pcc = new PageContentCollection(2,this.GetType().Name);
//...
}
}

namespace Gake.Orchard.Business
{
public class PageContentCollection : Gake.Orchard.Data.PageContentCollection
{
//...
}
}

namespace Gake.Orchard.Data
{
public abstract class PageContentCollection : Gake.Data.Base.DataCollection where typPageContent : PageContent
{
public PageContentCollection(int Panel, string Page)
{
//DataResult result = base.Retrieve("Panel = @1 and Page = @2", Panel, Page);
DataResult result = base.Retrieve(typeof(typPageContent), "Panel = @1 and Page = @2", Panel, Page);
//...
}
}
}

namespace Gake.Data.Base
{
public abstract class DataCollection : CollectionBase where typDataObject : DataObject//, new()
{
//public DataResult Retrieve(string Conditions, params object[] Values)
public DataResult Retrieve(Type TypeOfChild, string Conditions, params object[] Values)
{
//...
//typDataObject typObj = new typDataObject();
Object objChild = Activator.CreateInstance(TypeOfChild);
//...
}
}
}