1 //----------------------------------------------------------------------------- 2 // Copyright (c) Microsoft Corporation. All rights reserved. 3 //----------------------------------------------------------------------------- 4 5 namespace System.ServiceModel.Channels 6 { 7 using System.Runtime; 8 9 public class NetworkInterfaceMessageProperty 10 { 11 const string PropertyName = "NetworkInterfaceMessageProperty"; 12 NetworkInterfaceMessageProperty(int interfaceIndex)13 public NetworkInterfaceMessageProperty(int interfaceIndex) 14 { 15 this.InterfaceIndex = interfaceIndex; 16 } 17 NetworkInterfaceMessageProperty(NetworkInterfaceMessageProperty other)18 NetworkInterfaceMessageProperty(NetworkInterfaceMessageProperty other) 19 { 20 this.InterfaceIndex = other.InterfaceIndex; 21 } 22 23 public static string Name 24 { 25 get { return PropertyName; } 26 } 27 28 public int InterfaceIndex 29 { 30 get; 31 private set; 32 } 33 TryGet(Message message, out NetworkInterfaceMessageProperty property)34 public static bool TryGet(Message message, out NetworkInterfaceMessageProperty property) 35 { 36 if (message == null) 37 { 38 throw FxTrace.Exception.ArgumentNull("message"); 39 } 40 41 return TryGet(message.Properties, out property); 42 } 43 TryGet(MessageProperties properties, out NetworkInterfaceMessageProperty property)44 public static bool TryGet(MessageProperties properties, out NetworkInterfaceMessageProperty property) 45 { 46 if (properties == null) 47 { 48 throw FxTrace.Exception.ArgumentNull("properties"); 49 } 50 51 object value = null; 52 if (properties.TryGetValue(PropertyName, out value)) 53 { 54 property = value as NetworkInterfaceMessageProperty; 55 } 56 else 57 { 58 property = null; 59 } 60 return property != null; 61 } 62 AddTo(Message message)63 public void AddTo(Message message) 64 { 65 if (message == null) 66 { 67 throw FxTrace.Exception.ArgumentNull("message"); 68 } 69 70 AddTo(message.Properties); 71 } 72 AddTo(MessageProperties properties)73 public void AddTo(MessageProperties properties) 74 { 75 if (properties == null) 76 { 77 throw FxTrace.Exception.ArgumentNull("properties"); 78 } 79 80 properties.Add(NetworkInterfaceMessageProperty.Name, this); 81 } 82 } 83 } 84