ProviderBase.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------
  4. namespace System.ServiceModel.Administration
  5. {
  6. using System.Collections;
  7. using System.Runtime;
  8. abstract class ProviderBase : IWmiProvider
  9. {
  10. public static void FillCollectionInfo(ICollection info, IWmiInstance instance, string propertyName)
  11. {
  12. Fx.Assert(null != info, "");
  13. Fx.Assert(null != instance, "");
  14. //warning 56507 : Prefer 'string.IsNullOrEmpty(action)' over checks for null and/or emptiness.
  15. #pragma warning suppress 56507 //[....]; Asserting non-null object for marshalling reasons. Empty string may be valid input.
  16. Fx.Assert(null != propertyName, "");
  17. string[] data = new string[info.Count];
  18. int i = 0;
  19. foreach (object o in info)
  20. {
  21. data[i++] = o.ToString();
  22. }
  23. instance.SetProperty(propertyName, data);
  24. }
  25. public static void FillCollectionInfo(IEnumerable info, IWmiInstance instance, string propertyName)
  26. {
  27. Fx.Assert(null != info, "");
  28. Fx.Assert(null != instance, "");
  29. //warning 56507 : Prefer 'string.IsNullOrEmpty(action)' over checks for null and/or emptiness.
  30. #pragma warning suppress 56507 //[....]; Asserting non-null object for marshalling reasons. Empty string may be valid input.
  31. Fx.Assert(null != propertyName, "");
  32. int i = 0;
  33. foreach (object o in info)
  34. {
  35. i++;
  36. }
  37. string[] data = new string[i];
  38. i = 0;
  39. foreach (object o in info)
  40. {
  41. data[i++] = o.ToString();
  42. }
  43. instance.SetProperty(propertyName, data);
  44. }
  45. void IWmiProvider.EnumInstances(IWmiInstances instances)
  46. {
  47. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new WbemNotSupportedException());
  48. }
  49. bool IWmiProvider.GetInstance(IWmiInstance contract)
  50. {
  51. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new WbemNotSupportedException());
  52. }
  53. bool IWmiProvider.PutInstance(IWmiInstance instance)
  54. {
  55. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new WbemNotSupportedException());
  56. }
  57. bool IWmiProvider.DeleteInstance(IWmiInstance instance)
  58. {
  59. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new WbemNotSupportedException());
  60. }
  61. bool IWmiProvider.InvokeMethod(IWmiMethodContext method)
  62. {
  63. method.ReturnParameter = 0;
  64. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new WbemNotSupportedException());
  65. }
  66. }
  67. }