About MeSoftware EngineerSax Player  
 
Start Page
 
Resume
Journal
Galleries
Extras
 
Links
Guestbook
Contact Me
 

Journal Listing

There are 2899 total entries.

There are 943 total comments.


Ongoing list of C#/.NET complaints and suggestions
Computers/Internet/Gaming
Undated

Language
  • Enums need to be inheritable from other enums. This is especially useful in P/Invoke situations like window style flags and kernel object permission flags, where there is a base set of common flags to which subsystem components then add their own.
  • Enum.ToString( ) needs to not spit out garbage for [Flags]-marked enums that contain bitflags not listed in the enum. Instead it should isolate the hex values of those unrecognized flags, especially to aid the developer.
  • IntPtr and UIntPtr need to be first class datatypes with full arithmetic operator, enum, and const literal support (requiring checked/unchecked to prevent runtime overflow exceptions, when applicable), and also intptr/uintptr reserved words if possible.
  • Overloaded typecast operators need to accept interfaces as input and output.
  • Compound short-circuiting Boolean operators &&= and ||= would be useful for breaking apart complex boolean expressions and then stepping through them with the debugger.
  • A compound null-coalescing operator ??= would be very useful for patching up null references.
  • We need to be able to overload the compound arithmetic assignment operators in order to alter the original object without creating an unnecessary intermediate. Add( ) calls on collections everywhere get annoying.
  • We need a params IEnumerable<T> for method definitions so that we’re not forced to convert to arrays whenever passing other collections into the method.
  • There is no obvious technical inhibitor to allowing structs to inherit from other structs. This would help prevent redundancy and the risk of mistakes in areas like P/Invoke that add features based on appended fields.
  • The ? : needs to use base operand validity on the L value type.
  • Why must a ref or out parameter always be an assignable value no matter what? What is logically wrong with ref'ing an anonymous new instance when we don't care what the return value is?
  • Why can't pointers be used as generic type parameters? You already know they are the same size as an IntPtr.
  • Why can't unsafe code be used in iterator methods? The "it might take too long to execute" reason is completely unacceptable considering that every framework function that performs I/O would be impossible without unsafe or P/Invoke code.
Marshaling
  • The marshaler uses MarshalAsAttribute.SizeParamIndex to know how many array elements to write, but why isn't it intelligent enough to know how many elements to read back when set to a ref or out parameter? This would help stop runaway marshaling on top of dead trailing buffer space.
  • The marshaler needs to be able to marshal struct array fields as LPArray, exactly as it is currently capable of doing with method parameters. Instead of SizeParamIndex to know how many elements to marshal, it should use a new SizeFieldIndex. Or use the existing one for both.
  • Why can’t arrays of SafeHandles be marshaled at all? For interface methods like IEnumIDList.Next( ) which return arrays of pointers that need to be freed after use, this means we are in danger of the very thing SafeHandle was created to prevent, which is a ThreadAbortException occuring after a function returns but before its value gets assigned to a class with a finalizer. We can mask the implementation detail with an extension method but the vulnerability remains.
  • For the same reason, we need to be able to marshal struct SafeHandle fields. Not every resource handle is marshaled as a ref or out method parameter.
  • StructLayout(LayoutKind.Explicit) is almost useless when dealing with IntPtr fields that can change the value depending on bitness. Either we need LayoutKind.ExplicitRelative or FieldOffset needs a second parameter that says whether the field position is absolute, relative to the start of the previous field, or relative to the first byte following the previous field.
  • Passing a null SafeHandle into a function that expects a null is entirely reasonable, but the marshaler throws an error. There needs to be a mechanism for allowing something like this, such as requiring a static property called Invalid to be substituted by the marshaler instead of the null. Or an attribute for the SafeHandle that specifies the IntPtr null substitution value.
  • Why do COM interfaces declared in .NET require the inclusion of every inherited interface function up the chain to IUnknown or IDispatch, instead of observing the language-specified inheritance? This is absolutely grotesque, and completely defeats polymorphism.
Framework
  • Why doesn't Guid have a copy constructor?
  • Enumerable needs FirstOrNull, LastOrNull, and SingleOrNull restrained to IEnumerables of structs, that returns a null Nullable<T> when the element wasn't actually found.

1 comment

© 2012 JAS Powered by ASP.NET, C#, and SQL Server
Please sign the guestbook!
Follow JoshASchaeffer on Twitter