Anything like "Extension Methods" for Properties ?

Hi everybody
Is there anything like “Extension Methods” for class Properties ?

Here’s what I looking for :

in (Object1) >> Script : Animations.cs 

- List of Animates;

in Script : Animate.cs

- Play()
...

in (Object 2)Script : sample1.cs
 //this is what I want
 Object1.Anims.Walk.Play();

Can it be done ? and if yes , HOW?!??!?!
Thanks a lot(thousands) .

No, there is nothing like extension properties. As far as i know it is planned for a future C# version, but since Unity uses a quite old implementation of Mono I wouldn’t expect such a feature in the near future (2-x years at least).

The question is if it actually makes sense to implement them. Extension methods are just normal methods which work on a specific object type. All they allow is to have a simpler way of calling them.

Properties usually describe, well, properties of an object. To me it makes no sense to kind of “inject” new properties into a foreign object. Why don’t you just use Methods instead of properties? Properties are just a pair of functions.

Actually i don’t really get your pseudo example. What is “Walk” ? It look like that “Walk” is more data then a property. What you might want is an indexer. Before you ask, no, you can’t implement an “extension indexer”, it has to be declared inside the class itself.

Indexers are actually properties with “indexing” parameters. For example:

public class SomeClass
{
    public Transform this[string aName]
    {
       get { return /*Do some fancy stuff with "aName" and return a Transform reference*/; }
       set { /*Here you have the "value" and the "aName" parameter*/}
    }
}

// ...
public SomeClass instance;

instance["SomeName"].position = Vector3.zero;