Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding attribute to BehaviorExtensionElement

I'm adding a custom behaviorExtensionElement for WCF and want to add an attribute that can be read when the configured element is being read, e.g.

<system.serviceModel>
    <extensions>
      <behaviorExtensions>
        <add name="myExtension"
             type="Bar.FooBarElement, Bar"/>
      </behaviorExtensions>
    </extensions>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <myExtension myAttribute="Foo" />

However, I get an error "Unrecognized attribute 'myAttribute'. Note that attribute names are case-sensitive."

How can I avoid this? How do I read the myAttribute value in code?

like image 249
ConfusedNoob Avatar asked Dec 12 '22 10:12

ConfusedNoob


1 Answers

Turns out it's pretty easy, since BehaviorExtensionElement subclasses ConfigurationElement, the usual configuration rules apply.

[ConfigurationProperty("myAttribute")]
public string MyAttribute
{
  get { return (string)this["myAttribute"]; }
  set { this["myAttribute"] = value; }
}
like image 100
ConfusedNoob Avatar answered Jan 23 '23 01:01

ConfusedNoob