/// <summary> /// Pushes an collection access on the path. /// </summary> /// <param name="descriptor">The descriptor of the set.</param> /// <param name="index">The index in the set.</param> /// <exception cref="System.ArgumentNullException">descriptor</exception> public void Push(SetDescriptor descriptor, object index) { if (descriptor == null) { throw new ArgumentNullException(nameof(descriptor)); } AddItem(new SetPathItem(descriptor, index)); }
public SetPathItem(SetDescriptor descriptor, object index) { if (descriptor == null) { throw new ArgumentNullException(nameof(descriptor)); } Descriptor = descriptor; Index = index; }
/// <summary> /// Creates a type descriptor for the specified type. /// </summary> /// <param name="type">The type.</param> /// <returns>An instance of type descriptor.</returns> protected virtual ITypeDescriptor Create(Type type) { ITypeDescriptor descriptor; // The order of the descriptors here is important if (PrimitiveDescriptor.IsPrimitive(type)) { descriptor = new PrimitiveDescriptor(this, type, emitDefaultValues, namingConvention); } else if (DictionaryDescriptor.IsDictionary(type)) // resolve dictionary before collections, as they are also collections { // IDictionary descriptor = new DictionaryDescriptor(this, type, emitDefaultValues, namingConvention); } else if (ListDescriptor.IsList(type)) { // IList descriptor = new ListDescriptor(this, type, emitDefaultValues, namingConvention); } else if (SetDescriptor.IsSet(type)) { // ISet descriptor = new SetDescriptor(this, type, emitDefaultValues, namingConvention); } else if (OldCollectionDescriptor.IsCollection(type)) { // ICollection descriptor = new OldCollectionDescriptor(this, type, emitDefaultValues, namingConvention); } else if (type.IsArray) { if (type.GetArrayRank() == 1 && !type.GetElementType().IsArray) { // array[] - only single dimension array is supported descriptor = new ArrayDescriptor(this, type, emitDefaultValues, namingConvention); } else { // multi-dimension array to be treated as a 'standard' object descriptor = new NotSupportedObjectDescriptor(this, type, emitDefaultValues, namingConvention); } } else if (NullableDescriptor.IsNullable(type)) { descriptor = new NullableDescriptor(this, type, emitDefaultValues, namingConvention); } else { // standard object (class or value type) descriptor = new ObjectDescriptor(this, type, emitDefaultValues, namingConvention); } return(descriptor); }
/// <inheritdoc /> public virtual void VisitSet(IEnumerable set, SetDescriptor descriptor) { // Make a copy in case VisitCollectionItem mutates something IEnumerator enumerator = set.GetEnumerator(); while (enumerator.MoveNext()) { object item = enumerator.Current; CurrentPath.Push(descriptor, item); VisitSetItem(set, descriptor, item, TypeDescriptorFactory.Find(item?.GetType() ?? descriptor.ElementType)); CurrentPath.Pop(); } }
/// <inheritdoc /> public virtual void VisitSetItem(IEnumerable set, SetDescriptor descriptor, object item, ITypeDescriptor itemDescriptor) { Visit(item, itemDescriptor); }