0

How to create Lambda extensions chains like this in C#?

someVar.GetOwnProperites().With.DefaultValues.From(datasource);

I saw this syntax in DI like Automapper I think. But I'm not sure how to do it..

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
raxinaga
  • 411
  • 1
  • 6
  • 18

1 Answers1

0

Write an extension method which returns the same object

e.g

public static class Extensions{
   public static WhateverYouWantToOperateOn With(this WhateverYouWantToOperateOn source){
   //your logic 
   return source;      
}
}

For things like With and DefaultValues, there would be a property in the class which returns the instance of the same class.

Mittal Patel
  • 2,732
  • 14
  • 23
Pratap Bhaskar
  • 408
  • 3
  • 11