5 namespace SiliconStudio.Quantum.References
12 private object orphanObject;
21 internal ObjectReference(
object objectValue, Type objectType,
object index)
23 Reference.CheckReferenceCreationSafeGuard();
24 if (objectType == null)
throw new ArgumentNullException(
"objectType");
25 if (objectValue != null && !objectType.IsInstanceOfType(objectValue))
throw new ArgumentException(
@"The given type does not match the given object.",
"objectValue");
26 orphanObject = objectValue;
37 public object ObjectValue {
get {
return TargetNode != null ? TargetNode.Content.Value : orphanObject; } }
40 public Type Type {
get;
private set; }
43 public object Index {
get;
private set; }
48 public Guid TargetGuid {
get;
private set; }
54 TargetGuid = Guid.Empty;
59 public void Refresh(
object newObjectValue)
62 orphanObject = newObjectValue;
71 if (targetNode.
Content.Value != null && !Type.IsInstanceOfType(targetNode.
Content.Value))
throw new ArgumentException(
@"The type of the node content does not match the type of this reference",
"targetNode");
73 if (TargetNode != null || TargetGuid != Guid.Empty)
74 throw new InvalidOperationException(
"TargetNode has already been set.");
75 if (targetNode.
Content.Value != null && !Type.IsInstanceOfType(targetNode.
Content.Value))
76 throw new InvalidOperationException(
"TargetNode type does not match the reference type.");
77 TargetNode = targetNode;
78 TargetGuid = targetNode.Guid;
84 if (TargetNode == null)
86 var guid = modelContainer.GetGuid(ObjectValue, Type);
87 if (TargetGuid != guid)
88 throw new InvalidOperationException(
"The Guid of the object value is different from the current TargetGuid. The given ModelContainer may be different.");
90 if (TargetGuid != Guid.Empty)
92 TargetNode = modelContainer.GetModelNode(TargetGuid);
93 if (TargetNode.Content.Value != null && !Type.IsInstanceOfType(TargetNode.Content.Value))
94 throw new InvalidOperationException(
"The type of the node content does not match the type of this reference");
96 return TargetNode != null;
106 if (otherReference == null)
109 return TargetGuid == otherReference.TargetGuid && TargetNode == otherReference.TargetNode;
116 if (TargetNode != null)
117 result +=
"[HasNode] ";
118 else if (TargetGuid != Guid.Empty)
119 result +=
"[HasGuid] ";
121 result += TargetGuid +
" " + (ObjectValue != null ? ObjectValue.ToString() :
"null");
A container used to store models and resolve references between them.
override string ToString()
IContent Content
Gets the content of the IModelNode.
void Refresh(object newObjectValue)
Refresh this reference and its nested references.
bool UpdateTarget(ModelContainer modelContainer)
Updates the target node of this reference or its nested references from a ModelContainer. A ModelContainer in which the corresponding model node may have been registered.true if the model node was found in the ModelContainer and the target nodes has been updated, false otherwise.
bool Equals(IReference other)
void SetTarget(IModelNode targetNode)
Set the TargetNode and TargetGuid to the given object.
A class representing a reference to another object that has a different model.
The IModelNode interface represents a node in a model object. A model object is represented by a grap...
void Clear()
Clear the reference, making it represent a null or empty object.