/// <summary> /// Compare the <see cref="IValueUpdater"/> with another object to /// determine equality. /// </summary> /// <param name="o"> /// The object to compare with. /// </param> /// <returns> /// <b>true</b> iff this <see cref="IValueUpdater"/> and the passed /// object are quivalent <b>IValueUpdater</b>s. /// </returns> public override bool Equals(object o) { if (o is ReflectionUpdater) { ReflectionUpdater that = (ReflectionUpdater)o; return(m_memberName.Equals(that.m_memberName)); } return(false); }
/// <summary> /// Construct a <b>CompositeUpdater</b> for a specified method name /// sequence. /// </summary> /// <remarks> /// For example: "Address.Zip" property will indicate that /// the "Address" property should be used to extract an Address /// object, which will then be used by the "Zip" call. /// </remarks> /// <param name="name"> /// A dot-delimited sequence of N method names which results in a /// <b>CompositeUpdater</b> that is based on an chain of (N-1) /// <see cref="ReflectionExtractor"/> objects and a single /// <see cref="ReflectionUpdater"/>. /// </param> public CompositeUpdater(string name) { Debug.Assert(name != null && name.Length > 0); int ofLast = name.LastIndexOf('.'); m_extractor = ofLast == -1 ? (IValueExtractor)IdentityExtractor.Instance : new ChainedExtractor(name.Substring(0, ofLast)); m_updater = new ReflectionUpdater(name.Substring(ofLast + 1)); }
public void TestReflectionUpdater() { IValueUpdater updater = new ReflectionUpdater("field"); IValueUpdater updater1 = new ReflectionUpdater("field"); IValueUpdater updater2 = new CompositeUpdater("field"); Assert.IsNotNull(updater); Assert.AreEqual(updater, updater1); Assert.AreNotEqual(updater, updater2); Assert.AreEqual(updater.ToString(), updater1.ToString()); Assert.AreEqual(updater.GetHashCode(), updater1.GetHashCode()); ReflectionTestType o = new ReflectionTestType(); int value = 100; o.field = 0; updater.Update(o, value); Assert.AreEqual(o.field, value); updater.Update(o, value * 2); Assert.AreEqual(o.field, value * 2); try { updater.Update(null, value); } catch (Exception e) { Assert.IsInstanceOf(typeof(ArgumentNullException), e); } updater = new ReflectionUpdater("Property"); o.Property = 1; updater.Update(o, value); Assert.AreEqual(o.Property, value); updater = new ReflectionUpdater("SetMethod"); o = new ReflectionTestType(); updater.Update(o, value); Assert.AreEqual(o.field, value); try { updater = new ReflectionUpdater("InvalidMember"); updater.Update(o, value); } catch (Exception e) { Assert.IsInstanceOf(typeof(ArgumentException), e.InnerException); } }
public void TestCompositeUpdater() { IValueUpdater updater = new CompositeUpdater("field"); IValueUpdater updater1 = new CompositeUpdater("field"); IValueUpdater updater2 = new ReflectionUpdater("field"); Assert.IsNotNull(updater); Assert.AreEqual(updater, updater1); Assert.AreNotEqual(updater, updater2); Assert.AreEqual(updater.ToString(), updater1.ToString()); Assert.AreEqual(updater.GetHashCode(), updater1.GetHashCode()); IValueExtractor extractor = (updater as CompositeUpdater).Extractor; Assert.IsNotNull(extractor); IValueUpdater updter = (updater as CompositeUpdater).Updater; Assert.IsNotNull(updter); Assert.IsInstanceOf(typeof(IdentityExtractor), extractor); Assert.IsInstanceOf(typeof(ReflectionUpdater), updter); ReflectionTestType o = new ReflectionTestType(); int value = 100; o.field = 0; updater.Update(o, value); Assert.AreEqual(o.field, value); updater = new CompositeUpdater("InnerMember.field"); IValueExtractor ext = new ChainedExtractor("InnerMember"); IValueUpdater upd = new ReflectionUpdater("field"); updater1 = new CompositeUpdater(ext, upd); Assert.IsNotNull(updater); Assert.AreEqual(updater, updater1); Assert.AreEqual(updater.ToString(), updater1.ToString()); Assert.AreEqual(updater.GetHashCode(), updater1.GetHashCode()); updater.Update(o, value); Assert.AreEqual(o.InnerMember.field, value); }
public void TestUpdaterSerialization() { ConfigurablePofContext ctx = new ConfigurablePofContext("assembly://Coherence.Tests/Tangosol.Resources/s4hc-test-config.xml"); Assert.IsNotNull(ctx); CompositeUpdater compositeUpdater = new CompositeUpdater("name"); ReflectionUpdater reflectionUpdater = new ReflectionUpdater("member"); Stream stream = new MemoryStream(); ctx.Serialize(new DataWriter(stream), compositeUpdater); ctx.Serialize(new DataWriter(stream), reflectionUpdater); stream.Position = 0; Assert.AreEqual(compositeUpdater, ctx.Deserialize(new DataReader(stream))); Assert.AreEqual(reflectionUpdater, ctx.Deserialize(new DataReader(stream))); stream.Close(); }