public static void Freeze(object item) { if (item is IFreezable) { IFreezable f = item as IFreezable; f.Freeze(); } }
public static void Freeze(object item) { IFreezable f = item as IFreezable; if (f != null) { f.Freeze(); } }
private void Freeze(IFreezable freezable) { if (freezable != null && !collisions.Contains(freezable)) { if (isActive) { freezable.Freeze(); } collisions.Add(freezable); } }
public Exception ValidateValue(object value, string locationName, LocationKind locationKind) { IFreezable freezable = value as IFreezable; if (freezable != null) { freezable.Freeze(); } return(null); }
public static void TestFreeze(IFreezable sut) { var properties = sut.GetType().GetRuntimeProperties() .Where(x => x.CanWrite && x.CanRead && x.Name != "IsFrozen"); foreach (var property in properties) { var value = property.PropertyType.IsValueType ? Activator.CreateInstance(property.PropertyType) : null; property.SetValue(sut, value); var result = property.GetValue(sut); Assert.Equal(value, result); } sut.Freeze(); foreach (var property in properties) { var value = property.PropertyType.IsValueType ? Activator.CreateInstance(property.PropertyType) : null; Assert.Throws <InvalidOperationException>(() => { try { property.SetValue(sut, value); } catch (Exception ex) { throw ex.InnerException; } }); } }