mardi 21 mai 2019

Is there a way to implicitly reference an object in a has-a relationship without explicitly using the object name?

I want to use a contained object "implicitly", as an alias, like if it were "this" relationship. Does C# support anything like this or what design pattern might come closest to the intent expressed? The alternative I am looking at is to define a delegate and implement it in the MyHasA class.

Pseudo example A

 public class MyClass
    {
    public MyHasA hasA;

    public void MyMethod()
    {
      implicit(hasA)->
     {
       Print("Hello World"); // vs hasA.Print("Hello World") 

     }
    }
  }

Pseudo example B

 public class MyClass
    {
    public MyHasA hasA;
    using implicit hasA;
    public void MyMethod()
    {
       Print("Hello World"); // vs hasA.Print("Hello World")          
     }
    }
  }

Aucun commentaire:

Enregistrer un commentaire