Exemple #1
0
            /// <summary>
            /// Perform a depth-first search, finding a cycle by marking visited value promises.
            /// </summary>
            /// <returns><code>true</code> if and only if no cycle was found</returns>
            private bool IsCycleFreeFrom(IValuePromise valuePromise)
            {
                bool isCycleFree;

                if (m_markers.TryGetValue(valuePromise, out isCycleFree))
                {
                    return(isCycleFree);
                }

                m_markers[valuePromise] = false; // valuePromise is being visited; if we recursively find it again, it's a cycle!
                Dictionary <IValuePromise, int> toCountedValuePromises;

                if (m_graph.TryGetValue(valuePromise, out toCountedValuePromises))
                {
                    foreach (var toValuePromise in toCountedValuePromises.Keys)
                    {
                        if (!IsCycleFreeFrom(toValuePromise))
                        {
                            return(false);
                        }
                    }
                }

                m_markers[valuePromise] = true; // valuePromise is fully visited and no cycle was found from it.
                return(true);
            }
Exemple #2
0
 internal static void DeserializeHelper(Type tItem, IParser parser, Func <IParser, Type, object> nestedObjectDeserializer, IList result, bool canUpdate)
 {
     parser.Expect <SequenceStart>();
     while (!parser.Accept <SequenceEnd>())
     {
         ParsingEvent  current      = parser.Current;
         object        obj          = nestedObjectDeserializer(parser, tItem);
         IValuePromise valuePromise = obj as IValuePromise;
         if (valuePromise == null)
         {
             result.Add(TypeConverter.ChangeType(obj, tItem));
         }
         else
         {
             if (!canUpdate)
             {
                 throw new ForwardAnchorNotSupportedException(current.Start, current.End, "Forward alias references are not allowed because this type does not implement IList<>");
             }
             int index = result.Add((!tItem.IsValueType()) ? null : Activator.CreateInstance(tItem));
             valuePromise.ValueAvailable += delegate(object v)
             {
                 result[index] = TypeConverter.ChangeType(v, tItem);
             };
         }
     }
     parser.Expect <SequenceEnd>();
 }
Exemple #3
0
        bool INodeDeserializer.Deserialize(IParser parser, Type expectedType, Func <IParser, Type, object> nestedObjectDeserializer, out object value)
        {
            MappingStart mappingStart = parser.Allow <MappingStart>();

            if (mappingStart == null)
            {
                value = null;
                return(false);
            }
            value = _objectFactory.Create(expectedType);
            while (!parser.Accept <MappingEnd>())
            {
                Scalar scalar = parser.Expect <Scalar>();
                IPropertyDescriptor property = _typeDescriptor.GetProperty(expectedType, null, scalar.Value, _ignoreUnmatched);
                if (property == null)
                {
                    if (_unmatchedLogFn != null)
                    {
                        _unmatchedLogFn(string.Format("{2} Found a property '{0}' on a type '{1}', but that type doesn't have that property!", scalar.Value, expectedType.FullName, parser.Current.Start));
                    }
                    parser.SkipThisAndNestedEvents();
                }
                else
                {
                    object        obj          = nestedObjectDeserializer(parser, property.Type);
                    IValuePromise valuePromise = obj as IValuePromise;
                    if (valuePromise == null)
                    {
                        object value2 = TypeConverter.ChangeType(obj, property.Type);
                        property.Write(value, value2);
                    }
                    else
                    {
                        object valueRef = value;
                        valuePromise.ValueAvailable += delegate(object v)
                        {
                            object value3 = TypeConverter.ChangeType(v, property.Type);
                            property.Write(valueRef, value3);
                        };
                    }
                }
            }
            parser.Expect <MappingEnd>();
            return(true);
        }
Exemple #4
0
 public Edge(IValuePromise from, IValuePromise to)
 {
     From = from;
     To   = to;
 }
 private static void DeserializeHelper(Type tKey, Type tValue, IParser parser, Func <IParser, Type, object> nestedObjectDeserializer, IDictionary result)
 {
     parser.Expect <MappingStart>();
     while (!parser.Accept <MappingEnd>())
     {
         object        key           = nestedObjectDeserializer(parser, tKey);
         IValuePromise valuePromise  = key as IValuePromise;
         object        value         = nestedObjectDeserializer(parser, tValue);
         IValuePromise valuePromise2 = value as IValuePromise;
         if (valuePromise == null)
         {
             if (valuePromise2 == null)
             {
                 result[key] = value;
             }
             else
             {
                 valuePromise2.ValueAvailable += delegate(object v)
                 {
                     result[key] = v;
                 };
             }
         }
         else if (valuePromise2 == null)
         {
             valuePromise.ValueAvailable += delegate(object v)
             {
                 result[v] = value;
             };
         }
         else
         {
             bool hasFirstPart = false;
             valuePromise.ValueAvailable += delegate(object v)
             {
                 if (hasFirstPart)
                 {
                     result[v] = value;
                 }
                 else
                 {
                     key          = v;
                     hasFirstPart = true;
                 }
             };
             valuePromise2.ValueAvailable += delegate(object v)
             {
                 if (hasFirstPart)
                 {
                     result[key] = v;
                 }
                 else
                 {
                     value        = v;
                     hasFirstPart = true;
                 }
             };
         }
     }
     parser.Expect <MappingEnd>();
 }
Exemple #6
0
            public bool Deserialize(IParser parser, Type expectedType, Func <IParser, Type, object> nestedObjectDeserializer, out object value)
            {
                value = null;
                if (!typeof(ManagedGameObject).IsAssignableFrom(expectedType) || !parser.TryConsume(out MappingStart _))
                {
                    return(false);
                }
                bool findType = false;

                MappingEnd event2;

                Scalar scalar = parser.Consume <Scalar>();

                if (scalar.Value == "MGO.Type")
                {
                    string i = nestedObjectDeserializer(parser, typeof(string)) as string;
                    expectedType = TypeByName(i);
#if DEBUG
                    debugLogger.Start("Deserialize");

                    debugLogger.WriteLine($"nestedObjectDeserializer : { i }");
                    debugLogger.WriteLine($"expectedType : { expectedType }");

                    debugLogger.End();
#endif
                    if (expectedType == null)
                    {
                        findType = false;
                    }
                    else
                    {
                        value    = objectFactory.Create(expectedType);
                        findType = true;
                    }
                }

                while (!parser.TryConsume(out event2))
                {
                    scalar = parser.Consume <Scalar>();
                    IPropertyDescriptor property = typeDescriptor.GetProperty(expectedType, null, scalar.Value, false);
                    if (property == null || !findType)
                    {
                        parser.SkipThisAndNestedEvents();
                        continue;
                    }

                    object        obj          = nestedObjectDeserializer(parser, property.Type);
                    IValuePromise valuePromise = obj as IValuePromise;
                    if (valuePromise != null)
                    {
                        object valueRef = value;
                        valuePromise.ValueAvailable += (Action <object>) delegate(object v)
                        {
                            object value3 = YamlDotNet.Serialization.Utilities.
                                            TypeConverter.ChangeType(v, property.Type);
                            property.Write(valueRef, value3);
                        };
                    }
                    else
                    {
                        object value2 = YamlDotNet.Serialization.Utilities.
                                        TypeConverter.ChangeType(obj, property.Type);
                        property.Write(value, value2);
                    }
                }
                return(true);
            }