How to override base classes\structs such as int, string?

LyingOnTheSky

To reduce downvotes: (Skippable at first)

I am aware that this question sounds pointless and\or weird. I am creating JIT that takes C# code compiles it with csc.exe, extracts the IL and parallize it into CUDA, and I want to override some of the things in C#.

How override base things such as int\ string? I tried:

class String { /* In namespace System of course */
    BasicString wrap_to;
    public String( ) {
        wrap_to = new BasicString( 32 ); // capacity
    }
    public String( int Count ) {
        wrap_to = new BasicString( Count );
    }
    public char this[ int index ] {
        get { return wrap_to[ index ]; }
        set {
            if ( wrap_to.Handlers != 1 )
                wrap_to = new BasicString( wrap_to );
            wrap_to[ index ] = value;
        }
    }
    ...
}
... // not in namespace System now
class Test {
    public static void f(string s) { }
}

But when I tried:

Test.f( new string( ) );

It error'd Cannot implicitly convert type 'System.String' to 'string'. I tried moving my System.String to just string in the global scope and it error'd on the class itself. Any ideas how? I think somehow it could help if I can compile my .cs files without that mscorlib.dll, but I can't find a way to do it.

Even a way to reach to csc.exe source code may help. (This is critical.)

Jeppe Stig Nielsen

Yes, you will have to not reference mscorlib.dll. Otherwise there will be two System.String classes, and clearly the predefined (C# Specification given) type string cannot be both of them.

See /nostdlib C# compiler option. The page also describes how to do it with a setting in the Visual Studio IDE.

You need to write really many other required types (or copy-paste them) when you do not refer mscorlib.dll!

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How to override a base class constructor in Javascript

分類Dev

How to override a virtual base class property with a derived class property

分類Dev

How to convert string to int in bash?

分類Dev

What happens to String[] from and int [] to when I override newView/bindView in SimpleCursorAdapter

分類Dev

How to override base classes' virtual functions that have identical names in multiple inheritance?

分類Dev

How can I convert a std::string to int?

分類Dev

How can I convert a std::string to int?

分類Dev

How to convert string array to int array in scala

分類Dev

How to count string occurrences in another string in base R?

分類Dev

In OCaml using Base, how do you construct a set with elements of type `int * int`?

分類Dev

tup :: [String]-> [(Int、Int)]

分類Dev

Pythonのint(string、base)のエレガントな逆関数

分類Dev

How to override a function in a package?

分類Dev

NodeJS: How to decode base64 encoded string back to binary?

分類Dev

How can I convert an image into a Base64 string?

分類Dev

how to decode base64 string to NSString in ios?

分類Dev

How we get image type from a base64_string

分類Dev

How to get the int64 size of an image as a string?

分類Dev

How do int-to-string casts work in Go?

分類Dev

How to implement the Hashable Protocol in Swift for an Int array (a custom string struct)

分類Dev

How do i convert an int retrieved from a database to string

分類Dev

How to apply flatMap to list of tuples (Int,String) in Scala?

分類Dev

How to display a message when a string is input instead of an int?

分類Dev

C/C++ How to convert back int to string (a word)?

分類Dev

How do convert an enum int value to a string in ionic template

分類Dev

Node JS, How to properly store Base64 String in JSON string?

分類Dev

Make overflow¹, or “How to override a target?”

分類Dev

How to override route in a plugin nopcommerce

分類Dev

how to mock a class and override a method

Related 関連記事

  1. 1

    How to override a base class constructor in Javascript

  2. 2

    How to override a virtual base class property with a derived class property

  3. 3

    How to convert string to int in bash?

  4. 4

    What happens to String[] from and int [] to when I override newView/bindView in SimpleCursorAdapter

  5. 5

    How to override base classes' virtual functions that have identical names in multiple inheritance?

  6. 6

    How can I convert a std::string to int?

  7. 7

    How can I convert a std::string to int?

  8. 8

    How to convert string array to int array in scala

  9. 9

    How to count string occurrences in another string in base R?

  10. 10

    In OCaml using Base, how do you construct a set with elements of type `int * int`?

  11. 11

    tup :: [String]-> [(Int、Int)]

  12. 12

    Pythonのint(string、base)のエレガントな逆関数

  13. 13

    How to override a function in a package?

  14. 14

    NodeJS: How to decode base64 encoded string back to binary?

  15. 15

    How can I convert an image into a Base64 string?

  16. 16

    how to decode base64 string to NSString in ios?

  17. 17

    How we get image type from a base64_string

  18. 18

    How to get the int64 size of an image as a string?

  19. 19

    How do int-to-string casts work in Go?

  20. 20

    How to implement the Hashable Protocol in Swift for an Int array (a custom string struct)

  21. 21

    How do i convert an int retrieved from a database to string

  22. 22

    How to apply flatMap to list of tuples (Int,String) in Scala?

  23. 23

    How to display a message when a string is input instead of an int?

  24. 24

    C/C++ How to convert back int to string (a word)?

  25. 25

    How do convert an enum int value to a string in ionic template

  26. 26

    Node JS, How to properly store Base64 String in JSON string?

  27. 27

    Make overflow¹, or “How to override a target?”

  28. 28

    How to override route in a plugin nopcommerce

  29. 29

    how to mock a class and override a method

ホットタグ

アーカイブ