I need some help in order to use overrides function for 'Equals' and 'GetHashCode' into a structure:

You'll find enclose a sample function which erase the block references when they have the same name, layer, insertion point, scale and angle.

For that function, i wanted to use a dictionary in order to compare those parameters by using a structure.This function seems to work this way, however, i think i have to improve the structure i used in order to compare the parameters exactly with the criteria i want but i don't really understand how to use override for the GetHashCode function.

By my side, I'd rather use a 'Duplicate' extension method for the BlockReference class than create a strucure.

Here's an example, in a 'BlockRefExtension' static class, two extension methods are defined to be used in the DeletDuplicatedBlockRef() method (a Test command is provided to test the code).The GetName() method is needed while targeting the 2007 SDK (and perhaps 2088 and 2009) which doesn't contains the BlockReference.Name property.

EDIT: the DeletDuplicatedBlockRef() method returns the number of erased blocksEDIT: removed some unusefull statements

- I've tried to translate your code (the first one) in VB, but i didn't succeed in implementing the extension, it's said that extension must be into modules. I haven't really understood what is extension?

- Also, I found that by using dictionaries and checking if the key already exists, it's more "simple" since we don't have to "play" with counters and we get through the list of blocks only once. Actually, i previously used the lisp program "deldup_blk" (maybe yours?), so i wanted to implement in a way the same algorithm. However, i find that's not very clean if we don't know with which precision the comparison are done, but tell me if i'm wrong because sometimes i really don't understand how lisp can works without knowing the type of the variables.

- For your second solution, I've some difficulties to read F# code, but it seems that you don't have counters and that you manipulate list instead?(Also, do you know some good code converters for this language? I open a new topic for this question)

1_ Extension methods is a way to add methods to an already existing class. Usually they're compiled in a separate dll so that while this dll is refered by another project, these methods are available the same way as built-in methods.In the upper example, a 'Duplicate' method is added to the BlockReference class, it's visible in the intellisense as:Bool BlockReference.Duplicate(BlockReference br).But as I said, you can define a private method inside your class: Bool Duplicate(BlockReference br1, BlockReference br2).

2_ I really think the structure/GetHashCode... way isn't the simpler one because you have to compare objects with different types (String, Point3d, Double, ...) with tolerances. This way is easy using LISP which allows to build list of different type objects.The 'for' statement used in the upper example is a classical way to run through collections. It's optimised here by removing the duplicated items from the collection at each loop.

3_ As all functional programming languages, F# provides specific higher order functions to deal with collections (List, Array, Seq) which have none equivalent ones in VB or C#.

I think I got something working with the strcture way using a ResultBuffer (the AutoCAD .NET/ObjectARX object which looks the most like a LISP DXF list).

In the following example:The ParamBlockDoubled are stored in a List<ParamBlockDoubled>, there's no need to use a Dictionary as the items Value (objectId) are never used. DoubleToErase is defined as a List<BlockReference> because it avoid to open them twice from their ObjectId.It still uses the BlockTable -> BlockTableRecord _> GetReferenceIds route which avoid to run through the whole database.