├── ExtensibilityForMasses
├── Op.cs
├── Env.cs
├── Forest.cs
├── NormType.cs
├── SqlQuery.cs
├── SqlTable.cs
├── Expression.cs
├── ISchema.cs
├── IIntAlg.cs
├── IValue.cs
├── IExp.cs
├── IStmt.cs
├── IPrint.cs
├── IIntVal.cs
├── IExpIntBool.cs
├── IIntValue.cs
├── IIntExp.cs
├── ExtensibilityForMasses.csproj
├── IBoolAlg.cs
├── IIntBoolAlg.cs
├── BoolFactory.cs
├── IntBoolFactory2.cs
├── IStmtAlg.cs
├── VInt.cs
├── VBool.cs
├── EvalIntAlg.cs
├── IPartitionFactory.cs
├── Lit.cs
├── IntFactory.cs
├── Print2.cs
├── Bool.cs
├── IntBoolFactory.cs
├── Add.cs
├── Iff.cs
├── Eval.cs
├── Debug.cs
├── ISqlTranslation.cs
├── Pair.cs
├── Combine.cs
├── IntAlg.cs
├── GCombine.cs
├── Union.cs
├── GUnion.cs
├── IBatchFactory.cs
├── IntPrint.cs
├── IntBoolPrint.cs
└── StmtFactory.cs
├── ExtensibilityForMasses.Test
├── ExtensibilityForMasses.Test.csproj
└── ExpTests.cs
├── ExtensibilityForMasses.sln
├── README.md
├── .gitattributes
└── .gitignore
/ExtensibilityForMasses/Op.cs:
--------------------------------------------------------------------------------
1 | namespace Ploeh.Study.ExtensibilityForMasses
2 | {
3 | public class Op
4 | {
5 | }
6 | }
--------------------------------------------------------------------------------
/ExtensibilityForMasses/Env.cs:
--------------------------------------------------------------------------------
1 | namespace Ploeh.Study.ExtensibilityForMasses
2 | {
3 | public class Env
4 | {
5 | }
6 | }
--------------------------------------------------------------------------------
/ExtensibilityForMasses/Forest.cs:
--------------------------------------------------------------------------------
1 | namespace Ploeh.Study.ExtensibilityForMasses
2 | {
3 | public class Forest
4 | {
5 | }
6 | }
--------------------------------------------------------------------------------
/ExtensibilityForMasses/NormType.cs:
--------------------------------------------------------------------------------
1 | namespace Ploeh.Study.ExtensibilityForMasses
2 | {
3 | public class NormType
4 | {
5 | }
6 | }
--------------------------------------------------------------------------------
/ExtensibilityForMasses/SqlQuery.cs:
--------------------------------------------------------------------------------
1 | namespace Ploeh.Study.ExtensibilityForMasses
2 | {
3 | public class SqlQuery
4 | {
5 | }
6 | }
--------------------------------------------------------------------------------
/ExtensibilityForMasses/SqlTable.cs:
--------------------------------------------------------------------------------
1 | namespace Ploeh.Study.ExtensibilityForMasses
2 | {
3 | public class SqlTable
4 | {
5 | }
6 | }
--------------------------------------------------------------------------------
/ExtensibilityForMasses/Expression.cs:
--------------------------------------------------------------------------------
1 | namespace Ploeh.Study.ExtensibilityForMasses
2 | {
3 | public class Expression
4 | {
5 | }
6 | }
--------------------------------------------------------------------------------
/ExtensibilityForMasses/ISchema.cs:
--------------------------------------------------------------------------------
1 | namespace Ploeh.Study.ExtensibilityForMasses
2 | {
3 | public interface ISchema
4 | {
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/ExtensibilityForMasses/IIntAlg.cs:
--------------------------------------------------------------------------------
1 | namespace Ploeh.Study.ExtensibilityForMasses
2 | {
3 | public interface IIntAlg
4 | {
5 | A Lit(int x);
6 | A Add(A e1, A e2);
7 | }
8 | }
--------------------------------------------------------------------------------
/ExtensibilityForMasses/IValue.cs:
--------------------------------------------------------------------------------
1 | namespace Ploeh.Study.ExtensibilityForMasses
2 | {
3 | public interface IValue
4 | {
5 | int Int { get; }
6 | bool Bool { get; }
7 | }
8 | }
--------------------------------------------------------------------------------
/ExtensibilityForMasses/IExp.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace Ploeh.Study.ExtensibilityForMasses
8 | {
9 | public interface IExp
10 | {
11 | IValue Eval();
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/ExtensibilityForMasses/IStmt.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace Ploeh.Study.ExtensibilityForMasses
8 | {
9 | public interface IStmt
10 | {
11 | void Eval();
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/ExtensibilityForMasses/IPrint.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace Ploeh.Study.ExtensibilityForMasses
8 | {
9 | public interface IPrint
10 | {
11 | string Print();
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/ExtensibilityForMasses/IIntVal.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace Ploeh.Study.ExtensibilityForMasses
8 | {
9 | public interface IIntVal
10 | {
11 | A Lit(int x);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/ExtensibilityForMasses/IExpIntBool.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace Ploeh.Study.ExtensibilityForMasses
8 | {
9 | public interface IExpIntBool : IBoolAlg, IIntAlg
10 | {
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/ExtensibilityForMasses/IIntValue.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace Ploeh.Study.ExtensibilityForMasses
8 | {
9 | public interface IIntValue
10 | {
11 | int Int { get; }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/ExtensibilityForMasses/IIntExp.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace Ploeh.Study.ExtensibilityForMasses
8 | {
9 | public interface IIntExp : IIntVal
10 | {
11 | A Add(A x, A y);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/ExtensibilityForMasses/ExtensibilityForMasses.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net5.0
5 | Ploeh.Study.ExtensibilityForMasses
6 | Ploeh.Study.ExtensibilityForMasses
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/ExtensibilityForMasses/IBoolAlg.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace Ploeh.Study.ExtensibilityForMasses
8 | {
9 | public interface IBoolAlg
10 | {
11 | A Bool(bool b);
12 | A Iff(A b, A e1, A e2);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/ExtensibilityForMasses/IIntBoolAlg.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace Ploeh.Study.ExtensibilityForMasses
8 | {
9 | public interface IIntBoolAlg : IIntAlg
10 | {
11 | A Bool(bool b);
12 | A Iff(A e1, A e2, A e3);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/ExtensibilityForMasses/BoolFactory.cs:
--------------------------------------------------------------------------------
1 | namespace Ploeh.Study.ExtensibilityForMasses
2 | {
3 | public class BoolFactory : IBoolAlg
4 | {
5 | public IExp Bool(bool b)
6 | {
7 | return new Bool(b);
8 | }
9 |
10 | public IExp Iff(IExp b, IExp e1, IExp e2)
11 | {
12 | return new Iff(b, e1, e2);
13 | }
14 | }
15 | }
--------------------------------------------------------------------------------
/ExtensibilityForMasses/IntBoolFactory2.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace Ploeh.Study.ExtensibilityForMasses
8 | {
9 | public class IntBoolFactory2 : Union
10 | {
11 | public IntBoolFactory2() : base(new BoolFactory(), new IntFactory())
12 | {
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/ExtensibilityForMasses/IStmtAlg.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace Ploeh.Study.ExtensibilityForMasses
8 | {
9 | public interface IStmtAlg : IIntBoolAlg
10 | {
11 | E Var(string x);
12 | E Assign(string x, E e);
13 | S Expr(E e);
14 | S Comp(S e1, S e2);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/ExtensibilityForMasses/VInt.cs:
--------------------------------------------------------------------------------
1 | namespace Ploeh.Study.ExtensibilityForMasses
2 | {
3 | public class VInt : IValue
4 | {
5 | public VInt(int x)
6 | {
7 | Int = x;
8 | }
9 |
10 | public int Int { get; }
11 |
12 | public bool Bool => throw new System.NotImplementedException();
13 |
14 | public override string ToString()
15 | {
16 | return Int.ToString();
17 | }
18 | }
19 | }
--------------------------------------------------------------------------------
/ExtensibilityForMasses/VBool.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace Ploeh.Study.ExtensibilityForMasses
8 | {
9 | public class VBool : IValue
10 | {
11 | public VBool(bool b)
12 | {
13 | Bool = b;
14 | }
15 |
16 | public int Int => throw new NotImplementedException();
17 |
18 | public bool Bool { get; }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/ExtensibilityForMasses/EvalIntAlg.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace Ploeh.Study.ExtensibilityForMasses
8 | {
9 | public class EvalIntAlg : IIntAlg
10 | {
11 | public int Add(int e1, int e2)
12 | {
13 | return e1 + e2;
14 | }
15 |
16 | public int Lit(int x)
17 | {
18 | return x;
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/ExtensibilityForMasses/IPartitionFactory.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace Ploeh.Study.ExtensibilityForMasses
8 | {
9 | public interface IPartitionFactory : IBatchFactory
10 | {
11 | E Other(object external, params E[] subs);
12 | E DynamicCall(E target, string method, IEnumerable args);
13 | E Mobile(string type, object obj, E exp);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/ExtensibilityForMasses/Lit.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace Ploeh.Study.ExtensibilityForMasses
8 | {
9 | public class Lit : IExp
10 | {
11 | private readonly int x;
12 |
13 | public Lit(int x)
14 | {
15 | this.x = x;
16 | }
17 |
18 | public IValue Eval()
19 | {
20 | return new VInt(x);
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/ExtensibilityForMasses/IntFactory.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace Ploeh.Study.ExtensibilityForMasses
8 | {
9 | public class IntFactory : IIntAlg
10 | {
11 | public IExp Add(IExp e1, IExp e2)
12 | {
13 | return new Add(e1, e2);
14 | }
15 |
16 | public IExp Lit(int x)
17 | {
18 | return new Lit(x);
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/ExtensibilityForMasses/Print2.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace Ploeh.Study.ExtensibilityForMasses
8 | {
9 | public class Print2 : IIntAlg
10 | {
11 | public string Add(string e1, string e2)
12 | {
13 | return $"{e1} + {e2}";
14 | }
15 |
16 | public string Lit(int x)
17 | {
18 | return x.ToString();
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/ExtensibilityForMasses/Bool.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace Ploeh.Study.ExtensibilityForMasses
8 | {
9 | public sealed class Bool : IExp
10 | {
11 | private readonly bool b;
12 |
13 | public Bool(bool b)
14 | {
15 | this.b = b;
16 | }
17 |
18 | public IValue Eval()
19 | {
20 | return new VBool(b);
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/ExtensibilityForMasses/IntBoolFactory.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace Ploeh.Study.ExtensibilityForMasses
8 | {
9 | public class IntBoolFactory : IntFactory, IIntBoolAlg
10 | {
11 | public IExp Bool(bool b)
12 | {
13 | return new Bool(b);
14 | }
15 |
16 | public IExp Iff(IExp e1, IExp e2, IExp e3)
17 | {
18 | return new Iff(e1, e2, e3);
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/ExtensibilityForMasses/Add.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace Ploeh.Study.ExtensibilityForMasses
8 | {
9 | public class Add : IExp
10 | {
11 | private readonly IExp l;
12 | private readonly IExp r;
13 |
14 | public Add(IExp l, IExp r)
15 | {
16 | this.l = l;
17 | this.r = r;
18 | }
19 |
20 | public IValue Eval()
21 | {
22 | return new VInt(l.Eval().Int + r.Eval().Int);
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/ExtensibilityForMasses/Iff.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace Ploeh.Study.ExtensibilityForMasses
8 | {
9 | public sealed class Iff : IExp
10 | {
11 | private readonly IExp e1;
12 | private readonly IExp e2;
13 | private readonly IExp e3;
14 |
15 | public Iff(IExp e1, IExp e2, IExp e3)
16 | {
17 | this.e1 = e1;
18 | this.e2 = e2;
19 | this.e3 = e3;
20 | }
21 |
22 | public IValue Eval()
23 | {
24 | return e1.Eval().Bool ? e2.Eval() : e3.Eval();
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/ExtensibilityForMasses/Eval.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace Ploeh.Study.ExtensibilityForMasses
8 | {
9 | public class Eval : IIntExp
10 | where A : IIntValue
11 | where V : IIntVal
12 | {
13 | protected readonly V valFact;
14 |
15 | public Eval(V valFact)
16 | {
17 | this.valFact = valFact;
18 | }
19 |
20 | public A Lit(int x)
21 | {
22 | return valFact.Lit(x);
23 | }
24 |
25 | public A Add(A x, A y)
26 | {
27 | return valFact.Lit(x.Int + y.Int);
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/ExtensibilityForMasses/Debug.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace Ploeh.Study.ExtensibilityForMasses
8 | {
9 | public class Debug : Combine
10 | {
11 | public Debug() : base(new IntFactory(), new IntPrint())
12 | {
13 | }
14 |
15 | public override Pair Add(Pair e1, Pair e2)
16 | {
17 | Console.WriteLine($"The first expression {e1.TheB.Print()} evaluates to {e1.TheA.Eval()}");
18 | Console.WriteLine($"The second expression {e2.TheB.Print()} evaluates to {e2.TheA.Eval()}");
19 | return base.Add(e1, e2);
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/ExtensibilityForMasses/ISqlTranslation.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace Ploeh.Study.ExtensibilityForMasses
8 | {
9 | public interface ISqlTranslation
10 | {
11 | void ToSql(StringBuilder sb, IEnumerable