private object CreateObjectCore(ReferenceTargetProperty property) { // Is it multidimensional array? if (property is MultiDimensionalArrayProperty multiDimensionalArrayProperty) { return(CreateObjectFromMultidimensionalArrayProperty(multiDimensionalArrayProperty)); } // Is it single dimensional array? if (property is SingleDimensionalArrayProperty singleDimensionalArrayProperty) { return(CreateObjectFromSingleDimensionalArrayProperty(singleDimensionalArrayProperty)); } // Is it dictionary? if (property is DictionaryProperty dictionaryProperty) { return(CreateObjectFromDictionaryProperty(dictionaryProperty)); } // Is it collection? if (property is CollectionProperty collectionProperty) { return(CreateObjectFromCollectionProperty(collectionProperty)); } // Is it complex type? Class? Structure? if (property is ComplexProperty complexProperty) { return(CreateObjectFromComplexProperty(complexProperty)); } return(null); }
/// <summary> /// </summary> /// <param name = "name"></param> /// <param name = "value"></param> /// <returns>NullProperty if the value is null</returns> public Property CreateProperty(string name, object value) { if (value == null) { return(new NullProperty(name)); } // If value type is recognized, it will be taken from typeinfo cache TypeInfo typeInfo = TypeInfo.GetTypeInfo(value); // Is it simple type Property property = createSimpleProperty(name, typeInfo, value); if (property != null) { // It is simple type return(property); } // From now it can only be an instance of ReferenceTargetProperty ReferenceTargetProperty referenceTarget = createReferenceTargetInstance(name, typeInfo); // Search in Cache ReferenceTargetProperty cachedTarget; if (_propertyCache.TryGetValue(value, out cachedTarget)) { // Value was already referenced // Its reference will be used cachedTarget.Reference.Count++; referenceTarget.MakeFlatCopyFrom(cachedTarget); return(referenceTarget); } // Target was not found in cache // it must be created // Adding property to cache referenceTarget.Reference = new ReferenceInfo(); referenceTarget.Reference.Id = _currentReferenceId++; _propertyCache.Add(value, referenceTarget); // Parsing the property var handled = fillSingleDimensionalArrayProperty(referenceTarget as SingleDimensionalArrayProperty, typeInfo, value); handled = handled || fillMultiDimensionalArrayProperty(referenceTarget as MultiDimensionalArrayProperty, typeInfo, value); handled = handled || fillDictionaryProperty(referenceTarget as DictionaryProperty, typeInfo, value); handled = handled || fillCollectionProperty(referenceTarget as CollectionProperty, typeInfo, value); handled = handled || fillComplexProperty(referenceTarget as ComplexProperty, typeInfo, value); if (!handled) { throw new InvalidOperationException(string.Format("Property cannot be filled. Property: {0}", referenceTarget)); } return(referenceTarget); }
private bool serializeReference(ReferenceTargetProperty property) { if (property.Reference.Count > 1) { // There are more references to this object if (property.Reference.IsProcessed) { // The object is already serialized // Only its reference should be stored SerializeReference(property); return(true); } } return(false); }
private object createObjectCore(ReferenceTargetProperty property) { // Is it multidimensional array? var multiDimensionalArrayProperty = property as MultiDimensionalArrayProperty; if (multiDimensionalArrayProperty != null) { return(createObjectFromMultidimensionalArrayProperty(multiDimensionalArrayProperty)); } // Is it singledimensional array? var singleDimensionalArrayProperty = property as SingleDimensionalArrayProperty; if (singleDimensionalArrayProperty != null) { return(createObjectFromSingleDimensionalArrayProperty(singleDimensionalArrayProperty)); } // Is it dictionary? var dictionaryProperty = property as DictionaryProperty; if (dictionaryProperty != null) { return(createObjectFromDictionaryProperty(dictionaryProperty)); } // Is it collection? var collectionProperty = property as CollectionProperty; if (collectionProperty != null) { return(createObjectFromCollectionProperty(collectionProperty)); } // Is it complex type? Class? Structure? var complexProperty = property as ComplexProperty; if (complexProperty != null) { return(createObjectFromComplexProperty(complexProperty)); } return(null); }
private object createObjectCore(ReferenceTargetProperty property) { // Is it multidimensional array? var multiDimensionalArrayProperty = property as MultiDimensionalArrayProperty; if (multiDimensionalArrayProperty != null) { return createObjectFromMultidimensionalArrayProperty(multiDimensionalArrayProperty); } // Is it singledimensional array? var singleDimensionalArrayProperty = property as SingleDimensionalArrayProperty; if (singleDimensionalArrayProperty != null) { return createObjectFromSingleDimensionalArrayProperty(singleDimensionalArrayProperty); } // Is it dictionary? var dictionaryProperty = property as DictionaryProperty; if (dictionaryProperty != null) { return createObjectFromDictionaryProperty(dictionaryProperty); } // Is it collection? var collectionProperty = property as CollectionProperty; if (collectionProperty != null) { return createObjectFromCollectionProperty(collectionProperty); } // Is it complex type? Class? Structure? var complexProperty = property as ComplexProperty; if (complexProperty != null) { return createObjectFromComplexProperty(complexProperty); } return null; }
/// <summary> /// /// </summary> /// <param name="referenceTarget"></param> protected abstract void SerializeReference(ReferenceTargetProperty referenceTarget);
private bool serializeReference(ReferenceTargetProperty property) { if (property.Reference.Count > 1) { // There are more references to this object if (property.Reference.IsProcessed) { // The object is already serialized // Only its reference should be stored SerializeReference(property); return true; } } return false; }
/// <summary> /// /// </summary> /// <param name="referenceTarget"></param> protected override void SerializeReference(ReferenceTargetProperty referenceTarget) { this.writePropertyHeader(Elements.Reference, referenceTarget.Name, null); this._writer.WriteNumber(referenceTarget.Reference.Id); }
/// <summary> /// Stores only reference to an object, not the object itself /// </summary> /// <param name="referenceTarget"></param> protected override void SerializeReference(ReferenceTargetProperty referenceTarget) { writeStartProperty(Elements.Reference, referenceTarget.Name, null); _writer.WriteAttribute(Attributes.ReferenceId, referenceTarget.Reference.Id); writeEndProperty(); }
/// <summary> /// /// </summary> /// <param name="referenceTarget"></param> protected override void SerializeReference(ReferenceTargetProperty referenceTarget) { writePropertyHeader(Elements.Reference, referenceTarget.Name, null); _writer.WriteNumber(referenceTarget.Reference.Id); }