Is it legal to take sealed .NET framework class source and extend it?

Posted by Giedrius on Stack Overflow See other posts from Stack Overflow or by Giedrius
Published on 2012-09-06T09:14:07Z Indexed on 2012/09/06 9:38 UTC
Read the original article Hit count: 200

Filed under:
|
|

To be short, I'm giving very specific example, but I'm interested in general situation. There is a FtpWebRequest class in .NET framework and it is missing some of new FTP operations, like MFCT. It is ok in a sense that this operation is still in draft mode, but it is not ok in a sense, that FtpWebRequest is sealed and there's no other way (at least I don't see it) to extend it with this new operation.
Easiest way to do it would be take FtpWebRequest class source from .NET reference sources and extend it, in such way will be kept all the consistence in naming, implementation, etc.

  1. Question is how much legal it is? I won't sell this class as a product, I can publish my changes on web - nothing to hide here.
  2. If it is not legal, can I take this class source from mono and include in native .net project?
  3. Did you had similar case and how you solved it?

Update: as long as extension method is offered, I'm pasting source from .NET framework which should show that extension methods are not the solution. So there's a property Method, where you can pass FTP command:

 public override string Method {
        get { 
            return m_MethodInfo.Method; 
        }
        set { 
            if (String.IsNullOrEmpty(value)) {
                throw new ArgumentException(SR.GetString(SR.net_ftp_invalid_method_name), "value");
            }
            if (InUse) { 
                throw new InvalidOperationException(SR.GetString(SR.net_reqsubmitted));
            } 
            try { 
                m_MethodInfo = FtpMethodInfo.GetMethodInfo(value);
            } catch (ArgumentException) { 
                throw new ArgumentException(SR.GetString(SR.net_ftp_unsupported_method), "value");
            }
       }
} 

As you can see there FtpMethodInfo.GetMethodInfo(value) call in setter, which basically validates value against internal enum static array.

Update 2: Checked mono implementation and it is not exact replica of native code + it does not implement some of the things.

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET