Reflection in Dot Net
GET ASSEMBLY(Currently executing OR With Location) INFORMATION
Add following NameSpace
using System.Reflection;
Now write code in code file as per your requirement.
string strFile_URL_Path = string.Empty;
string strFilePath = string.Empty;
string strVersionNo = string.Empty;
string strAssemblyName = string.Empty;
string strCultureInfo = string.Empty;
string strFilePath = string.Empty;
string strVersionNo = string.Empty;
string strAssemblyName = string.Empty;
string strCultureInfo = string.Empty;
//Find Information Of Executing Assembly
Version v = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; //GET VERSION NO
strVersionNo = v.ToString();
strCultureInfo = System.Reflection.Assembly.GetExecutingAssembly().GetName().CultureInfo.ToString();
object[] ar = new object[] { };
ar = System.Reflection.Assembly.GetExecutingAssembly().GetReferencedAssemblies(); //Get All Referenced Assembly Object From Current assembly
strVersionNo = v.ToString();
strCultureInfo = System.Reflection.Assembly.GetExecutingAssembly().GetName().CultureInfo.ToString();
object[] ar = new object[] { };
ar = System.Reflection.Assembly.GetExecutingAssembly().GetReferencedAssemblies(); //Get All Referenced Assembly Object From Current assembly
//Find Information With Location of assembly
AssemblyName anm = AssemblyName.GetAssemblyName("c:\\Sharjeel.dll");
strFile_URL_Path = anm.CodeBase; //Get Complete Assembly path as URL
strFilePath = anm.CultureInfo.ToString(); // Get Assembly Culture Information
strAssemblyName = anm.FullName.ToString(); //Get full name including version, token
strFile_URL_Path = anm.CodeBase; //Get Complete Assembly path as URL
strFilePath = anm.CultureInfo.ToString(); // Get Assembly Culture Information
strAssemblyName = anm.FullName.ToString(); //Get full name including version, token
GET METHOD INFO FROM ASSEMBLY
Add following NameSpace
using System.Diagnostics;
Now write following Code
System.Diagnostics.StackFrame sf = new System.Diagnostics.StackFrame(1);
System.Reflection.MethodBase mb = sf.GetMethod();
string assemblyName = mb.DeclaringType.Assembly.GetName().Name;
string Method = mb.DeclaringType.Name + "." + mb.Name + "()";
System.Reflection.MethodBase mb = sf.GetMethod();
string assemblyName = mb.DeclaringType.Assembly.GetName().Name;
string Method = mb.DeclaringType.Name + "." + mb.Name + "()";
GET CURRENT METHOD NAME & PARAMETERS OF THAT METHOD IN CODE FILE:
string CurrentMethodName = System.Reflection.MethodBase.GetCurrentMethod().Name.ToString();
object[] ParametersOfMethos = new object[] { };
ParametersOfMethos = System.Reflection.MethodBase.GetCurrentMethod().GetParameters();
object[] ParametersOfMethos = new object[] { };
ParametersOfMethos = System.Reflection.MethodBase.GetCurrentMethod().GetParameters();
Comments
Post a Comment