0 Replies - 599 Views - Last Post: 17 February 2012 - 04:08 PM Rate Topic: -----

#1 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2250
  • View blog
  • Posts: 9,432
  • Joined: 29-May 08

Inheritance Issues leads to Code Bodgery

Posted 17 February 2012 - 04:08 PM

From one my coding adventures.

The Offending Acts of Bodgery
  • Use of Module
    Cos, I can't write base-class only methods.
  • Use of reflection
    Unable to refer to static method on the Type specified by the Generic Type Parameter.
    VS suggest using Token.Parser which isn't the method in the derived type.


Public Module TokenModule
  Public Function Parse(Of T As Token)(cr As CharReader) As T
    '
    ' Here Be Nasty Reflection Based Bodge Job 
    '
    ' Why? What I want to write. ( Call a static method on the generic (constrianed) type specifier.)
    '
    ' Return T.Parser(cr)
    ' 
    ' Start Bodgery {
    Dim tt As T
    tt = GetType(T).InvokeMember("Parser",
                                    Reflection.BindingFlags.InvokeMethod +
                                    Reflection.BindingFlags.NonPublic +
                                    Reflection.BindingFlags.Static, Nothing, tt, {cr})
    Return tt
    ' } End Bodgery
  End Function

End Module



It would be so much nicer to write if it supported Partial Inheritance.
Spoiler


Is This A Good Question/Topic? 0
  • +

Page 1 of 1