FunctionTemplate.cs 1.3 KB

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