Exploring Caller Info Attributes

Last year, Microsoft announced a simple new feature in C# 5: Caller Info Attributes.  These attributes let you to create methods with optional parameters and tell the compiler to pass the caller’s filepath, line number, or member name instead of the parameter’s default value.  This allows you to create logging methods that automatically know where they’re being called.

When the feature was announced, I wrote a couple of blog posts that delved into some of the corner cases of the new feature.  At the time, there was no public implementation, so they were pure conjecture.

This morning, Microsoft released the beta of Visual Studio 11, which is the first public build supporting these attributes.  Now, I can finally test my theories.  Here are the results:

Although these classes are new to the .Net Framework 4.5, you can still use this feature against older framework versions by creating your own classes in the System.Runtime.CompilerServices namespace.  However, the feature will only work if the code calling the method is compiled with the C# 5 compiler; older compilers will ignore the attributes and simply pass the parameters’ default values.

All of the attributes can only be applied to arguments of types that have standard (not custom) implicit conversions to int or string.  This means that it isn’t practical to overflow [CallerLineNumber] (the compiler ran out of memory first), so I can’t test how that behaves.

Using [CallerMemberName] on field initializers passes the field name, and on static or instances constructors passes the string ".cctor" or ".ctor" (as documented)  In indexers, it passes "Item".

If a class has a constructor that takes only caller info attribute parameters, and you create another class that inherits it and does not declare a constructor (thus implicitly passing optional parameters), it passes the line number and file name of the class keyword in the derived class, but leaves the declared default for the member name (I suspect that’s a bug). 

If you do declare a constructor, it passes the string ".ctor" as the member name for the implicit base() call (just like a normal method call from inside a constructor) and the line number of the beginning of the constructor declaration.  If you actually write a base() call, it passes the line number of the base keyword.

If a call spans multiple lines, [CallerLineNumber] passes the line containing the openning parenthesis.

Delegates are fully supported; if you call a delegate that has an argumented annotated with a caller info attribute, the compiler will insert the correct value, regardless of the method you’re actually calling (which the compiler doesn’t even know).

LINQ query comprehension syntax is not supported at all; if you create a (for example) Select() method that contains a caller info attribute, then call it from a LINQ query (not lambda syntax), the compiler will crash (!).  (they will fix that)

Expression trees do not support optional parameters at all, so that corner case is irrelevant.

Attributes are the most interesting story.  What should happen if you declare a custom attribute that takes parameters with caller info attributes, then apply that attribute in various cases?  This could potentially be very useful, since there is currently no way for an attribute to know what it’s being applied to. (I hadn’t thought of this usage when I wrote the original blog post)

The documentation says that this will work in all cases, and that [CallerMemberName] will pass whatever the attribute is being applied to.  However, in the beta build, this doesn’t always work.

Attributes applied to method arguments or return values do not pass any caller info at all.  Attributes applied to types or generic type arguments do not pass member names (this is very disappointing)

Hopefully, those will be fixed before release.

674 comments:

«Oldest   ‹Older   601 – 674 of 674   Newer›   Newest»

I want to leave a little comment to support and wish you the best of luck.we wish you the best of luck in all your blogging enedevors.
data science course fees in bangalore

Great post i must say and thanks for the information. Education is definitely a sticky subject. However, is still among the leading topics of our time. I appreciate your post and look forward to more.
Data Science Course in Bangalore

Thank you for your informative post!!!
Village Talkies a top-quality professional corporate video production company in Bangalore and also best explainer video company in Bangalore & animation video makers in Bangalore, Chennai, India & Maryland, Baltimore, USA provides Corporate & Brand films, Promotional, Marketing videos & Training videos, Product demo videos, Employee videos, Product video explainers, eLearning videos, 2d Animation, 3d Animation, Motion Graphics, Whiteboard Explainer videos Client Testimonial Videos, Video Presentation and more for all start-ups, industries, and corporate companies. From scripting to corporate video production services, explainer & 3d, 2d animation video production , our solutions are customized to your budget, timeline, and to meet the company goals and objectives.
As a best video production company in Bangalore, we produce quality and creative videos to our clients.

