public void TryCastFrom_ReferencesSamePropertyValue() { var carrier = new object(); var name = Guid.NewGuid().ToString("N"); PropertyConnector.Default.Get(carrier, name).Set(13); Assert.AreEqual(13, ConnectibleProperty <int> .TryCastFrom(PropertyConnector.Default.Get(carrier, name)).Get()); }
public void TryCastFrom_ToInvalidType_ThrowsWhenUsed() { var carrier = new object(); var name = Guid.NewGuid().ToString("N"); PropertyConnector.Default.Get(carrier, name).Set(13); var property = ConnectibleProperty <string> .TryCastFrom(PropertyConnector.Default.Get(carrier, name)); AssertEx.Throws <InvalidCastException>(() => property.Get()); }
public void TryCastFrom_WithNullSource_ReturnsNull() { ConnectibleProperty <dynamic> source = null; Assert.IsNull(ConnectibleProperty <string> .TryCastFrom(source)); }
public static IConnectibleProperty <TValue> TryGetConnectedProperty <TValue, TTag>(this object carrier, bool bypassValidation) { Contract.Requires(carrier != null); return(ConnectibleProperty <TValue> .TryCastFrom(Connector.TryGet <TTag>(carrier, bypassValidation))); }
/// <summary> /// Gets a connectible property on the specified carrier object, optionally bypassing carrier object validation. Returns <c>null</c> if validation is not bypassed and the specified object cannot have connected properties. /// </summary> /// <param name="carrier">The carrier object for which to retrieve the connectible property. This object must be reference-equatable unless validation is bypassed. May not be <c>null</c>.</param> /// <param name="bypassValidation">Whether to bypass carrier object validation. Normally, callers pass <c>true</c> for this parameter.</param> /// <returns>The connectible property, or <c>null</c> if <paramref name="bypassValidation"/> is <c>false</c> and <paramref name="carrier"/> may not have connected properties.</returns> public IConnectibleProperty <TValue> TryGetProperty(TCarrier carrier, bool bypassValidation) { return(ConnectibleProperty <TValue> .TryCastFrom(_connector.TryGet(carrier, string.Empty, bypassValidation))); }