4 using System.Collections;
6 using SiliconStudio.Core;
8 namespace SiliconStudio.Quantum.References
10 internal static class Reference
12 private static int creatingReference;
17 internal static readonly
object NotInCollection =
new object();
19 internal static IReference CreateReference(
object objectValue, Type objectType,
object index)
21 if (objectValue != null && !objectType.IsInstanceOfType(objectValue))
throw new ArgumentException(
@"objectValue type does not match objectType",
"objectValue");
28 if (enumerableValue != null && index == NotInCollection)
30 reference =
new ReferenceEnumerable(enumerableValue, objectType, index);
34 reference =
new ObjectReference(objectValue, objectType, index);
42 internal static Type GetReferenceType(
object objectValue,
object index)
44 return objectValue is IEnumerable && index == NotInCollection ? typeof(ReferenceEnumerable) : typeof(ObjectReference);
47 internal static void CheckReferenceCreationSafeGuard()
49 if (creatingReference == 0)
throw new InvalidOperationException(
"A reference can only be constructed with the method Reference.CreateReference");
The type of the serialized type will be passed as a generic arguments of the serializer. Example: serializer of A becomes instantiated as Serializer{A}.