Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
403 views
in Technique[技术] by (71.8m points)

c# - Reflection Get Variables in Method

How can i get varibles used in Method which then I will write their values on Console ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You cannot. Reflection does not extend to reading the values of method variables. It only handles the declaration metadata of variables. And even then, the compiler may have removed the variable you thought you declared. Reflection allows full access to fields (instance / static type variables), but not method variables.

There are tricks you can use like lambda expressions, but this changes their form (from method variables into instance fields).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...