# Attributes

**URL:** <https://www.ruby-forum.com/t/attributes/160707>\
**Category:** IronRuby\
**Created:** [February 19, 2009, 1:40am UTC](https://www.ruby-forum.com/t/attributes/160707 "2009-02-19T01:40:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Orion\_E](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/65b543/32.png) [@Orion\_E](https://www.ruby-forum.com/u/Orion_E)\
**Post date:** [February 19, 2009, 1:40am UTC](https://www.ruby-forum.com/t/attributes/160707/1 "2009-02-19T01:40:53Z")

</div>

I’d like to mock up a WCF service using IronRuby.

This presents some stumbling blocks however, in that WCF  
ServiceContracts  
are defined by creating an Interface and then applying attributes to it.

Interface ~= Module in IronRuby, so that would probably be fine, but how  
can  
I apply attributes to the module and the methods it declares?

---

<div class="post-metadata">

**Author:** ![Orion\_E](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/65b543/32.png) [@Orion\_E](https://www.ruby-forum.com/u/Orion_E)\
**Post date:** [February 19, 2009, 2:02am UTC](https://www.ruby-forum.com/t/attributes/160707/2 "2009-02-19T02:02:31Z")

</div>

AFAIK you can’t yet. It’s one of those interop things that are on the  
back  
burner while language compatibility is worked on. There’s still alot of  
discussion needed about how to do this…

---

<div class="post-metadata">

**Author:** ![Orion\_E](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/65b543/32.png) [@Orion\_E](https://www.ruby-forum.com/u/Orion_E)\
**Post date:** [February 19, 2009, 2:19am UTC](https://www.ruby-forum.com/t/attributes/160707/3 "2009-02-19T02:19:28Z")

</div>

We currently don’t support attributes. As a workaround you can define a  
class in C# that will have all the attributes. The class can then  
forward all functionality to Ruby (e.g. via abstract methods implemented  
in a class derived in Ruby).

Tomas

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of Orion E.  
Sent: Wednesday, February 18, 2009 4:20 PM  
To: removed\_email\_address@domain.invalid  
Subject: [Ironruby-core] Attributes

I’d like to mock up a WCF service using IronRuby.

This presents some stumbling blocks however, in that WCF  
ServiceContracts are defined by creating an Interface and then applying  
attributes to it.

Interface ~= Module in IronRuby, so that would probably be fine, but how  
can I apply attributes to the module and the methods it declares?

---

<div class="post-metadata">

**Author:** ![Orion\_E](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/65b543/32.png) [@Orion\_E](https://www.ruby-forum.com/u/Orion_E)\
**Post date:** [February 19, 2009, 2:32am UTC](https://www.ruby-forum.com/t/attributes/160707/4 "2009-02-19T02:32:21Z")

</div>

Fair enough:  
Here’s my thoughts on what such a thing might look like:

module IMyService  
clr\_attribute ServiceContractAttribute.new(“blah”)

```
clr_attribute OperationContractAttribute.new, :on => "SomeMethod"
def SomeMethod; end

```

end

Could also have similar methods which map from string to ClassName at  
runtime

clr\_attr “ServiceContract”  
clr\_attr “OperationContract”, :on =\> “SomeMethod”

Could also implement named parameters eg

clr\_attr “ServiceContract”, :name =\> “MyFancyContract”  
clr\_attr “OperationContract”, :name =\> “CoolOperation”, :on =\>  
“SomeMethod”

Hope this helps inspire 🙂

On Thu, Feb 19, 2009 at 2:01 PM, Michael L. \<

---

<div class="post-metadata">

**Author:** ![Orion\_E](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/65b543/32.png) [@Orion\_E](https://www.ruby-forum.com/u/Orion_E)\
**Post date:** [February 19, 2009, 2:57am UTC](https://www.ruby-forum.com/t/attributes/160707/5 "2009-02-19T02:57:31Z")

</div>

Thanks for answering that. I wrote a small C# interface and then  
implemented  
that from IronRuby

On Thu, Feb 19, 2009 at 1:54 PM, Tomas M. \<

---

<div class="post-metadata">

**Author:** ![Orion\_E](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/65b543/32.png) [@Orion\_E](https://www.ruby-forum.com/u/Orion_E)\
**Post date:** [February 19, 2009, 3:32am UTC](https://www.ruby-forum.com/t/attributes/160707/6 "2009-02-19T03:32:41Z")

</div>

We think in similar directions.

Tomas

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of Orion E.  
Sent: Wednesday, February 18, 2009 5:18 PM  
To: removed\_email\_address@domain.invalid  
Subject: Re: [Ironruby-core] Attributes

Fair enough:  
Here’s my thoughts on what such a thing might look like:

module IMyService  
clr\_attribute ServiceContractAttribute.new(“blah”)

```
clr_attribute OperationContractAttribute.new, :on => "SomeMethod"
def SomeMethod; end

```

end

Could also have similar methods which map from string to ClassName at  
runtime

clr\_attr “ServiceContract”  
clr\_attr “OperationContract”, :on =\> “SomeMethod”

Could also implement named parameters eg

clr\_attr “ServiceContract”, :name =\> “MyFancyContract”  
clr\_attr “OperationContract”, :name =\> “CoolOperation”, :on =\>  
“SomeMethod”

Hope this helps inspire 🙂

On Thu, Feb 19, 2009 at 2:01 PM, Michael L.  
\<removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)\> wrote:  
AFAIK you can’t yet. It’s one of those interop things that are on the  
back burner while language compatibility is worked on. There’s still  
alot of discussion needed about how to do this…  
On Wed, Feb 18, 2009 at 7:20 PM, Orion E.  
\<removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)\> wrote:  
I’d like to mock up a WCF service using IronRuby.

This presents some stumbling blocks however, in that WCF  
ServiceContracts are defined by creating an Interface and then applying  
attributes to it.

Interface ~= Module in IronRuby, so that would probably be fine, but how  
can I apply attributes to the module and the methods it declares?

* * *

Ironruby-core mailing list  
removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[http://rubyforge.org/mailman/listinfo/ironruby-core](http://rubyforge.org/mailman/listinfo/ironruby-core)

–  
Michael L.  
IronRuby MVP  
[http://blog.prokrams.com](http://blog.prokrams.com)
