Back to Devexpress

IObjectSpace.GetObject<ObjectType>(ObjectType) Method

expressappframework-devexpress-dot-expressapp-dot-iobjectspace-dot-getobject-1-x28-0-x29.md

latest3.3 KB
Original Source

IObjectSpace.GetObject<ObjectType>(ObjectType) Method

Gets an object similar to the specified object from another Object Space, to the current Object Space. The returned object is cast by the type designated by the specified generic type parameter.

Namespace : DevExpress.ExpressApp

Assembly : DevExpress.ExpressApp.v25.2.dll

NuGet Package : DevExpress.ExpressApp

Declaration

csharp
ObjectType GetObject<ObjectType>(
    ObjectType obj
)
vb
Function GetObject(Of ObjectType)(
    obj As ObjectType
) As ObjectType

Parameters

NameTypeDescription
objObjectType

An object that represents a template object from another Object Space.

|

Type Parameters

Name
ObjectType

Returns

TypeDescription
ObjectType

An object retrieved from the database to the current Object Space and cast by the specified type.

|

Remarks

Use this method to check whether a particular persistent object belongs to the current Object Space. If the object passed as the parameter belongs to another Object Space, this method retrieves the same object from the database via the current Object Space.

When implementing the IObjectSpace interface in the BaseObjectSpace class’s descendant, don’t implement the GetObject<ObjectType> method. It’s implemented in the BaseObjectSpace class. The BaseObjectSpace.GetObject<ObjectType>(ObjectType objectFromDifferentObjectSpace) method calls the BaseObjectSpace.GetObject(Object objectFromDifferentObjectSpace) method, which returns null. The latter method is virtual. So, you should override it in your descendant.

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the GetObject<ObjectType>(ObjectType) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

XAF_Non-Persistent-Objects-Nested-In-Persistent-Objects-Demo/CS/XPO/NonPersistentDemo/NonPersistentDemo.Module/BusinessObjects/SerializationHelper.cs#L23

csharp
acceptor?.Invoke(obj);
var tobj = objectSpace.GetObject(obj);
var aobj = tobj as IAssignable<T>;

See Also

IObjectSpace Interface

IObjectSpace Members

DevExpress.ExpressApp Namespace