Exemple #1
0
        public void Resolve()
        {
            EnumerateProperties();

            if (Session.Relatives.ContainsKey(Self)) Value = Session.Relatives[Self];

            else if (AlreadyFound) Value = new CicularReference();

            else if (Value == null && Todo == null) Value = "";

            else if (Todo != null)
            {
                var values = new List<string>();

                foreach (var kvp in Todo)
                {
                    var temp = kvp.Value.Invoke();

                    if (temp is CicularReference || temp.Value is CicularReference) continue;

                    values.Add(Stringify(kvp.Key, Casing) + ": " + Stringify(temp));
                }

                if (values.Any()) Value = "{ " + string.Join(", ", values) + " }";
            }
        }
Exemple #2
0
        public void Resolve()
        {
            EnumerateProperties();

            if (Session.Relatives.ContainsKey(Self))
            {
                Value = Session.Relatives[Self];
            }

            else if (AlreadyFound)
            {
                Value = new CicularReference();
            }

            else if (Value == null && Todo == null)
            {
                Value = "";
            }

            else if (Todo != null)
            {
                var values = new List <string>();

                foreach (var kvp in Todo)
                {
                    var temp = kvp.Value.Invoke();

                    if (temp is CicularReference || temp.Value is CicularReference)
                    {
                        continue;
                    }

                    values.Add(Stringify(kvp.Key, Casing) + ": " + Stringify(temp));
                }

                if (values.Any())
                {
                    Value = "{ " + string.Join(", ", values) + " }";
                }
            }
        }
Exemple #3
0
        public void EnumerateProperties()
        {
            if (Enumerated) return;

            if (Session.Visited.Contains(Self))
            {
                AlreadyFound = true;
                return;
            }

            if (IsValueType(Self))
            {
                Value = Stringify(Self);
                Todo = null;
                Enumerated = true;
                return;
            }

            Todo = new Dictionary<string, Func<dynamic>>();

            if (Self is IEnumerable<dynamic>)
            {
                if (Session.ProcessingList == true)
                {
                    Enumerated = false;
                    return;
                }

                Session.ProcessingList = true;
                var todos = new List<Item>();

                foreach (var item in (Self as IEnumerable<dynamic>))
                {
                    Item newItem = new Item(item, Session, Casing, true);
                    newItem.EnumerateProperties();
                    todos.Add(newItem);
                }

                Session.ProcessingList = false;

                todos.ForEach(s => s.Resolve());

                if (todos.Any() && todos.All(s => s.IsCircular())) Value = new CicularReference();

                else Value = "[ " + string.Join(", ", todos.Where(s => !s.IsCircular()).Select(x => x.Value)) + " ]";

                Todo = null;
            }
            else if (Self is Prototype)
            {
                Session.Visited.Add(Self);
                ResultsFor(Self);
            }
            else if (Self is Gemini)
            {
                Session.Visited.Add(Self);
                ResultsFor(Self.HashOfProperties());
            }
            else
            {
                Session.Visited.Add(Self);
                ResultsFor((Self as object).ToPrototype());
            }

            Enumerated = true;
        }
Exemple #4
0
        public void EnumerateProperties()
        {
            if (Enumerated)
            {
                return;
            }

            if (Session.Visited.Contains(Self))
            {
                AlreadyFound = true;
                return;
            }

            if (IsValueType(Self))
            {
                Value      = Stringify(Self);
                Todo       = null;
                Enumerated = true;
                return;
            }

            Todo = new Dictionary <string, Func <dynamic> >();

            if (Self is IEnumerable <dynamic> )
            {
                if (Session.ProcessingList == true)
                {
                    Enumerated = false;
                    return;
                }

                Session.ProcessingList = true;
                var todos = new List <Item>();

                foreach (var item in (Self as IEnumerable <dynamic>))
                {
                    Item newItem = new Item(item, Session, Casing, true);
                    newItem.EnumerateProperties();
                    todos.Add(newItem);
                }

                Session.ProcessingList = false;

                todos.ForEach(s => s.Resolve());

                if (todos.Any() && todos.All(s => s.IsCircular()))
                {
                    Value = new CicularReference();
                }

                else
                {
                    Value = "[ " + string.Join(", ", todos.Where(s => !s.IsCircular()).Select(x => x.Value)) + " ]";
                }

                Todo = null;
            }
            else if (Self is Prototype)
            {
                Session.Visited.Add(Self);
                ResultsFor(Self);
            }
            else if (Self is Gemini)
            {
                Session.Visited.Add(Self);
                ResultsFor(Self.HashOfProperties());
            }
            else
            {
                Session.Visited.Add(Self);
                ResultsFor((Self as object).ToPrototype());
            }

            Enumerated = true;
        }