Raba - Defend your code RSS 2.0
# Saturday, January 28, 2006

After the last Assembly lesson in "What is the difference between Const and Readonly?" post, many of you praised and asked for more from the ildasm subject, so here it is, a simple question about the assembly behind you code.

What going to happen if you'll try to write this code:

        public string HtmlSnippet
        {
            get
            {
                return m_HtmlSnippet;
            }
            set
            {
                m_HtmlSnippet = value;
            }
        }

        public string get_HtmlSnippet()
        {
            return m_HtmlSnippet;
        }

This one is simple, This is the error message at the compilation:
error CS0111: Class 'Sentence' already defines a member called 'get_HtmlSnippet' with the same parameter types.

Why is it an error?
while converting the C# Code into Assembly the compiler will transfer each property into method!
after all, there are no properties in assemblies.
The format of such transformation will be:
public PropertyType   get_PropertyName(){....}
public void               set_PropertyName(string value){....}

Saturday, January 28, 2006 4:35:52 PM (GMT Standard Time, UTC+00:00)  #    Comments [1] - Trackback
.Net

Thursday, February 16, 2006 4:27:42 PM (GMT Standard Time, UTC+00:00)
Just to note, there is one important difference with those two.
The Property will be compiled with IsSpecialName attribute, which is needed for tool support is several cases.
Comments are closed.
Archive
<February 2012>
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
26272829123
45678910
Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2012
Shani Raba
Sign In
Statistics
Total Posts: 145
This Year: 0
This Month: 0
This Week: 0
Comments: 97
Cool Stuff
Add to Technorati Favorites
Themes
Pick a theme:
All Content © 2012, Shani Raba
DasBlog theme 'Business' created by Christoph De Baene (delarou)