17 Eyl 2011

Jquery İle input İçeriğini Temizleme onfocus, onblur ( Asp.net MVC )

var clearMePrevious = '';
        // focus'da içeriği temizle
        function focusFunc(strInputName) {
            if ($('#' + strInputName).val() == $('#' + strInputName).attr('title')) {
                clearMePrevious = $('#' + strInputName).val();
                $('#' + strInputName).val('');
            }
        }
       
        // Blur'da eski içeriği döndür
        function blurFunc(strInputName) {
            if ($('#' + strInputName).val('')) {
                $('#' + strInputName).val(clearMePrevious);
            }
        }
<input type="text" onblur="blurFunc('query');" onfocus="focusFunc('query');" id="query" name="query" title="Aranacak kelimeyi giriniz" value="<%= Request.QueryString["query"] ?? "Aranacak kelimeyi giriniz" %>" />

12 Eyl 2011

C# .Net Reflection Kullanım Örneği

Örneğin test namespace'i ile oluşturulan projenin dll'ini ele alalım.

[C#]
namespace Test 
public class Calculator 
 {
public Calculator() { ... } 
private double _number; 
public double Number { get { ... } set { ... } } 
public void Clear() { ... }         private void DoClear() { ... } 
public double Add(double number) { ... } 
public static double Pi { ... } 
public static double GetPi() { ... }
 } 
}  



[C#]
// dynamically load assembly from file Test.dll 
Assembly testAssembly = Assembly.LoadFile(@"c:\Test.dll");

// get type of class Calculator from just loaded assembly 
Type calcType = testAssembly.GetType("Test.Calculator");

// create instance of class Calculator                                                                                    
 object calcInstance = Activator.CreateInstance(calcType); 

// get info about property: public double Number                                                                  
PropertyInfo numberPropertyInfo = calcType.GetProperty("Number"); 

// get value of property: public double Number                                                                       
double value = (double)numberPropertyInfo.GetValue(calcInstance, null); 

// set value of property: public double Number                                                                       numberPropertyInfo.SetValue(calcInstance, 10.0, null); 

// get info about static property: public static double Pi       
PropertyInfo piPropertyInfo = calcType.GetProperty("Pi"); 

// get value of static property: public static double Pi                                                           
double piValue = (double)piPropertyInfo.GetValue(null, null); 

// invoke public instance method: public void Clear()                                                           
calcType.InvokeMember("Clear",     BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.Public,     null, calcInstance, null); 

// invoke private instance method: private void DoClear()
calcType.InvokeMember("DoClear",     BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.NonPublic,     null, calcInstance, null); 

// invoke public instance method: public double Add(double number)                                 
double value = (double)calcType.InvokeMember("Add",     BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.Public,     null, calcInstance, new object[] { 20.0 }); 

// invoke public static method: public static double GetPi()                                                 
double piValue = (double)calcType.InvokeMember("GetPi",     BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.Public,     null, null, null); 

// get value of private field: private double _number                                                            
double value = (double)calcType.InvokeMember("_number",     BindingFlags.GetField | BindingFlags.Instance | BindingFlags.NonPublic,     null, calcInstance, null);





KAYNAK:  http://www.csharp-examples.net/reflection-examples/

Reflection ile Execute Edilen Metod'un Namespace, Class Adı, ve Metod adını alma

protected string CurrentName
  {
    get
    {
      StackTrace st = new StackTrace(true);
      MethodBase mb = st.GetFrame(1).GetMethod();
      return mb.ReflectedType.Namespace + "." + mb.ReflectedType.Name + "." + mb.Name;
    }
  }