/// <summary> /// Initializes a new <see cref="EtpEndpointProtocol"/> instance. /// </summary> /// <param name="supportedProtocol">The supported protocol to initialize from.</param> /// <param name="useRole">If <c>true</c>, use the supported protocol's role. Otherwise, use the supported protocol's counterpart role.</param> public EtpEndpointProtocol(ISupportedProtocol supportedProtocol, bool useRole) { EtpVersion = supportedProtocol.EtpVersion; Protocol = supportedProtocol.Protocol; Role = useRole ? supportedProtocol.Role : Roles.GetCounterpartRole(supportedProtocol.Role); CounterpartRole = useRole ? Roles.GetCounterpartRole(supportedProtocol.Role) : supportedProtocol.Role; Capabilities = new EtpProtocolCapabilities(supportedProtocol.EtpVersion, supportedProtocol.ProtocolCapabilities); }
/// <summary> /// Converts an <see cref="ISupportedProtocol"/> instance to a SupportedProtocol with a concrete type. /// </summary> /// <typeparam name="TSupportedProtocol">The concrete supported protocol type.</typeparam> /// <param name="supportedProtocol">The <see cref="ISupportedProtocol"/> to convert</param> /// <returns>The converted supported protocol.</returns> public static TSupportedProtocol ToSupportedProtocol <TSupportedProtocol>(this ISupportedProtocol supportedProtocol) where TSupportedProtocol : class, ISupportedProtocol, new() { if (supportedProtocol == null) { return(null); } if (supportedProtocol is TSupportedProtocol) { return(supportedProtocol as TSupportedProtocol); } var converted = new TSupportedProtocol { EtpVersion = supportedProtocol.EtpVersion, Protocol = supportedProtocol.Protocol, Role = supportedProtocol.Role, }; converted.SetProtocolCapabilitiesFrom(supportedProtocol.ProtocolCapabilities); return(converted); }