Beispiel #1
0
        internal static IReference CreateReference(object objectValue, Type objectType, Index index, bool isMember)
        {
            if (objectValue != null && !objectType.IsInstanceOfType(objectValue)) throw new ArgumentException(@"objectValue type does not match objectType", nameof(objectValue));

            if (!CreatingReference.IsValueCreated)
                CreatingReference.Value = 0;

            ++CreatingReference.Value;

            IReference reference;
            var isCollection = HasCollectionReference(objectValue?.GetType() ?? objectType);
            if (isMember)
            {
                reference = new ObjectReference(objectValue, objectType, index);
            }
            else
            {
                if (objectValue != null && isCollection && index.IsEmpty)
                {
                    reference = new ReferenceEnumerable((IEnumerable)objectValue, objectType);
                }
                else
                {
                    reference = null;
                }
            }

            --CreatingReference.Value;

            return reference;
        }
Beispiel #2
0
 public void Dispose()
 {
     obj = null;
     indexEnumerator.Dispose();
 }
Beispiel #3
0
 public ReferenceEnumerator([NotNull] ReferenceEnumerable obj)
 {
     this.obj        = obj;
     indexEnumerator = obj.Indices.GetEnumerator();
 }