0

I have class A in namespace do.it.like.a.boss,

After that I am creating another class A that it will be partial and the namespace will be do.it.like.a.child

Until now everything sounds good ... but

I have prop that I want to return the partial class and the actual data in my list is the original one

public do.it.like.a.child.A A
{
   get
   {
      return my list.Where(x => x.id == someid).FirstOrDeffult(); // the list is do.it.like.a.boss.A objects
   }
}

Is it even possible to do something in that case ?

Thanks

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Leon Barkan
  • 2,676
  • 2
  • 19
  • 43
  • 4
    As [this](https://stackoverflow.com/a/4504306/9363973) answer states, you cannot have two parts of a class in two different namespaces. do.it.like.a.boss.A and do.it.like.a.child.A are two entirely different types that just happen to share a name – MindSwipe Jul 09 '19 at 06:22
  • Can you show more code? It is very hard to ascertain what you are trying to do. A partial class must have all "fragments" in the same namespace. – Tanveer Badar Jul 09 '19 at 06:22
  • What is even the purpose of your idea (spreading partial classes over namespaces)? – Ackdari Jul 09 '19 at 06:29
  • 1
    You cannot have a partial class in two namespaces. https://stackoverflow.com/a/14446250/1273882 – Ankush Jain Jul 09 '19 at 06:40
  • @Ackdari , reverse engineering thought maybe there are some new features to deal with that kind of situation – Leon Barkan Jul 09 '19 at 06:55

1 Answers1

1

This is impossible, because each part of a partial class needs to be in the same namespace. Take this as an example:

namespace Test.Foo
{
    public partial class Bar
    {
        public string Hello => "World";
    }
}

namespace Test.Bar
{
    public partial class Bar
    {
        // This is impossible, as Test.Foo.Bar and Test.Bar.Bar are 2 entirely different classes
        public string World => Hello;
    }
}

Here is the MSDN documentation on partial classes.

P.S Why would you need something like this?

MindSwipe
  • 7,193
  • 24
  • 47
  • thought so... reverse engineering (not my code that I should add functionality) ok.. need to change list datasource, thanks – Leon Barkan Jul 09 '19 at 06:44