public override object ExtractObject(Type requestedType) { object buildObject; if (IsReferedMultipleTimes) { if (ParentGraph.TryGetObjectForRefId(RefId, out buildObject)) { return(buildObject); } } Type typeToBuild = requestedType; if (ObjectType != null) { Type myType = ObjectType.ClassType; if (requestedType != null && !requestedType.IsAssignableFrom(myType)) { throw new Exception("Unable to build object. Requested on type but data has another type"); //TODO better exception } typeToBuild = myType; } if (typeToBuild == null) { throw new Exception("Missing type information. Unable to build object"); //TODO better exception } if (typeToBuild.IsAbstract || typeToBuild.IsInterface) { throw new Exception("Cannot create a direct instance of a abstract or interface"); //TODO better exception } if (typeToBuild.IsArray || typeToBuild.IsPrimitiveData()) { //Handle Boxed Value Types IGraphNode boxedValue = m_fields[DEFAULT_BOXED_VALUE_FIELD_NAME]; return(boxedValue.RebuildObject(typeToBuild)); } buildObject = SerializationServices.GetUninitializedObject(typeToBuild); ParentGraph.LinkObjectToNode(this, buildObject); var surrogate = SerializationServices.GetDefaultSerializationSurrogate(typeToBuild); surrogate.SetObjectData(ref buildObject, this); return(buildObject); }