11using Botticelli . Framework . Exceptions ;
2+ using Botticelli . Interfaces ;
23
34namespace Botticelli . Framework . SendOptions
45{
@@ -7,18 +8,19 @@ namespace Botticelli.Framework.SendOptions
78 /// (for example you can use InlineKeyboardMarkup as T)
89 /// </summary>
910 /// <typeparam name="T"></typeparam>
10- public class SendOptionsBuilder < T >
11- where T : class
11+ public class SendOptionsBuilder < T > : ISendOptionsBuilder < T > where T : class
1212 {
13- private T innerObject = default ;
13+ private T _innerObject = default ;
1414
1515 protected SendOptionsBuilder ( )
1616 {
1717 }
1818
19- public T Create ( params object [ ] args )
19+ protected SendOptionsBuilder ( T innerObject ) => this . _innerObject = innerObject ;
20+
21+ public ISendOptionsBuilder < T > Create ( params object [ ] args )
2022 {
21- if ( innerObject != default )
23+ if ( _innerObject != default )
2224 throw new BotException ( $ "You shouldn't use { nameof ( Create ) } () method twice!") ;
2325
2426 var constructors = typeof ( T )
@@ -28,9 +30,9 @@ public T Create(params object[] args)
2830 // no params? ok => let's seek a parameterless constructor!
2931 if ( ( args == null || ! args . Any ( ) ) && constructors . Any ( c => ! c . GetParameters ( ) . Any ( ) ) )
3032 {
31- innerObject = Activator . CreateInstance < T > ( ) ;
33+ _innerObject = Activator . CreateInstance < T > ( ) ;
3234
33- return innerObject ;
35+ return this ;
3436 }
3537
3638 // Let's see if we can process parameter set and put it to a constructor|initializer
@@ -41,19 +43,21 @@ public T Create(params object[] args)
4143
4244
4345
44- return innerObject ;
46+ return this ;
4547 }
4648
47- public T Set ( Func < T > func )
49+ public ISendOptionsBuilder < T > Set ( Func < T , T > func )
4850 {
49- func ? . Invoke ( ) ;
51+ func ? . Invoke ( _innerObject ) ;
5052
51- return innerObject ;
53+ return this ;
5254 }
5355
5456 public T Build ( )
55- => innerObject ;
57+ => _innerObject ;
5658
5759 public static SendOptionsBuilder < T > CreateBuilder ( ) => new ( ) ;
60+
61+ public static SendOptionsBuilder < T > CreateBuilder ( T input ) => new ( input ) ;
5862 }
5963}
0 commit comments