Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Property definition C# #9771

Closed
josejmoran opened this issue Mar 15, 2016 · 12 comments
Closed

Property definition C# #9771

josejmoran opened this issue Mar 15, 2016 · 12 comments
Labels
Area-Language Design Resolution-Duplicate The described behavior is tracked in another issue

Comments

@josejmoran
Copy link

Version Used: C# 6

Steps to Reproduce: When we create a class we need to add the properties and always add {get; set;}

It will be great if we only enter the property access level, type and name and the {get; set;} is only needed when we need to control something in the getter or setter of a property.

Now we need to do this: public int BookID { get; set; }

It will be great if we do this: public int BookID;
1.
2.
3.

Expected Behavior:

Actual Behavior:

@svick
Copy link
Contributor

svick commented Mar 15, 2016

public int BookID; is already valid syntax to declare a field, so this certainly wouldn't be backwards-compatible.

@josejmoran
Copy link
Author

I just tried it and it worked. Sorry about that.

On Tue, Mar 15, 2016 at 6:40 PM, Petr Onderka notifications@github.com
wrote:

public int BookID; is already a valid syntax to declare a field, so this
certainly wouldn't be backwards-compatible.


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
#9771 (comment)

Regards,

Jose J. Moran
336-347-8688

@MgSam
Copy link

MgSam commented Mar 16, 2016

@josejmoran I recommend reading up on the differences between a field and a property.

@josejmoran
Copy link
Author

I am talking about the property. Let's focus on the main idea: Not having
to write a constructor to set all the instance variables if we can get it
for free.

The default constructor will be available to us and we can use it without
having to write the code. Only if we need some special code in the getter
or setter we will need to create a new constructor.

On Tue, Mar 15, 2016 at 11:17 PM, Sam notifications@github.com wrote:

@josejmoran https://github.com/josejmoran I recommend reading up on the
differences between a field and a property
http://stackoverflow.com/questions/295104/what-is-the-difference-between-a-field-and-a-property-in-c
.


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#9771 (comment)

Regards,

Jose J. Moran
336-347-8688

@josejmoran
Copy link
Author

Thanks for the observation of difference between field and property. I just made a mistake there. I meant property.

@alrz
Copy link
Member

alrz commented Mar 16, 2016

Only if we need some special code in the getter or setter we will need to create a new constructor.

I didn't know that.

@HaloFour
Copy link

I am talking about the property. Let's focus on the main idea: Not having
to write a constructor to set all the instance variables if we can get it
for free.

Could you update the proposal to flesh out this concept? There's nothing there that describes constructors or field/property initializers.

@josejmoran
Copy link
Author

When I check the code generated by ASP.NET is see this:

public class AccountController : Controller
{
    private readonly UserManager<ApplicationUser> _userManager;
    private readonly SignInManager<ApplicationUser> _signInManager;
    private readonly IEmailSender _emailSender;
    private readonly ISmsSender _smsSender;
    private readonly ILogger _logger;
  •    public AccountController(*
    
  •        UserManager<ApplicationUser> userManager,*
    
  •        SignInManager<ApplicationUser> signInManager,*
    
  •        IEmailSender emailSender,*
    
  •        ISmsSender smsSender,*
    
  •        ILoggerFactory loggerFactory)*
    
  •    {*
    
  •        _userManager = userManager;*
    
  •        _signInManager = signInManager;*
    
  •        _emailSender = emailSender;*
    
  •        _smsSender = smsSender;*
    
  •        _logger = loggerFactory.CreateLogger<AccountController>();*
    
  •    }*
    

...

}

I am proposing that a Default constructor should be made available for us
for free without me having to add this code to a class I create or this
class for that matter.

A default constructor for all classes we create that will be available to
us for free and we just need to call it if we want to and if we need to
change its default behavior then we override it or create a new one with a
different signature.

Thanks.

On Wed, Mar 16, 2016 at 10:59 AM, HaloFour notifications@github.com wrote:

I am talking about the property. Let's focus on the main idea: Not having
to write a constructor to set all the instance variables if we can get it
for free.

Could you update the proposal to flesh out this concept? There's nothing
there that describes constructors or field/property initializers.


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#9771 (comment)

Regards,

Jose J. Moran
336-347-8688

@josejmoran
Copy link
Author

Sorry, this is a different proposal. My bad.

The property one is related to that when I type* prop tab tab* I always get
for example private Name {get; set;} by default.

My suggestion is that I should get: private Name; as the default and if I
need to add some logic to the getter and setter then I myself add the
necessary get{} or set{} I need.

Thanks

On Wed, Mar 16, 2016 at 11:19 AM, Jose Moran josejmoranh@gmail.com wrote:

When I check the code generated by ASP.NET is see this:

public class AccountController : Controller
{
    private readonly UserManager<ApplicationUser> _userManager;
    private readonly SignInManager<ApplicationUser> _signInManager;
    private readonly IEmailSender _emailSender;
    private readonly ISmsSender _smsSender;
    private readonly ILogger _logger;
  •    public AccountController(*
    
  •        UserManager<ApplicationUser> userManager,*
    
  •        SignInManager<ApplicationUser> signInManager,*
    
  •        IEmailSender emailSender,*
    
  •        ISmsSender smsSender,*
    
  •        ILoggerFactory loggerFactory)*
    
  •    {*
    
  •        _userManager = userManager;*
    
  •        _signInManager = signInManager;*
    
  •        _emailSender = emailSender;*
    
  •        _smsSender = smsSender;*
    
  •        _logger = loggerFactory.CreateLogger<AccountController>();*
    
  •    }*
    

...

}

I am proposing that a Default constructor should be made available for us
for free without me having to add this code to a class I create or this
class for that matter.

A default constructor for all classes we create that will be available to
us for free and we just need to call it if we want to and if we need to
change its default behavior then we override it or create a new one with a
different signature.

Thanks.

On Wed, Mar 16, 2016 at 10:59 AM, HaloFour notifications@github.com
wrote:

I am talking about the property. Let's focus on the main idea: Not having
to write a constructor to set all the instance variables if we can get it
for free.

Could you update the proposal to flesh out this concept? There's nothing
there that describes constructors or field/property initializers.


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#9771 (comment)

Regards,

Jose J. Moran
336-347-8688

Regards,

Jose J. Moran
336-347-8688

@svick
Copy link
Contributor

svick commented Mar 16, 2016

If you don't actually want to write a property, and instead you want to write a field, then don't start with propTabTab, just write the field directly. Properties have some boilerplate code (the { get; set; } part), so it makes sense to have a code snippet for writing them.

If you really want a snippet to write a field (whether confusingly called prop or, say, something like fld), you can create one yourself.

@mgravell
Copy link
Member

Looks to be a troll having some fun; see all suggested issues: https://github.com/josejmoran

@gafter
Copy link
Member

gafter commented Mar 29, 2016

@josejmoran See #10154 for the current records proposal that may address your needs.

@gafter gafter closed this as completed Mar 29, 2016
@gafter gafter added the Resolution-Duplicate The described behavior is tracked in another issue label Mar 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Language Design Resolution-Duplicate The described behavior is tracked in another issue
Projects
None yet
Development

No branches or pull requests

8 participants