/// <summary> /// Initialize a new instance of the <see cref="ObjectReference"/> class using a data object. /// </summary> /// <remarks>This constructor should be used when the given <see cref="objectValue"/> has no mode node yet existing.</remarks> /// <param name="objectValue">A data object to reference. Can be null.</param> /// <param name="objectType">The type of data object to reference.</param> /// <param name="index">The index of this reference in its parent reference, if it is a <see cref="ReferenceEnumerable"/>.</param> internal ObjectReference(object objectValue, Type objectType, object index) { Reference.CheckReferenceCreationSafeGuard(); if (objectType == null) { throw new ArgumentNullException(nameof(objectType)); } if (objectValue != null && !objectType.IsInstanceOfType(objectValue)) { throw new ArgumentException(@"The given type does not match the given object.", nameof(objectValue)); } orphanObject = objectValue; Type = objectType; Index = index; }
internal ReferenceEnumerable(IEnumerable enumerable, Type enumerableType) { Reference.CheckReferenceCreationSafeGuard(); ObjectValue = enumerable; if (enumerableType.HasInterface(typeof(IDictionary <,>))) { ElementType = enumerableType.GetInterface(typeof(IDictionary <,>)).GetGenericArguments()[1]; } else if (enumerableType.HasInterface(typeof(IEnumerable <>))) { ElementType = enumerableType.GetInterface(typeof(IEnumerable <>)).GetGenericArguments()[0]; } else { ElementType = typeof(object); } }
internal ReferenceEnumerable(IEnumerable enumerable, Type enumerableType, object index) { Reference.CheckReferenceCreationSafeGuard(); Type = enumerableType; Index = index; if (enumerableType.HasInterface(typeof(IDictionary <,>))) { elementType = enumerableType.GetInterface(typeof(IDictionary <,>)).GetGenericArguments()[1]; } else if (enumerableType.HasInterface(typeof(IEnumerable <>))) { elementType = enumerableType.GetInterface(typeof(IEnumerable <>)).GetGenericArguments()[0]; } else { elementType = typeof(object); } Refresh(enumerable); }