我知道这可能不值得,但仅仅出于教育目的,我想知道是否有办法将自己的关键词注入.NET语言.
例如,我认为在C#中使用C++ asm关键字是件好事.
请记住,我不是在讨论如何实现asm关键字,而是将关键字添加到C#的一般方法.
我想象的代码:
asm{
mov ax,1
add ax,4
}
Run Code Online (Sandbox Code Playgroud)
有没有办法实现这一目标?
涵盖实施的答案keyword{ }足以满足这个问题.
有两个项目,一个是C++ CLI,另一个是C#.
C#项目引用了C++ CLI项目.
在C#中我想这样做:
//method signature is somemethod(dynamic data);
somemethod("haaaii");
Run Code Online (Sandbox Code Playgroud)
现在C++ CLI项目中的方法必须处理这个问题.
如何在C++ CLI中声明此方法?
另外如何在C++ CLI中检测数据类型?
我想检测我的输入字符串是否包含Arabic字符.
也许有些代码是这样的:
string str = "?S";
str[0].IsArabicCharacter(); //true
str[1].IsArabicCharacter(); //false
Run Code Online (Sandbox Code Playgroud)
目前正在使用映射,但我想迁移到一些C#内置功能.
ArabicChars = "?????????????????????????????";
string str = "?";
if(ArabicChars.Contains(str[0]) return true; else return false;
Run Code Online (Sandbox Code Playgroud) 有什么区别observer.throw(err)和observer.error(err)?
我正在使用RxJS版本"5.0.0-beta.12"
var innerObservable = new Observable(observer => {
console.log('Inner observable call failed');
observer.error(new Error('Call failed!'));
})
var outerObservable = new Observable(observer => {
innerObservable.subscribe(
data => {
observer.next(data);
observer.onCompleted();
},
err => {
//observer.throw(err); // `console.error` doesn't get called
observer.error(err); //// `console.error` it's called
}
)
});
outerObservable.subscribe(
next => {
console.log('ok!');
}
, err => {
console.error('error');
}
, () => {
console.log('done');
}
);
Run Code Online (Sandbox Code Playgroud) 我试图设置ASP.NET应用程序的Culture和UICulture但没有成功.也在C#Windows应用程序中尝试过.
System.Globalization.CultureInfo a = new System.Globalization.CultureInfo("fa-IR");
a.NumberFormat.DigitSubstitution = System.Globalization.DigitShapes.NativeNational;
string Q = string.Format(a, "{0}", 1234567890); // Output 1234567890 instead of ??????????
Run Code Online (Sandbox Code Playgroud)
我在代码中遗漏了哪些部分?
我们有两个相同的字母'ی'和'ي',第一个作为主要信件在Windows 7之后出现.
回到旧版XP,我们将第二个作为主要版本.
现在,如果一个客户端在Windows XP上,另一个客户端在Windows 7上,我得到的输入被确定为不同.
我也尝试过使用波斯文化而没有成功.
我错过了什么吗?
编辑:不得不改变单词以便更好地理解..现在它们看起来很相似.
foreach (CompareOptions i in Enum.GetValues(new CompareOptions().GetType()).OfType<CompareOptions>())
Console.WriteLine( string.Compare("??????", "??????", new CultureInfo("fa-ir"), i) + "\t : " + i );
Run Code Online (Sandbox Code Playgroud)
产出:
-1 : None
-1 : IgnoreCase
-1 : IgnoreNonSpace
-1 : IgnoreSymbols
-1 : IgnoreKanaType
-1 : IgnoreWidth
1 : OrdinalIgnoreCase
-1 : StringSort
130 : Ordinal
Run Code Online (Sandbox Code Playgroud) 代码:
public class A {
public const int beingSupportedRate = 0;
}
public partial class B : A {
public const int beingSupportedRate = 1;
}
Run Code Online (Sandbox Code Playgroud)
因为性能,我希望它像const int一样明确.将虚拟放在class A变量前面beingSupportedRate会导致编译器错误:
The modifier 'virtual' is not valid for this item
这是我的代码:
private void ModifyMethods()
{
SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(@"
using System;
namespace ToIL
{
public class Class1
{
public void Write()
{
Console.WriteLine(""Hello"");
}
}
}");
string assemblyName = System.IO.Path.GetRandomFileName();
MetadataReference[] references = new MetadataReference[]
{
MetadataReference.CreateFromFile(typeof(object).Assembly.Location),
MetadataReference.CreateFromFile(typeof(Enumerable).Assembly.Location)
};
CSharpCompilation compilation = CSharpCompilation.Create( assemblyName, syntaxTrees: new[] { syntaxTree }, references: references,
options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
Mono.Cecil.AssemblyDefinition asm = null;
using (var ms = new MemoryStream())
{
var emitResult = compilation.Emit(ms);
if (emitResult.Success)
{
ms.Seek(0, SeekOrigin.Begin);
asm = Mono.Cecil.AssemblyDefinition.ReadAssembly(ms);
}
}
var …Run Code Online (Sandbox Code Playgroud) 我正在寻找的伪代码如下所示,但它导致我的浏览器挂起。
索引.ts
findCustomerById(id) {
return new Promise<string>((resolve, reject) => {
resolve("hi");
});
}
getCustomerNameById(id: string) {
return this.findCustomerById(id);
//findCustomerById returns NEW Promise<string>
}
Run Code Online (Sandbox Code Playgroud)
索引.html
<p>Customer: {{ getCustomerNameById('1') | async }} </p>
//this does not show anything
<p>Customer: {{ getCustomerNameById('1') | async | json }} </p>
//this shows null
<p>Customer: {{ getCustomerNameById('1') | json }}</p>
//this shows the following
{
"__zone_symbol__state": true,
"__zone_symbol__value": "hi"
}
Run Code Online (Sandbox Code Playgroud)
这是 Plunker :https ://plnkr.co/edit/pAKtCZo0Uog2GFzlj50c
这是一个例子.
var tobeCasted = 1;
object data = null;
if (whatIsMyType == typeof(int)) {
data = (int)tobeCasted;
}
else if (whatIsMyType == typeof(float)) {
data = (float)tobeCasted;
}
Run Code Online (Sandbox Code Playgroud)
但是,上述代码是手动检测每种数据类型的.我正在寻找一个如下所示的一线通用解决方案:
data = (whatIsMyType)tobeCasted;
Run Code Online (Sandbox Code Playgroud) c# ×8
.net ×6
vb.net ×5
cultureinfo ×2
typescript ×2
angular ×1
asp.net ×1
c++-cli ×1
cil ×1
culture ×1
il ×1
mono.cecil ×1
observable ×1
roslyn ×1
rxjs ×1
visual-c++ ×1