在非标准C#.NET项目中使用脚本#code与字符串操作 [英] Using Script# code with string operations in standart C# .NET project

查看:123
本文介绍了在非标准C#.NET项目中使用脚本#code与字符串操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我添加的脚本#参考我的非标准的控制台应用程序。从那以后,我试图调用从那里的一些方法,但越来越以下错误:

我想这发生在下面一行:

 字符串[]行= s.Split(';');
 

我的假设是,通常的的mscorlib 库有没有方法公共字符串[]斯普利特(字符分隔),但公共字符串[]斯普利特(PARAMS的char []分隔)

是否有可能写入有效code这样的字符串操作都为一个脚本#项目和一个非标准C#.NET项目?由于这个问题我必须写重复的code这两个项目以最小的区别。

PS 我试图用assemblty绑定重定向,如这太问题的讨论,但它并没有帮助我。

解决方案

我找到了解决办法!

我的行动顺序:

  1. 在创建任何脚本#类的字符串分裂分割方法。

  2. 定义你的.NET项目的条件编译符号的 DOTNET

  3. 添加链接文件分割方法,从脚本到#.NET项目并添加为纽带另一个必要的相关文件。

公共静态字符串[]斯普利特(字符串str,字符串分隔符) {     字符串[]结果; #如果DOTNET     结果= str.Split(新的String [] {}分隔符,System.StringSplitOptions.None); #其他     结果= str.Split(分隔符); #ENDIF     返回结果; }

在适当的code将选择依赖于DOTNET符号,它仅仅在.NET项目。其他类似的方法,不仅与弦,可以改写以相同的方式

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:

I suppose it happened on the following line:

string[] lines = s.Split(';');

My assumption is that usual mscorlib library has not method public string[] Split(char separator), but has public string[] Split(params char[] separator)

Is it possible to write valid code with such string operations both for a Script# project and for a standart C# .NET project? Due to this problem I have to write duplicate code for both projects with minimal difference.

P.S. I tried to use assemblty binding redirects, as discussed in this SO question, but it didn't help me.

解决方案

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.

这篇关于在非标准C#.NET项目中使用脚本#code与字符串操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