CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 14 of 14

Thread: Dynamic casting

Threaded View

  1. #6
    Join Date
    Apr 2004
    Location
    England, Europe
    Posts
    2,492

    Re: Dynamic casting

    Quote Originally Posted by Mr. Tomaszek
    What I'm trying to acheive is that when type of that property will change I would not have to change the code that is used for setting them.
    Ok, I think I understand now.

    Can you make use of the using keyword in this case?

    Code:
    using MyGeneralType = MySpecificType;
    
    class MySpecificType
    {
    }
    
    class MyOtherType
    {
    }
    
    //...
    
    class Xyz
    {
        public MyGeneralType TheProperty { /* ... */ }
    
        void f(object o)
        {
            this.TheProperty = (MyGeneralType)o;
        }
    }
    That way you can change what type MyGeneralType actually is by modifying just one line:

    Code:
    using MyGeneralType = MyOtherType;
    Last edited by Zaccheus; January 13th, 2007 at 02:50 PM.
    My hobby projects:
    www.rclsoftware.org.uk

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured