Bom vamos direto ao assunto, veja o exemplo abaixo:
[csharp] #region Fluent Examplepublic interface IConfigurationFluent
{
IConfigurationFluent SetColor(string color);
IConfigurationFluent SetHeight(int height);
IConfigurationFluent SetLength(int length);
IConfigurationFluent SetDepth(int depth);
}
public class ConfigurationFluent : IConfigurationFluent
{
string color;
int height;
int length;
int depth;
public IConfigurationFluent SetColor(string color)
{
this.color = color;
return this;
}
public IConfigurationFluent SetHeight(int height)
{
this.height = height;
return this;
}
public IConfigurationFluent SetLength(int length)
{
this.length = length;
return this;
}
public IConfigurationFluent SetDepth(int depth)
{
this.depth = depth;
return this;
}
#endregion
public class ExampleProgram
{
public static void Main(string[] args)
{
//Standard Example
IConfiguration config = new Configuration
{
Color = "blue",
Height = 1,
Length = 2,
Depth = 3
};
//Fluent Example
IConfigurationFluent fluentConfig =
new ConfigurationFluent().SetColor("blue")
.SetHeight()
.SetLength(2)
.SetDepth(3);
}
}
[/csharp]
Referência:
Posts recentes
Categorias
- .Net (25)
- .Net Standard (2)
- .NetCore (3)
- Android (3)
- Arquitetura de Software (6)
- Asp.Net (6)
- C# (17)
- Dependency Injection (1)
- Entity Framework (3)
- Eventos (2)
- Fluent Interface (2)
- Gerenciamento de Projetos (1)
- IOS (3)
- NHibernate (4)
- ORM (5)
- Silverlight (3)
- Uncategorized (5)
- Visual Studio (10)
- WCF (5)
- Windows Azure (2)
- WPF (3)
- Xamarin (6)