Esempio n. 1
0
 public static void Freeze(object item)
 {
     if (item is IFreezable)
     {
         IFreezable f = item as IFreezable;
         f.Freeze();
     }
 }
Esempio n. 2
0
        public static void Freeze(object item)
        {
            IFreezable f = item as IFreezable;

            if (f != null)
            {
                f.Freeze();
            }
        }
Esempio n. 3
0
 private void Freeze(IFreezable freezable)
 {
     if (freezable != null && !collisions.Contains(freezable))
     {
         if (isActive)
         {
             freezable.Freeze();
         }
         collisions.Add(freezable);
     }
 }
Esempio n. 4
0
        public Exception ValidateValue(object value, string locationName, LocationKind locationKind)
        {
            IFreezable freezable = value as IFreezable;

            if (freezable != null)
            {
                freezable.Freeze();
            }

            return(null);
        }
Esempio n. 5
0
        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;
                    }
                });
            }
        }