Saturday, June 21, 2014

Fun with Nuances (C# Attributes vs. Properties)!

An attribute is a way to link up data that and a target element of code (class, interface, methods, properties, or others..).

A property is a type of method (accessor) that are used like a public data member.. but they give you a way to read/write/evaluate some private field. This = safety + flexibility in your code.

Properties usually edit the attributes.

Just something new and fun. This is what we use today (some synonymous hybrid mix "thing"):
In a lot of ways, this is easier, shorter, and MUCH nicer to the eye!

This is what we used to use

However, you lose the ability/flexibility to edit the individual parts of it when the attribute used to be wrapped around a layer of property! There are only rare instances you would need this.. but those times do exist!

Here is one for you! For instance.. if you are making a "dummy" database and seeding it -- let's say you were making a nice end to end ASP .NET MVC.. and you did not want to open up a SQL database just yet. This "dummy" database would help you bounce off your ideas for the MVC with its own little pseudo-database that is made just to get things up and running a little quicker on the front end! So.. you could not do this:


.. for the reason stated above (you can't edit the specific attribute and property out!).

However.. this works as a whole!


See how the variable _recipes is actually used now??? This is one of those useful rare instances..