FunctionTemplate.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace InABox.DynamicGrid
  7. {
  8. public interface IFunctionParameter
  9. {
  10. string Name { get; }
  11. string ParamType { get; }
  12. }
  13. public class FunctionParameter : IFunctionParameter
  14. {
  15. public string Name { get; set; }
  16. public string ParamType { get; set; }
  17. public FunctionParameter(string name, string paramType)
  18. {
  19. Name = name;
  20. ParamType = paramType;
  21. }
  22. }
  23. public class FunctionParameter<TParam> : IFunctionParameter
  24. {
  25. public string Name { get; set; }
  26. public string ParamType => typeof(TParam).ToString();
  27. public FunctionParameter(string name)
  28. {
  29. Name = name;
  30. }
  31. }
  32. public class FunctionTemplate
  33. {
  34. public string Name { get; set; }
  35. public string Description { get; set; }
  36. public List<IFunctionParameter> Parameters { get; set; }
  37. public string Template => $"{Name}({string.Join(", ", Parameters.Select(x => x.Name))})";
  38. public string Tooltip => $"{Name}({string.Join(", ", Parameters.Select(x => string.IsNullOrWhiteSpace(x.ParamType) ? x.Name : $"{x.ParamType} {x.Name}"))})";
  39. }
  40. }