Full Body Exoskeleton - An exoskeleton usually pertains to an external body covering feature facilitating a certain biological process thereby,Using exoskeleton can prevent neurological injury and physical damage.

Tags - "full body exoskeleton , homemade exoskeleton, exoskeleton for lifting
"

Link - http://exoskeleton360.com/

The website does not have a policy to charge a membership fee or any fee at all, if the players encounter the charge by the team or the website staff, they can report it. Football สมัคร ufabet betting here knows the results immediately. Takes a long time to complete Since we have an automated system that can calculate everything immediately.

I just got to this amazing site not long ago. I was actually captured with the piece of resources you have got here. Big thumbs up for making such wonderful blog page!
data analytics course in bangalore

Get instant Finance Assignment Help from the best experts. The experts from My Assignment Help
assignment team keep a regular watch on all the university guidelines. We always strive to provide the students with the best quality assignments. All the details are gone through each time we get a finance assignment order from the students.

I am a new user of this site, so here I saw several articles and posts published on this site, I am more interested in some of them, hope you will provide more information on these topics in your next articles.
data analytics training in bangalore

Information Technology is the process of collecting, processing, storing, and distribution of different forms of information in form of text, picture, voice and numerical information. The micro-electronic based telecommunication techniques are used in this electronic process. Different information technology assignment helps services have come into existence that offers professional assistance on various kinds of assignments including the Information technology-based assignments. We are at assignment help. Assignment helps under our IT assignment help so that students can complete their assignment on time and score good marks.

I am glad to discover this page. I have to thank you for the time I spent on this especially great reading !! I really liked each part and also bookmarked you for new information on your site.
Data Science Training in Chennai

combine gaming and study!
game word unscrambler will help you Improve your vocabulary
With so many words in the archives, you might find something really useful here. It not only helps to improve your vocabulary but also strengthens your language skills.

This post is very simple to read and appreciate without leaving any details out. Great work!
artificial intelligence courses in aurangabad

You have an extremely knowledge perspective.It’s incredible how thorough your work is.
data analytics course

Global Translation Help offers NYC Translation Services at very pocket-friendly prices. We have a team of more than 500 certified native translators in New York who are highly skilled and expertise in delivering excellent translation services for any kind of documents in the desired language. We provide same-day translation and one-hour translation service for you if you have an urgent requirement.

I want to leave a little comment to support and wish you the best of luck.we wish you the best of luck in all your blogging enedevors.
data science training in chennai

Thanks for the informative and helpful post, obviously in your blog everything is good..
digital marketing courses in hyderabad with placement

nice article. keep posting. we provide Java Assignment Help.We provide all kinds of academic assignments such as research paper, term paper, thesis assignments and essay assignments. if anyone need Database Homework help also provide expert tutor help at the best price. 24x7 online chat support.

Wow, happy to see this awesome post. I hope this think help any newbie for their awesome work and by the way thanks for share this awesomeness, i thought this was a pretty interesting read when it comes to this topic. Thank you..
Artificial Intelligence Course

Excellent Blog! I would like to thank you for the efforts you have made in writing this post. Gained lots of knowledge.
Data Analytics Course

What an incredible message this is. Truly one of the best posts I have ever seen in my life. Wow, keep it up.
AI Courses in Bangalore

I need to thank you for this very good read and i have bookmarked to check out new things from your post. Thank you very much for sharing such a useful article and will definitely saved and revisit your site.
Data Science Course

Attributes applied to method arguments or return values do not pass any caller info at all. Attributes applied to types or generic type arguments do not pass member names (this is very disappointing) cotton comforter , best cotton sheets ,

This blog has the relevant data according to the topic and precise to the topic.
German Courses in Chennai
Best German Classes in Chennai
German Language Classes Near Me

