How do I use the propful aspect in Visual studio?

799 views Asked by At

How do I use the propfull tab tab gadget in visual studio?

Class Foo
{
public int regirsterR0
    {
        get { return R0; }
        set { R0 = value; }
    }
}

How would I use the get and set methods from another class? Let's say this method is in a class called foo. How would I use the get and set from foo in goo?

Class Goo
{
  Foo g= new Foo();
  g.regirsterR0.Get?????
}
3

There are 3 answers

0
BradleyDotNET On BEST ANSWER

First, thats called a snippet (and there are a bunch of others!). This one creates a full property (MSDN) definition.

To answer your question; you just use it as if it were a field:

var test = g.Register0; //invokes get
g.Register0 = 2; //invokes set

get and set are nice method abstractions that are called when the associated property is accessed or assigned to.

Note that you don't even need the snippet; you could have used an auto-property:

public int RegisterR0 { get; set; } //Properties are PascalCase!
0
Osman Villi On

Get and Set is not a value or method. Actually they are property like a control mechanism. (encapsulation principle)

for ex:

var variable = g.Register0; // so it is get property. // like a var variable = 5;
g.Register0 = 5; // so it is set property.

Look msdn explaining.

2
Piotr Knut On

You just forgot create method. :-)

class Foo
{
    private int regirsterR0;

    public int RegirsterR0
    {
        get { return regirsterR0; }
        set { regirsterR0 = value; }
    }
}

class Goo
{
    Foo g = new Foo();

    void myMethod()
    {
        // Set Property
        g.RegirsterR0 = 10;
        // Get property
        int _myProperty = g.RegirsterR0;
    }

}

If you want initialize new object of class Foo with Value you can:

class Foo
{
    private int regirsterR0;

    public int RegirsterR0
    {
        get { return regirsterR0; }
        set { regirsterR0 = value; }
    }
}

class Goo
{
    Foo g = new Foo() { RegirsterR0 = 10 };

    void myMethod()
    {
        Console.WriteLine("My Value is: {0}", g.RegirsterR0);
    }
}

But usualy you don't need use propfull. Will be fine if you use prop + 2xTAB. Example:

class Foo
{
    public int RegirsterR0 { get; set; }
}

class Goo
{
    Foo g = new Foo() { RegirsterR0 = 10 };

    void myMethod()
    {
        Console.WriteLine("My Value is: {0}", g.RegirsterR0);
    }
}

Wrok the same and easer to read.