tags:

views:

88

answers:

2

Hi all,

I have this code structure:

public abstract class ContentEntryBase
{
    public string UniqueIdentifier;
    public string Title;

    public abstract ContentType contentType { get;}
}

public class TextArticle : ContentEntryBase
{
    // Holds plain / HTML text as content

    public override ContentType contentType { 
        get { return ContentType.TextArticle; } }
}

public class Series : ContentEntryBase
{
    // Holds a series of TextArticles, Separators 
    // and Prefaces as content

    ContentEntryBase[] Articles = null;

    public override ContentType contentType { 
        get { return ContentType.Series; } }
}

ContentEntryBase isn't an interface as so to allow me to perform basic actions valid to all descendant types from the base class.

I have a WinForms application utilizing these classes, and I want it to be able to call a method on ContentEntryBase (meaning, without realizing the exact type of the object at hand) for both displaying the content, and editing it.

So for example, TextArticle would show a TextBox / WYSIWYG editor when accessed for editing, and return a string when accessed for display. When Series is accessed for editing, it would show a list of all elements it contains (derived from ContentEntryBase) where those items could be edited or sorted. When accessed for display, it would show a list of all children. I also have several more derived types, but these are the basic ones.

I tried thinking of the best contract to define for this, but came with no good solution. Can this be made in a way where it could be used in both WinForms and WebForms or MVC? Can display and edit functionalities use the same contract / function (GetContent() or something)?

I know using .NET 2.0 only limiting this even further, but this is what I have to use...

Thanks in advance!

Itamar.

A: 

There isn't a good solution for this. WPF makes this kind of thing possible, but you're stuck in 2.0. But even with WPF, it's a non-trivial app to write.

McKay
How would the solution with WPF look like?
synhershko
Like I said, it's non trivial. I wrote code that edited arbitrary (though must meet certain criteria) objects, and it took a couple weeks, and it's far from perfect.
McKay
A: 

Could you not just have an abstract ShowEditor method on ContentEntryBase.

public class TextArticle : ContentEntryBase
{
    public override void ShowEditor ()
    {
        var editor = new FrmTextEditor (this);
        editor.ShowDialog();
    }
}

where the FrmTextEditor CTor takes an instance of TextArticle which it will modify and provides the UI to do such a thing?

The other option I can think of is to provide method which returns a UserControl which provides the same UI functionality.

**Edit **

Re-reading for display - assuming you are turning it all into text you could just have a method which returns a List<string> which is populated as required TextArticle would only have a single string in the collection and others could have multiple of them. You could even create some form of DisplayObject which wraps the string and provides additional data for you to use when displaying it.

Courtney de Lautour