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()); }
/// <summary> /// Creates a segment of code inside this function. /// This signature allows a fluent code to "emit" one or more insertion points. /// </summary> /// <typeparam name="T">The function scope type.</typeparam> /// <param name="this">This function scope.</param> /// <param name="part">The function 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 function scope writer to enable fluent syntax.</returns> public static T CreatePart <T>(this T @this, out IFunctionScopePart part, bool top = false) where T : IFunctionScope { part = @this.CreatePart(top); return(@this); }