-
Notifications
You must be signed in to change notification settings - Fork 0
/
Extensions.cs
31 lines (28 loc) · 1.12 KB
/
Extensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
Copyright (c) 2011, thinktecture (http://www.thinktecture.com).
All rights reserved, comes as-is and without any warranty. Use of this
source file is governed by the license which is contained in LICENSE.TXT
in the distribution.
*/
using System.ServiceModel.Description;
namespace Thinktecture.ServiceModel
{
/// <summary>
///
/// </summary>
public static class ServiceHostExtensions
{
/// <summary>
/// Adds or replaces a service behavior.
/// </summary>
/// <typeparam name="TBehavior">The type of the behavior.</typeparam>
/// <param name="serviceHost">The service host.</param>
/// <param name="behavior">The new behavior.</param>
public static void AddOrReplaceBehavior<TBehavior>(this System.ServiceModel.ServiceHost serviceHost, TBehavior behavior) where TBehavior : IServiceBehavior
{
if (serviceHost.Description.Behaviors.Find<TBehavior>() != null)
serviceHost.Description.Behaviors.Remove<TBehavior>();
serviceHost.Description.Behaviors.Add(behavior);
}
}
}