Awesome article. I enjoyed reading your articles. this can be really a good scan for me. wanting forward to reading new articles. maintain the nice work!
Data Science Courses in Bangalore

I am sure it will help many people. Keep up the good work. It's very compelling and I enjoyed browsing the entire blog.
Business Analytics Course in Bangalore

Your site is truly cool and this is an extraordinary moving article and If it's not too much trouble share more like that. Thank You..
Digital Marketing Course in Hyderabad

Thank a lot. You have done excellent job. I enjoyed your blog . Nice efforts
Data Science Certification in Hyderabad

I really enjoy reading and also appreciate your work.
data science training in pune

Such a useful blog with required information. Thanks for sharing this amazing blog.
AWS Certification in Chennai
DevOps Course in Chennai

You have completed certain reliable points there. I did some research on the subject and found that almost everyone will agree with your blog.

Data Science Training in Bangalore

Wonderful blog found to be very impressive to come across such an awesome blog. I should really appreciate the blogger for the efforts they have put in to develop such amazing content for all the curious readers who are very keen on being updated across every corner. Ultimately, this is an awesome experience for the readers. Anyways, thanks a lot and keep sharing the content in the future too.

Digital Marketing Training in Bangalore

I found Habit to be a transparent site, a social hub that is a conglomerate of buyers and sellers willing to offer digital advice online at a decent cost.

Artificial Intelligence Training in Bangalore

The Extraordinary blog went amazed by the content that they have developed in a very descriptive manner. This type of content surely ensures the participants explore themselves. Hope you deliver the same near the future as well. Gratitude to the blogger for the efforts.

Machine Learning Course in Bangalore

Trutech Products is the most determined Transformer Manufacturers In Pune. Our products range passes a number of quality checks before reaching to our clients. If you want to invest in it, drop us your queries.
Transformer Manufacturers in India | Transformer Manufacturers in Mumbai

Are you searching for nursing assignment help? We offer you the best academic writing services including the help you need to create a nursing assignment. Visit our website for more help.

Thank you for sharing excellent information. I’ve learned a lot from your blog here, Keep on going my friend.

PCD Pharma Franchise In India

Pharma Franchise Company In India

PCD Pharma Company In India

Third Party Manufacturing Pharma Company

Stupendous blog huge applause to the blogger and hoping you to come up with such an extraordinary content in future. Surely, this post will inspire many aspirants who are very keen in gaining the knowledge. Expecting many more contents with lot more curiosity further.

Data Science Certification in Bhilai

Extraordinary blog filled with an amazing content which no one has touched this subject before. Thanking the blogger for all the terrific efforts put in to develop such an awesome content. Expecting to deliver similar content further too and keep sharing as always.

Data Science Training

This is a great post. I like this topic.This site has lots of advantage.I found many interesting things from this site. It helps me in many ways.Thanks for posting this again.
data scientist training and placement


It’s great to come across a blog every once in a while that isn’t the same out of date rehashed material. Fantastic read. Get for more information free online classes for kids

We are provided by a live project based Web Development Company in Chandigarh. Violet Automation is a best team of web Development consultants. Violet Automation is a good php expert who is a reliable guide.

Stupendous blog huge applause to the blogger and hoping you to come up with such an extraordinary content in future. Surely, this post will inspire many aspirants who are very keen in gaining the knowledge. Expecting many more contents with lot more curiosity further.

Data Science Certification in Bhilai

Extraordinary blog filled with an amazing content which no one has touched this subject before. Thanking the blogger for all the terrific efforts put in to develop such an awesome content. Expecting to deliver similar content further too and keep sharing as always.

Data Science Training

Thanks for providing a useful article containing valuable information. start learning the best online software courses.
Sailpoint Certification
Looker Training
F5 Load balancer Training
SAP Ariba Training

I am glad to discover this page. I have to thank you for the time I spent on this especially great reading !! I really liked each part and also bookmarked you for new information on your site.
Data Science Course Syllabus

