public IPropertyDescriptor GetProperty(Type type, object container, string name, bool ignoreUnmatched) { try { return(_inner.GetProperty(type, container, name, ignoreUnmatched)); } catch (System.Runtime.Serialization.SerializationException) { return(_inner.GetProperty(type, container, name + "Property", ignoreUnmatched)); } }
bool INodeDeserializer.Deserialize(IParser reader, Type expectedType, Func <IParser, Type, object> nestedObjectDeserializer, out object value) { var mapping = reader.Allow <MappingStart>(); if (mapping == null) { value = null; return(false); } value = _objectFactory.Create(expectedType); while (!reader.Accept <MappingEnd>()) { var propertyName = reader.Expect <Scalar>(); var property = _typeDescriptor.GetProperty(expectedType, value, propertyName.Value, _ignoreUnmatched); if (property == null) { reader.SkipThisAndNestedEvents(); continue; } var propertyValue = nestedObjectDeserializer(reader, property.Type); if (!(propertyValue is IValuePromise propertyValuePromise)) { var convertedValue = TypeConverter.ChangeType(propertyValue, property.Type); property.Write(value, convertedValue); }
public IPropertyDescriptor GetProperty(Type type, object container, string name, bool ignoreUnmatched) { if (container is PSObject psObject) { return(new PSObjectPropertyDescriptor(psObject.Properties[name])); } return(innerTypeDescriptor.GetProperty(type, container, name, ignoreUnmatched)); }
public IPropertyDescriptor GetProperty(Type type, object container, string name, bool ignoreUnmatched) { if (type != typeof(DynamicXml)) { return(_baseTypeInspector.GetProperty(type, container, name, ignoreUnmatched)); } return(GetProperty(container as DynamicXml, name, ignoreUnmatched, 0)); }
public IPropertyDescriptor GetProperty(Type type, object container, string name, bool ignoreUnmatched) { if (type != null && defaultInterfaceImplementations.TryGetValue(type, out var implementationType)) { type = implementationType; } return(typeInspector.GetProperty(type, container, name, ignoreUnmatched)); }
bool INodeDeserializer.Deserialize(IParser parser, Type expectedType, Func <IParser, Type, object?> nestedObjectDeserializer, out object?value) { if (!parser.TryConsume <MappingStart>(out var mapping)) { value = null; return(false); } // Strip off the nullable type, if present. This is needed for nullable structs. var implementationType = Nullable.GetUnderlyingType(expectedType) ?? expectedType; value = objectFactory.Create(implementationType); while (!parser.TryConsume <MappingEnd>(out var _)) { var propertyName = parser.Consume <Scalar>(); try { var property = typeDescriptor.GetProperty(implementationType, null, propertyName.Value, ignoreUnmatched); if (property == null) { parser.SkipThisAndNestedEvents(); continue; } var propertyValue = nestedObjectDeserializer(parser, property.Type); if (propertyValue is IValuePromise propertyValuePromise) { var valueRef = value; propertyValuePromise.ValueAvailable += v => { var convertedValue = TypeConverter.ChangeType(v, property.Type); property.Write(valueRef, convertedValue); }; } else { var convertedValue = TypeConverter.ChangeType(propertyValue, property.Type); property.Write(value, convertedValue); } } catch (SerializationException ex) { throw new YamlException(propertyName.Start, propertyName.End, ex.Message); } catch (YamlException) { throw; } catch (Exception ex) { throw new YamlException(propertyName.Start, propertyName.End, "Exception during deserialization", ex); } } return(true); }
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); }
bool INodeDeserializer.Deserialize(IParser parser, Type expectedType, Func <IParser, Type, object> nestedObjectDeserializer, out object value) { var mapping = parser.Allow <MappingStart>(); if (mapping == null) { value = null; return(false); } value = _objectFactory.Create(expectedType); while (!parser.Accept <MappingEnd>()) { var propertyName = parser.Expect <Scalar>(); var property = _typeDescriptor.GetProperty(expectedType, null, propertyName.Value, _ignoreUnmatched); if (property == null) { parser.SkipThisAndNestedEvents(); continue; } var propertyValue = nestedObjectDeserializer(parser, property.Type); var propertyValuePromise = propertyValue as IValuePromise; if (propertyValuePromise == null) { var convertedValue = TypeConverter.ChangeType(propertyValue, property.Type); property.Write(value, convertedValue); } else { var valueRef = value; propertyValuePromise.ValueAvailable += v => { var convertedValue = TypeConverter.ChangeType(v, property.Type); property.Write(valueRef, convertedValue); }; } } parser.Expect <MappingEnd>(); return(true); }
bool INodeDeserializer.Deserialize(EventReader reader, Type expectedType, Func <EventReader, Type, object> nestedObjectDeserializer, out object value) { var mapping = reader.Allow <MappingStart>(); if (mapping == null) { value = null; return(false); } value = _objectFactory.Create(expectedType); while (!reader.Accept <MappingEnd>()) { var propertyName = reader.Expect <Scalar>(); var property = _typeDescriptor.GetProperty(expectedType, null, propertyName.Value); var propertyValue = nestedObjectDeserializer(reader, property.Type); var propertyValuePromise = propertyValue as IValuePromise; if (propertyValuePromise == null) { var convertedValue = TypeConverter.ChangeType(propertyValue, property.Type); property.SetValue(value, convertedValue); } else { var valueRef = value; propertyValuePromise.ValueAvailable += v => { var convertedValue = TypeConverter.ChangeType(v, property.Type); property.SetValue(valueRef, convertedValue); }; } } reader.Expect <MappingEnd>(); return(true); }
public IPropertyDescriptor GetProperty(Type type, object container, string name, bool ignoreUnmatched) { return(TypeDescriptor.GetProperty(type, container, name, ignoreUnmatched)); }
public IPropertyDescriptor GetProperty(Type type, object container, string name) { return(TypeDescriptor.GetProperty(type, container, name)); }
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); }