Παρουσίαση με Ετικέτες

Xpo Properties for Strongly Typed freaks!!!
16 Ιουνίου 09 05:03 μμ | tolisss | 0 σχόλια   
Because XPbaseObject implements INotifyPropertyChanged property setters need to be implemented using a special way like public   string Name {     get     {         return name;     }     set     {         SetPropertyValue( "Name" , ref name, value);     } } but if you are a strongly typed fun like me the you certainly will not like the string representation of the “Name” as a parameter of SetPropertyValue because if you rename the property then you should explicitly rename the string parameter as well. I used to write my properties like private   string nameWithReflection; public  

Διαβάστε περισσότερα »

Δημοσίευση στην κατηγορία: , ,
More Static Reflection
15 Ιουνίου 09 10:57 μμ | tolisss | 0 σχόλια   
Today we are going to speak about an implementation of the approach describe in this post . INotifyPropertyChanged is responsible for notifying clients that a property value has changed.To implement INotifyPropertyChanged you should write a code similar to public class Client : INotifyPropertyChanged { private string name; public string Name { get { return name; } set { if (name == value) return; name = value; OnPropertyChanged(new PropertyChangedEventArgs("Name")); } } #region INotifyPropertyChanged Members public event PropertyChangedEventHandler PropertyChanged; #endregion protected virtual void OnPropertyChanged(PropertyChangedEventArgs e) { if (PropertyChanged != null) PropertyChanged(this, e); } } and the test of the behaviour that we want would

Διαβάστε περισσότερα »

Δημοσίευση στην κατηγορία: ,
Static Reflection
15 Ιουνίου 09 05:27 πμ | tolisss | 0 σχόλια   
We all get into situation where we need to access class metadata like properties,methods and fields and we use reflection to accomplish it private class Customer { public string LastName { get; set; } } [Test] public void Test() { Assert.IsNotNull(typeof(Customer).GetProperty("LastName")); } but what will happen if we change the property name of “LastName” to “SurnName” ?? Our test will fail . But there is a rescue on this one using linq expression trees. public static class ReflectionExtensions { public static MethodInfo GetMethod<TTarget>(this TTarget target, Expression<Action<TTarget>> method) { return GetMethodInfo(method); } private static MethodInfo GetMethodInfo(Expression method) { if (method == null) throw new ArgumentNullException("method");

Διαβάστε περισσότερα »

Δημοσίευση στην κατηγορία: ,

Search

Go

Το Ιστολόγιο

Ιστορικό Δημοσιεύσεων

Συνδρομές