Thanks for the informative article.keep share and update with such blogs.
Data Science Training in Pune

Wonderful blog found to be very impressive to come across such an awesome blog. I should really appreciate the blogger for the efforts they have put in to develop such an amazing content for all the curious readers who are very keen of being updated across every corner. Ultimately, this is an awesome experience for the readers. Anyways, thanks a lot and keep sharing the content in future too.

Data Science Course in Bhilai

Impressive blog to be honest definitely this post will inspire many more upcoming aspirants. Eventually, this makes the participants to experience and innovate themselves through knowledge wise by visiting this kind of a blog. Once again excellent job keep inspiring with your cool stuff.

Data Science Training in Bhilai

I am glad to discover this page. I have to thank you for the time I spent on this especially great reading !! I really liked each part and also bookmarked you for new information on your site.
Data Science Institutes in Hyderabad

Great, thank you so much for sharing such an amazing blog with us. OGEN Infosystem is one of the best Website Designing, Website Development, SEO, PPC, and Digital Marketing Services in Delhi, India.
Website Designing Company in India

I finally found great post here.I will get back here. I just added your blog to my bookmark sites. thanks.Quality posts is the crucial to invite the visitors to visit the web page, that's what this web page is providing.data scientist training in hyderabad

I recently came across your article and have been reading along. I want to express my admiration of your writing skill and ability to make readers read from the beginning to the end.
Python Classes in Pune

They make certain to draft the best programming projects according to your particulars and necessities.
programming assignment experts

Attempting to express profound gratitude won't just be satisfactory, for the fabulous clearness in your creation. I will in a brief instant get your rss channel to stay instructed with respect to any updates.
data scientist training and placement in hyderabad

Independent Escorts in Dubai is the right decision. the top Dubai Escorts at your one Click. Log on to us for entertainment

I want to leave a little comment to support and wish you the best of luck.we wish you the best of luck in all your blogging enedevors.
data science course

We have the best professional who can provide the best Java Homework Help at the best price. Our highly experienced & qualified tutors & writers have the capability of delivering write up based on any of the subjects or topics. For any help SAP assignment help, contact to our customer support and get expert help.

I like your blog you write your blog very carefully . it is very knowledgeable .If you like this information and want to know more about CAD you can call me at 9311002620 or can visit our website https://www.htsindia.com/autocad-training-institute

This is a wonderful article, Given so much info in it, These type of articles keeps the users interest in the website, and keep on sharing more ... good luck.
artificial intelligence course aurangabad

Hi, I am John Smith I am Web Developer, It is an amazing blog thanks for the sharing the blog. Frantic infotech provide the Flutter app development such as an information about software development for costumer service. Franti infotech also provide the ios app development. The development of advanced web applications is Orient Software’s specialty and we will successfully fulfill all your web application development requirements, from small-sized to wider-ranged projects.

I am glad to discover this page. I have to thank you for the time I spent on this especially great reading !! I really liked each part and also bookmarked you for new information on your site.
Data Science Training in Chennai

I want to leave a little comment to support and wish you the best of luck.we wish you the best of luck in all your blogging enedevors.
aws training in hyderabad

A big thank you for sharing this post your content is really good apart from that if anyone looking for best Core and Advanced Java training institute in delhi so contact here +91-9311002620 visit https://www.htsindia.com/java-training-courses

I want to leave a little comment to support and wish you the best of luck.we wish you the best of luck in all your blogging enedevors.
business analytics courses

I feel happy about and learning more about this topic. keep sharing your information regularly for my future reference. This content creates new hope and inspiration within me. Thanks for sharing an article like this. the information which you have provided is better than another blog.
Carpets Manufacturers in Panipat

I am a new user of this site, so here I saw several articles and posts published on this site, I am more interested in some of them, will provide more information on these topics in future articles.
data science course in london

«Oldest ‹Older   601 – 674 of 674   Newer› Newest»

Post a Comment