private void ConsumeParameters(TextBuffer inParameters, TextBuffer outParameters) { PropertyInfo[] properties = GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (var propInfo in properties) { ProtocolKeyAttribute attr = (ProtocolKeyAttribute)Attribute.GetCustomAttribute(propInfo, typeof(ProtocolKeyAttribute)); if (attr != null && (attr.Sender & KeySender.Target) != 0) { if (inParameters[attr.Name] != null) { object value = ProtocolKeyAttribute.GetValueAsObject(inParameters[attr.Name], propInfo.PropertyType); propInfo.GetSetMethod(true).Invoke(this, new object[] { value }); inParameters.Remove(attr.Name); if (attr.Type == KeyType.Negotiated && !_negotiatedParameters.ContainsKey(attr.Name)) { value = propInfo.GetGetMethod(true).Invoke(this, null); outParameters.Add(attr.Name, ProtocolKeyAttribute.GetValueAsString(value, propInfo.PropertyType)); _negotiatedParameters.Add(attr.Name, string.Empty); } } } } _session.ConsumeParameters(inParameters, outParameters); foreach (var param in inParameters.Lines) { outParameters.Add(param.Key, "NotUnderstood"); } }
private void GetParametersToNegotiate(TextBuffer parameters, KeyUsagePhase phase, SessionType sessionType) { PropertyInfo[] properties = GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (var propInfo in properties) { ProtocolKeyAttribute attr = (ProtocolKeyAttribute)Attribute.GetCustomAttribute(propInfo, typeof(ProtocolKeyAttribute)); if (attr != null) { object value = propInfo.GetGetMethod(true).Invoke(this, null); if (attr.ShouldTransmit(value, propInfo.PropertyType, phase, sessionType == SessionType.Discovery)) { parameters.Add(attr.Name, ProtocolKeyAttribute.GetValueAsString(value, propInfo.PropertyType)); _negotiatedParameters.Add(attr.Name, string.Empty); } } } }