Пример #1
0
       private static string GenerateNvimTypes(NvimAPIMetadata apiMetadata)
       {
           return(string.Join("", apiMetadata.Types.Select(type =>
           {
               var name = "Nvim" + StringUtil.ConvertToCamelCase(type.Key, true);
               return $@"
 public class {name}
 {{
   private readonly NvimAPI _api;
   private readonly MessagePackExtendedTypeObject _msgPackExtObj;
   internal {name}(NvimAPI api, MessagePackExtendedTypeObject msgPackExtObj)
   {{
     _api = api;
     _msgPackExtObj = msgPackExtObj;
   }}
   {
   GenerateNvimMethods(
     apiMetadata.Functions.Where(function =>
       !IsDeprecated(function) && function.Method
       && function.Name.StartsWith(type.Value.Prefix)),
     type.Value.Prefix, true)
   }
 }}";
           })));
       }
Пример #2
0
        private static string GenerateCSharpClass(NvimAPIMetadata apiMetadata) => @"
using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Runtime.Serialization;
using MsgPack;
using NvimClient.NvimMsgpack.Models;

namespace NvimClient.API
{
  public partial class NvimAPI
  {
" +
        GenerateNvimUIEvents(
            apiMetadata.UIEvents.Where(uiEvent => !IsDeprecated(uiEvent))) + @"
" + GenerateNvimMethods(
            apiMetadata.Functions.Where(function =>
                                        !IsDeprecated(function) && !function.Method),
            "nvim_", false) + @"
" + GenerateNvimTypes(apiMetadata) + @"
" + GenerateNvimUIEventArgs(
            apiMetadata.UIEvents.Where(uiEvent => !IsDeprecated(uiEvent))) + @"
    private void CallUIEventHandler(string eventName, object[] args)
    {
      switch (eventName)
      {
  " + GenerateNvimUIEventCalls(
            apiMetadata.UIEvents.Where(uiEvent => !IsDeprecated(uiEvent))) + @"
      }
    }

    private object GetExtensionType(MessagePackExtendedTypeObject msgPackExtObj)
    {
      switch (msgPackExtObj.TypeCode)
      {
" + GenerateNvimTypeCases(apiMetadata.Types) + @"
        default:
          throw new SerializationException(
            $""Unknown extension type id {msgPackExtObj.TypeCode}"");
      }
    }
  }
}";