Using Script# code with string operations in standart C# .NET project

后端 未结 2 1141
一个人的身影
一个人的身影 2021-01-20 10:34

I added reference of Script# to my standart console application. After that I was trying to invoke some method from there but was getting the following error:

2条回答
  •  一个人的身影
    2021-01-20 11:09

    I found solution!

    My sequence of actions:

    1. Create Split method of string splitting in any Script# class.

    2. Define conditional compilation symbol DOTNET in your .NET project.

    3. Add As Link file with Split method from Script# to .NET project and also add as link another necessary dependent files.

    public static string[] Split(string str, string separator)
    {
        string[] result;
    #if DOTNET
        result = str.Split(new string[] { separator }, System.StringSplitOptions.None);
    #else
        result = str.Split(separator);
    #endif
        return result;
    }
    

    After that appropriate code will be selected dependent on DOTNET symbol, which defined only in .NET project. Other similar methods, not only with strings, can be rewritten in the same way.

提交回复
热议问题