Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Stymied?
Message
From
25/07/2011 19:38:51
 
 
General information
Forum:
ASP.NET
Category:
Other
Title:
Environment versions
Environment:
C# 4.0
Miscellaneous
Thread ID:
01519092
Message ID:
01519120
Views:
44
>>>Assume this class:
public partial class Library : EntityObject
>>>    {
>>>         public Library Parent
>>>        {
>>>            get { return new Library();}
>>>         }
>>>    }
As you may guess given the EntityObject inheritance the really thing is more complex, generated by the EDMX builder and cannot be modified. I'd like it to implement an Interface:
public interface ITreeview
>>>    {
>>>        ITreeview Parent { get; }
>>>    }
But (I suppose expectedly) adding this won't compile:
public partial class Library : ITreeview
>>>    {
>>>    }
Is there anyway of achieving what I want ?
>>
>>And yes, that should compile, as long as you implement ITreeview in your custom partial class..
>
>The Library class (as in the first snippet above) has the 'Parent' property which is an instance of the Library class - but to compile it would have to be defined as ITreeview.Parent

Would this work for you?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
  {
  class Program
    {
    static void Main(string[] args)
      {
      Library lib = new Library();
      ITreeview itv = (ITreeview)lib;
      Console.WriteLine(((Library)itv.Parent).Name);
      Console.ReadLine();
      }
    }

  public interface ITreeview
    {
    ITreeview Parent { get; }
    }

  public partial class Library
    {
    public Library Parent { get { return new Library(); } }
    public string Name { get { return "Hello World"; } }
    }

  public partial class Library : ITreeview
    {
    ITreeview ITreeview.Parent
      {
      get { return this.Parent; }
      }
    }
  }
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform