ServiceDescriptor.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using Google.ProtocolBuffers.DescriptorProtos;
  5. namespace Google.ProtocolBuffers.Descriptors {
  6. /// <summary>
  7. /// Describes a service type.
  8. /// </summary>
  9. public class ServiceDescriptor : IndexedDescriptorBase<ServiceDescriptorProto, ServiceOptions> {
  10. private readonly IList<MethodDescriptor> methods;
  11. public ServiceDescriptor(ServiceDescriptorProto proto, FileDescriptor file, int index)
  12. : base(proto, file, ComputeFullName(file, null, proto.Name), index) {
  13. methods = DescriptorUtil.ConvertAndMakeReadOnly(proto.MethodList,
  14. (method, i) => new MethodDescriptor(method, file, this, i));
  15. file.DescriptorPool.AddSymbol(this);
  16. }
  17. /// <value>
  18. /// An unmodifiable list of methods in this service.
  19. /// </value>
  20. public IList<MethodDescriptor> Methods {
  21. get { return methods; }
  22. }
  23. /// <summary>
  24. /// Finds a method by name.
  25. /// </summary>
  26. /// <param name="name">The unqualified name of the method (e.g. "Foo").</param>
  27. /// <returns>The method's decsriptor, or null if not found.</returns>
  28. public MethodDescriptor FindMethodByName(String name) {
  29. return File.DescriptorPool.FindSymbol<MethodDescriptor>(FullName + "." + name);
  30. }
  31. internal void CrossLink() {
  32. foreach (MethodDescriptor method in methods) {
  33. method.CrossLink();
  34. }
  35. }
  36. }
  37. }