Store a C # Object in an AutoCAD XRecord Object

I am trying to find a way that I can store a C # class in an AutoCAD object as an XRecord. For example, I have the following class:

public class ExampleClass { private int x; private int y; public ExampleClass(int x, int y) { this.x = x; this.y = y; } #region Getters and Setters } 

and I create an instance of it:

 ExampleClass objToStoreInXRecord = new ExampleClass(3, 5); 

What is the best way to save this in an AutoCAD object (like a line in the drawing) of XRecord so that I can do something like this:

 ExampleClass objRecoveredFromXRecord = GetXRecordFromEntity(Entity e) 

Where GetXRecordFromEntity (Entity e) is a helper method that I can write that takes an object e, gets an XRecord of a previously saved object and returns it.

I do not have very good help on how XRecord works and how XRecord relates to a Named Object Oriented AutoCAD (NOD) object. I saw implementations where the object to be stored in XRecord is serialized with binary formatting and the serialized data is stored in the XRecord object, but I'm looking for a better way.

+6
source share
2 answers

Serialize the object and add it to xrecord. It works great.

0
source

Using .NET Serialize is not supported in AutoCAD, that is, other applications will not understand that ...

Check out this discussion on the Autodesk forum to clarify what I mean. In addition, there is a small piece of code.

http://forums.autodesk.com/t5/net/binary-serialization-to-xrecord/td-p/5601969

0
source

Source: https://habr.com/ru/post/985145/


All Articles