2

I have a struct called Services and in it I have some static properties

public struct Servico
{

    public static Servico Instalacao {
        get { return new Servico(ServicesType.Instalacao); }
    }

    public static Servico Desativacao {
        get { return new Servico(ServicesType.Desativacao); }
    }

    public static Servico TrocaVeiculo {
        get { return new Servico(ServicesType.TrocaVeiculo); }
    }

    public static Servico TrocaTitularidade {
        get { return new Servico(ServicesType.TrocaTitularidade); }
    }

}

How to list all my properties when I declare an object. Same when we declare a color, automatically all colors are listed.

Example:

enter image description here

Jon Hanna
  • 110,372
  • 10
  • 146
  • 251
  • http://stackoverflow.com/questions/824802/c-how-to-get-all-public-both-get-and-set-string-properties-of-a-type – Mottor Apr 13 '16 at 13:40
  • https://msdn.microsoft.com/en-us/library/kyaxdd3x(v=vs.110).aspx – Mottor Apr 13 '16 at 13:40
  • 5
    Why does your property getter always create a new instance? It should return always the same. Otherwise make it a (factory) method and not a property. – Tim Schmelter Apr 13 '16 at 13:42
  • 1
    Apart from that, you should already get a list of all public static properties and methods in intellisense if you type `Servico.`. – Tim Schmelter Apr 13 '16 at 13:59

1 Answers1

4

Some object-oriented languages allow one to access a static member through an instance.

C# however does not. While from within the class or struct (or one derived from it) you can call a static method or access a static field or property directly just as you can an instance method, from outside of it you must use the name of the class or struct.

Hence e.g.:

var foo = Servico.Instalacao;

The intellisense is geared towards helping you write reasonable code. As such if you write the above as far as:

var foo = Servico.

Then it should list the static members at that point.

Jon Hanna
  • 110,372
  • 10
  • 146
  • 251