MissingMemberException.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT license.
  3. // See the LICENSE file in the project root for more information.
  4. using System.Runtime.Serialization;
  5. namespace System
  6. {
  7. [Serializable]
  8. [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
  9. public partial class MissingMemberException : MemberAccessException
  10. {
  11. public MissingMemberException()
  12. : base(SR.Arg_MissingMemberException)
  13. {
  14. HResult = HResults.COR_E_MISSINGMEMBER;
  15. }
  16. public MissingMemberException(string message)
  17. : base(message)
  18. {
  19. HResult = HResults.COR_E_MISSINGMEMBER;
  20. }
  21. public MissingMemberException(string message, Exception inner)
  22. : base(message, inner)
  23. {
  24. HResult = HResults.COR_E_MISSINGMEMBER;
  25. }
  26. public MissingMemberException(string className, string memberName)
  27. {
  28. ClassName = className;
  29. MemberName = memberName;
  30. }
  31. protected MissingMemberException(SerializationInfo info, StreamingContext context)
  32. : base(info, context)
  33. {
  34. ClassName = info.GetString("MMClassName");
  35. MemberName = info.GetString("MMMemberName");
  36. Signature = (byte[])info.GetValue("MMSignature", typeof(byte[]));
  37. }
  38. public override void GetObjectData(SerializationInfo info, StreamingContext context)
  39. {
  40. base.GetObjectData(info, context);
  41. info.AddValue("MMClassName", ClassName, typeof(string));
  42. info.AddValue("MMMemberName", MemberName, typeof(string));
  43. info.AddValue("MMSignature", Signature, typeof(byte[]));
  44. }
  45. public override string Message
  46. {
  47. get
  48. {
  49. if (ClassName == null)
  50. {
  51. return base.Message;
  52. }
  53. else
  54. {
  55. // do any desired fixups to classname here.
  56. return SR.Format(SR.MissingMember_Name, ClassName + "." + MemberName + (Signature != null ? " " + FormatSignature(Signature) : string.Empty));
  57. }
  58. }
  59. }
  60. // If ClassName != null, GetMessage will construct on the fly using it
  61. // and the other variables. This allows customization of the
  62. // format depending on the language environment.
  63. protected string ClassName;
  64. protected string MemberName;
  65. protected byte[] Signature;
  66. }
  67. }