private void Generate(CSharpGeneratorContext context, IMethodDeclaration declaration, IList <GeneratorDeclaredElement <ITypeOwner> > elements, CSharpElementFactory factory) { var builder = new StringBuilder(); builder.Append("{").AppendFormat("{0}(bytes, 0);", ReadMethodGenerator.Instance.MethodName).Append("}"); IBlock body = factory.CreateBlock(builder.ToString()); declaration.SetBody(body); }
private static void Generate(CSharpGeneratorContext context, IMethodDeclaration declaration, IList <GeneratorDeclaredElement <ITypeOwner> > elements, CSharpElementFactory factory) { var owner = (IParametersOwner)declaration.DeclaredElement; if (owner == null) { return; } var ctx = new TypeHandlingContext(context); var size = ctx.GetSizeVariableName(); ctx.Builder.Append("{"); ctx.Builder.AppendFormat("var {0} = 0;", size); if (elements.Count > 0) { foreach (var element in elements) { ctx.Resolve(element.DeclaredElement); ITypeHandler handler = TypeHandlers.All.SingleOrDefault(h => h.CanHandle(ctx)); if (handler != null) { handler.HandleGetSize(ctx); } } } ctx.Builder.AppendFormat("return {0};", size); ctx.Builder.Append("}"); IBlock body = factory.CreateBlock(ctx.Builder.ToString(), ctx.Args.ToArray()); declaration.SetBody(body); }
protected override void Generate(CSharpGeneratorContext context, IMethodDeclaration declaration, IList <GeneratorDeclaredElement <ITypeOwner> > elements, CSharpElementFactory factory) { var owner = (IParametersOwner)declaration.DeclaredElement; if (owner == null) { return; } var ctx = new TypeHandlingContext(context); ctx.Builder.Append("{"); ctx.Builder.Append("var index = startIndex;"); ctx.Builder.Append("Byte[] tmp;"); if (elements.Count > 0) { foreach (var element in elements) { ctx.Resolve(element.DeclaredElement); ITypeHandler handler = TypeHandlers.All.SingleOrDefault(h => h.CanHandle(ctx)); if (handler != null) { handler.HandleRead(ctx); } } } ctx.Builder.Append("return index;"); ctx.Builder.Append("}"); IBlock body = factory.CreateBlock(ctx.Builder.ToString(), ctx.Args.ToArray()); declaration.SetBody(body); }