INotifyPropertyChanged Interface Callermembername Properties

Source: Internet
Author: User

2016-07-24

Caller Information

Using the caller Information property, you can get information about the caller passed to the method. you can get the source code, the line number in the source code, and the file path of the caller's member name. This information is useful for tracking, debugging, and creating diagnostic tools.

To get this information, use a default property for each of the optional parameters. The following table lists the caller information properties that are defined in the System.Runtime.CompilerServices namespace:

Characteristics

Description

Type

Callerfilepathattribute

Contains the full path of the call to the FountainVest partners file. This is the file path at compile time.

String

Callerlinenumberattribute

The line number in the source file of the calling method.

Integer

Callermembernameattribute

The property name of the method or caller. See Member Names later in this topic

String

Example

The following example shows how to use the caller information property. at each call to the Tracemessage method, the information is replaced with the caller of the parameter of the optional parameter.

1 //using System.Runtime.CompilerServices2 //using System.Diagnostics;3 4  Public voiddoprocessing ()5 {6Tracemessage ("Something happened.");7 }8 9  Public voidTracemessage (stringmessage,Ten[Callermembername]stringMemberName ="", One[Callerfilepath]stringSourcefilepath ="", A[Callerlinenumber]intSourcelinenumber =0) - { -Trace.WriteLine ("message:"+message); theTrace.WriteLine ("member Name:"+membername); -Trace.WriteLine ("source file path:"+Sourcefilepath); -Trace.WriteLine ("Source Line number:"+sourcelinenumber); - } +  - //Sample Output: + //message:something happened. A //member Name:doprocessing at //source file path:c:\users\username\documents\visual Studio 2012\projects\callerinfocs\callerinfocs\form1.cs  - //Source Line number:31
Notes you must specify an explicit default value for each optional parameter. The caller information attribute cannot be applied to a parameter that is not specified as an option.

The caller Information property does not make a parameter option. instead, they affect the passed default value when the argument is omitted.

The caller information value is emitted as text to the (IL) intermediate language that is evaluated at compile time. The results of different StackTrace properties are abnormal, and the results are not affected by the blurred process.

member name

string argument to the called method. " > you can use   callermembername   Property set to avoid specifying member names as parameters  string  To the calling method.  rename refactoring doesn ' t change the string values. " > by using this method, you can avoid this problem   rename refactoring   do not change  string  value.  

  • Use tracking and diagnostics instances.

  • inotifypropertychanged interface when Binding data. " > Implement the  INotifyPropertyChanged  interface when binding data.     Callermembername   Property, you must specify the property name as text.

Displays the returned member name as a table when you use the callermembername property.

 

The generated name member, for example, "op_addition".

TD data-th= "Member name result" >

Call occurs in

Member name result

Method, property, or event

The name of the method, the property, or the event that is called.

constructor function

String ". ctor"

Static constructors

String ". cctor"

Destructors

The string "Finalize"

user-defined operator or transform

attribute constructor

The name of the member to which the attribute applies.   If the property is any element in the member (such as a parameter, return value, or generic type parameter), this result is the name of the member associated with the component.

Non-contained members

(for example, assembly level or attribute applied to type)

The default value for the optional parameter.

INotifyPropertyChanged Interface Callermembername Properties

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.