Exemplo n.º 1
0
 public static void Main()
 {
     var popsicle = new Popsicle();
     popsicle.Value = 10;
     popsicle.Freeze();
     popsicle.Value = 20; // Bang!
 }
Exemplo n.º 2
0
    public static void Main()
    {
        var popsicle = new Popsicle();

        popsicle.Value = 10;
        popsicle.Freeze();
        popsicle.Value = 20; // Bang!
    }
Exemplo n.º 3
0
    public static void Main()
    {
        var popsicle = new Popsicle();

        popsicle.Value = 10;
        popsicle.Value = 15;
        popsicle.Freeze();
        Console.WriteLine(popsicle.Value); // 15? Memory model madness
        popsicle.Value = 20;               // Bang!
    }
Exemplo n.º 4
0
        public static void Run()
        {
            var popsicle = new Popsicle();

            popsicle.Value = 1;
            popsicle.Value = 2;
            popsicle.Freeze();
            //Exception!
            popsicle.Value = 2;
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            #region Level 0

            string name = " 123456 ";
            name.Trim();
            Console.WriteLine(name.Length);

            name = name.Trim(); // immutable always returns a new string
            Console.WriteLine(name.Length);

            #endregion

            #region Basic

            var r1 = new MutableRectangle();
            r1.Height = 10;
            r1.Length = 5;
            r1.Grow(10, 5);

            Console.WriteLine(r1.ToString());

            #endregion

            #region Patterns

            #region 1. Mutable
            var m = new Mutable();
            m.Value = 10;
            m.Value = 20;
            #endregion

            #region 2. ShallowMutable
            StringBuilder builder = new StringBuilder();
            builder.Append("foo");
            var sm = new ShallowMutable(10, builder);
            sm.Builder.Append("bar");
            Console.WriteLine(sm.Builder);
            #endregion

            #region 3. Popsicle
            var p = new Popsicle();
            p.Value = 10;
            p.Freeze();
            //p.Value = 20; //Bang!
            #endregion

            #region 4. ObservableImmutable

            #endregion

            #endregion

            Console.ReadLine();
        }
Exemplo n.º 6
0
        public void IsMutable()
        {
            var p = new Popsicle();

            Guard.IsMutable(p.A, "A");
            Guard.IsMutable(p.B, "B");
            Guard.IsMutable(p.C, "C");

            p.A = 1;
            ExceptionAssert.Throws<InvalidOperationException>(() => Guard.IsMutable(p.A, "A"));
            Guard.IsMutable(p.B, "B");
            Guard.IsMutable(p.C, "C");

            p.B = p;
            ExceptionAssert.Throws<InvalidOperationException>(() => Guard.IsMutable(p.A, "A"));
            ExceptionAssert.Throws<InvalidOperationException>(() =>Guard.IsMutable(p.B, "B"));
            Guard.IsMutable(p.C, "C");

            p.C = new TimeSpan(10, 59, 30);
            ExceptionAssert.Throws<InvalidOperationException>(() => Guard.IsMutable(p.A, "A"));
            ExceptionAssert.Throws<InvalidOperationException>(() => Guard.IsMutable(p.B, "B"));
            ExceptionAssert.Throws<InvalidOperationException>(() => Guard.IsMutable(p.C, "C"));
        }
Exemplo n.º 7
0
    public void Initialize()
    {
        LoadData();

        MainPanel      = this.GetComponent <RectTransform>().Find("Image").GetComponent <RectTransform>();
        BubbleList     = new List <GameObject>();
        UserBubbleList = new List <GameObject>();

        GameObject popsicle = UICreate.InstantiateRectTransformPrefab(Resources.Load <GameObject>("Prefabs/ContactsScreen/Popsicle"), MainPanel.GetComponent <RectTransform>());

        _Popsicle = popsicle.GetComponent <Popsicle>();

        GameObject prefab = Resources.Load <GameObject>("Prefabs/FrontPageButtons/MiddleDial");

        MiddleDial = UICreate.InstantiateRectTransformPrefab(prefab, MainPanel.GetComponent <RectTransform>());
        MiddleDial.GetComponent <RectTransform>().localScale = new Vector3(1.75f, 1.75f, 1);

        Button callButton = MiddleDial.transform.Find("CallButton").GetComponent <Button>();

        callButton.onClick.AddListener(() =>
        {
            SoundManager.GetInstance().PlaySingle("SoundFX/pop_drip");
            SoundManager.GetInstance().PlaySingle("SoundFX/Ringing_Phone", true);
            if (UserDataController.GetInstance().ActiveUserType == UserDataController.UserType.Caregiver)
            {
                UserDataController.GetInstance().UserName  = "******";
                UserDataController.GetInstance().UserImage = "Linda";
            }
            else
            {
                UserDataController.GetInstance().UserName  = "******";
                UserDataController.GetInstance().UserImage = "Emma";
            }

            TransitionToCall();
            callButton.onClick.RemoveAllListeners();
        });

        if (UserDataController.GetInstance().ActiveUserType == UserDataController.UserType.Caregiver)
        {
            AddBubbleToList(0, 0, model[0]);
            AddBubbleToList(-25, 25, model[1]);
            AddBubbleToList(25, -25, model[2]);
            AddContactListBubble(50, -50);
            AddContactAddBubble(-50, 50);
        }
        else
        {
            AddBubbleToList(0, 0, model[0]);
            AddBubbleToList(-25, 25, model[1]);
            AddBubbleToList(-50, 50, model[2]);
            AddBubbleToList(50, -50, model[3]);
            AddBubbleToList(25, -25, model[4]);
            AddContactListBubble(75, -75);
            AddContactAddBubble(-75, 75);
        }

        //FillWithData();
        //Image img = BubbleList[2].transform.Find("Circle/ImageMask/Image").GetComponent<Image>();
        //RotateArrow(BubbleList[2].transform.Find("Circle").GetComponent<RectTransform>().localRotation, img.sprite, model[2]);

        if (BubbleList.Count > 0)
        {
            BubbleList[0].GetComponent <Button>().onClick.Invoke();
        }

        EnterAnimation();
    }