Extend System.Decimal?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Fredrik Melin

    Extend System.Decimal?

    Is there any way to extend or write a own "System.Decimal "?

    In the doc its declared as
    <Serializable >
    Public Structure Decimal
    Implements IFormattable, IComparable, IConvertibleBut how do you get the
    functionallity that you can do Dim x as mydecimalx = 100Is that possible or
    can only microsoft do stuff like that?RegardsFre drik


  • Cor Ligthert

    #2
    Re: Extend System.Decimal?

    Frederik,

    In my opinion can you create any class that holds the methods to do what you
    want, however not create a new value type.

    Cor



    Comment

    • Jay B. Harlow [MVP - Outlook]

      #3
      Re: Extend System.Decimal?

      Fredrick,
      Decimal, being a Structure is a value type, which work the same as
      NotInheritable Classes. Which means you cannot extend it directly, you would
      need to encapsulate it and delegate all the methods to the real structure.

      You can define MyDecimalX as a Structure and it will have all the value type
      semantics of the Decimal type. However you will need to wait for VS.NET 2005
      (aka Whidbey, due out in 2005) to support overloaded operators. Which will
      allow your MyDecimalX to support +, -, /, * and other operators that you
      define.

      For a quick intro to overloading operators in VB.NET see:



      Overloading operator CType allows you to define custom conversions, for
      example Decimal to & from MyDecimalX, allowing:

      Dim d As Decimal
      Dim md As MyDecimalX
      d = md ' Widening Operator CType
      md = CType(d, MyDecimalX) ' Narrowing Operator CType

      FYI: VB.NET 2002 & 2003 knows about the Decimal type, so we are currently
      able to use its overloaded operators directly. With VB.NET 2005 we will be
      able to make use of the overloaded operators on any type in the Framework,
      such as DateTime & TimeSpan.

      Hope this helps
      Jay

      "Fredrik Melin" <mel@n.o.spam.d acsa.net.remove .as.needed> wrote in message
      news:exS9H$xiEH A.2448@TK2MSFTN GP12.phx.gbl...[color=blue]
      > Is there any way to extend or write a own "System.Decimal "?
      >
      > In the doc its declared as
      > <Serializable >
      > Public Structure Decimal
      > Implements IFormattable, IComparable, IConvertibleBut how do you get[/color]
      the[color=blue]
      > functionallity that you can do Dim x as mydecimalx = 100Is that possible[/color]
      or[color=blue]
      > can only microsoft do stuff like that?RegardsFre drik
      >
      >[/color]


      Comment

      Working...