Beispiel #1
0
        internal 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)
                {
                    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);
                        }
                    }
                }
            }
        }
Beispiel #2
0
        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);
                    }
                }
            }
        }