Esempio n. 1
0
        public void merging_code_space_with_parts()
        {
            var c1 = CodeWorkspace.Create();
            var c2 = CodeWorkspace.Create();

            INamespaceScopePart c1Part1    = c1.Global.CreatePart();
            INamespaceScope     c1Part1Sub = c1Part1.CreatePart();

            c1.Global.Append("n°0 (but after having created the 2 parts!)").NewLine();
            INamespaceScope c1Part2 = c1.Global.CreatePart();

            c1Part2.Append("2 - n°0").NewLine();
            c1Part2.Append("2 - n°1").NewLine();
            c1Part1.Append("1 - n°0").NewLine();
            c1Part1.Append("1 - n°1").NewLine();
            c1.Global.Append("n°1").NewLine();
            c1Part1Sub.Append("Hop! (Later but in a sup part of the first part).").NewLine();

            INamespaceScope c2Part1 = c1.Global.CreatePart();
            INamespaceScope c2Part2 = c1.Global.CreatePart();

            c2.Global.Append("!n°0").NewLine();
            c2Part2.Append("!2 - n°0").NewLine();
            c2Part2.Append("!2 - n°1").NewLine();
            c2Part1.Append("!1 - n°0").NewLine();
            c2Part1.Append("!1 - n°1").NewLine();
            c2.Global.Append("!n°1").NewLine();

            c1.MergeWith(c2);

            string code = c1.GetGlobalSource().Trim();

            code.Should().Be(@"
Hop! (Later but in a sup part of the first part).
1 - n°0
1 - n°1
n°0 (but after having created the 2 parts!)
2 - n°0
2 - n°1
n°1
!1 - n°0
!1 - n°1
!2 - n°0
!2 - n°1
!n°0
!n°1
".Trim().ReplaceLineEndings());
        }
Esempio n. 2
0
        public void playing_with_parts()
        {
            INamespaceScope     g                      = CodeWorkspace.Create().Global;
            INamespaceScopePart gSub                   = g.CreatePart();
            INamespaceScopePart gSub2                  = gSub.CreatePart();
            ITypeScope          gSub2Type1             = gSub2.CreateType("class GSub2Type1");
            ITypeScope          gSub2Type2             = gSub2.CreateType("class GSub2Type2");
            ITypeScopePart      gSub2Type1Part1        = gSub2Type1.CreatePart();
            ITypeScopePart      gSub2Type1Part2        = gSub2Type1.CreatePart();
            IFunctionScope      gSub2Type1Part2F1      = gSub2Type1Part2.CreateFunction("void Action()");
            IFunctionScopePart  gSub2Type1Part2F1Part1 = gSub2Type1Part2F1.CreatePart();

            g.Append("g:");
            gSub.Append("gSub:");
            gSub2.Append("gSub2:");
            gSub2Type1.Append("gSub2Type1:");
            gSub2Type2.Append("gSub2Type2:");
            gSub2Type1Part1.Append("gSub2Type1Part1:");
            gSub2Type1Part2.Append("gSub2Type1Part2:");
            gSub2Type1Part2F1.Append("gSub2Type1Part2F1:");
            gSub2Type1Part2F1Part1.Append("gSub2Type1Part2F1Part1:");

            var s = g.ToString().Trim();

            s.Should().Be(@"
gSub2:
gSub:
g:
class GSub2Type1
{
gSub2Type1Part1:
gSub2Type1Part2:
gSub2Type1:
void Action()
{
gSub2Type1Part2F1Part1:
gSub2Type1Part2F1:
}
}
class GSub2Type2
{
gSub2Type2:
}".Trim().ReplaceLineEndings());
        }
Esempio n. 3
0
 /// <summary>
 /// Creates a segment of code inside this namespace.
 /// This signature allows a fluent code to "emit" one or more insertion points.
 /// </summary>
 /// <typeparam name="T">The namespace scope type.</typeparam>
 /// <param name="this">This namespace scope.</param>
 /// <param name="part">The namespace part to use to inject code at this location (or at the top).</param>
 /// <param name="top">Optionally creates the new part at the start of the code instead of at the current writing position in the code.</param>
 /// <returns>This namespace scope writer to enable fluent syntax.</returns>
 public static T CreatePart <T>(this T @this, out INamespaceScopePart part, bool top = false) where T : INamespaceScope
 {
     part = @this.CreatePart(top);
     return(@this);
 }