fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Protocol
  6. {
  7. #region Consts
  8. public enum ObjectType{
  9. Register,
  10. Data,
  11. Clock,
  12. Profile
  13. }
  14. public enum DataType{
  15. INT_16,
  16. INT_32,
  17. INT_64,
  18. UINT_16,
  19. UINT_32,
  20. UINT_64,
  21. BYTE,
  22. FLOAT_32,
  23. FLOAT_64,
  24. UFLOAT_32,
  25. UFLOAT_64,
  26. STRING,
  27. BYTE_STRING,
  28. ARRAY,
  29. STRUCT,
  30. TIME
  31. }
  32. #endregion
  33. public class ProtocolObject
  34. {
  35. private readonly Dictionary<int, ObjectAttribute> _attributes;
  36. private readonly string _code;
  37. private readonly string _name;
  38.  
  39. public ProtocolObject(string code, string name)
  40. {
  41. if (code is null)
  42. {
  43. throw new ArgumentNullException(nameof(code));
  44. }
  45.  
  46. if (name is null)
  47. {
  48. throw new ArgumentNullException(nameof(name));
  49. }
  50.  
  51. _code = code;
  52. _name = name;
  53. _attributes = new Dictionary<int, ObjectAttribute>();
  54. }
  55. public string Code => _code;
  56. public string Name => _name;
  57. public ObjectType Type {get;set;}
  58.  
  59. public void AddAttribute(ObjectAttribute attribute)
  60. {
  61. if(attribute is null)
  62. throw new ArgumentNullException(nameof(attribute));
  63. if(_attributes.Any(x=>x.Key == attribute.Index))
  64. throw new InvalidOperationException("Атрибут с данным индексом присутствует в объекте");
  65. if (attribute.Index <= 0)
  66. throw new ArgumentException("Индекс должен быть положительным числом больше 0");
  67. _attributes.Add(attribute.Index, attribute);
  68. }
  69. public ObjectAttribute GetAttributeByIndex(int index) => _attributes[index];
  70. }
  71.  
  72. public class ObjectAttribute
  73. {
  74. public DataType Type {get;set;}
  75. public int Index {get;set;}
  76. public string Value { get; set; } = string.Empty;
  77. }
  78. }
  79.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(41,22): error CS1644: Feature `pattern matching' cannot be used because it is not part of the C# 7.0 language specification
prog.cs(46,22): error CS1644: Feature `pattern matching' cannot be used because it is not part of the C# 7.0 language specification
prog.cs(61,26): error CS1644: Feature `pattern matching' cannot be used because it is not part of the C# 7.0 language specification
Compilation failed: 3 error(s), 0 warnings
stdout
Standard output is empty