Author Topic: How do I set attribute values after inserting an external block  (Read 6792 times)

0 Members and 1 Guest are viewing this topic.

kaefer

  • Guest
Re: How do I set attribute values after inserting an external block
« Reply #15 on: June 02, 2013, 02:40:18 PM »
For example creating generic functions for SymbolTables then more specific for each of the Tables derived from SymbolTable,

Funny you should mention that. Since SymbolTableRecord doesn't implement IEnumerable, but its dependents are expected to, we could use this loophole.

Code - vb.net: [Select]
  1.         <ExtensionAttribute()>
  2.         Public Iterator Function GetObjects(Of T As DBObject)(str As SymbolTableRecord) As IEnumerable(Of T)
  3.             For Each objectId As ObjectId In CType(str, IEnumerable)
  4.                 Dim target As T = TryCast(objectId.GetObject(OpenMode.ForRead, False, False), T)
  5.                 If target IsNot Nothing Then
  6.                     Yield target
  7.                 End If
  8.             Next
  9.         End Function

Gasty

  • Newt
  • Posts: 90
Re: How do I set attribute values after inserting an external block
« Reply #16 on: June 02, 2013, 06:39:27 PM »
Hi,

The Yield statement  only exists in VB 11 .NET 4.5.

Gaston Nunez

Jeff H

  • Needs a day job
  • Posts: 6150
Re: How do I set attribute values after inserting an external block
« Reply #17 on: June 04, 2013, 01:29:35 AM »
Hi,

The Yield statement  only exists in VB 11 .NET 4.5.

Gaston Nunez

Also 4.0, 3.5, 3.0 &2.0

For example creating generic functions for SymbolTables then more specific for each of the Tables derived from SymbolTable,

Funny you should mention that. Since SymbolTableRecord doesn't implement IEnumerable, but its dependents are expected to, we could use this loophole.

Code - vb.net: [Select]
  1.         <ExtensionAttribute()>
  2.         Public Iterator Function GetObjects(Of T As DBObject)(str As SymbolTableRecord) As IEnumerable(Of T)
  3.             For Each objectId As ObjectId In CType(str, IEnumerable)
  4.                 Dim target As T = TryCast(objectId.GetObject(OpenMode.ForRead, False, False), T)
  5.                 If target IsNot Nothing Then
  6.                     Yield target
  7.                 End If
  8.             Next
  9.         End Function
BlockTableRecord implements IEnumarable, and that's the only SymbolTableRecord off the top of my head I can think of that is a "container"
 

TheMaster

  • Guest
Re: How do I set attribute values after inserting an external block
« Reply #18 on: June 04, 2013, 02:50:12 PM »

Certain people abhor passing a non-generic sequence to a functon which will produce run-time
errors when fed an argument of the wrong type, like string (IEnumerable of char), when a sequence of ObjectId  is expected. Make it an overload of the specific class.


Yes, I suppose that would be me.  I don't see it as being any different than typing an argument as System.Object, when only certain specific types are applicable. 
« Last Edit: June 05, 2013, 07:05:46 AM by TT »

Jeff H

  • Needs a day job
  • Posts: 6150
Re: How do I set attribute values after inserting an external block
« Reply #19 on: June 04, 2013, 07:12:44 PM »
To be fair and should of mentioned from early post I made
http://www.theswamp.org/index.php?topic=44641.msg499207#msg499207
 
To thank Tony as it was from comments in a example posted by Tony or how I understood what he was saying. Might have misunderstood his intent, but all I remember it threw an error if it was not derived from SymbolTableRecord and advised to create others for each of the different tables.