[英]Add boolean class to array of classes
我有一些用Java编写的代码,想要转换为Xamarin(C#)。 如何用C#编写?
private static final Class<?>[] mSetForegroundSignature = new Class[] { boolean.class };
private static final Class<?>[] mStartForegroundSignature = new Class[] { int.class, Notification.class };
private static final Class<?>[] mStopForegroundSignature = new Class[] { boolean.class };
我不知道如何获取此“ boolean.class”和“ <?>”也不起作用。 因为这样被称为
Method mStartForeground = getClass().getMethod("startForeground", mStartForegroundSignature);
然后为每个喜欢的包装
if (mStartForeground != null) {
mStartForegroundArgs[0] = Integer.valueOf(id);
mStartForegroundArgs[1] = notification;
invokeMethod(mStartForeground, mStartForegroundArgs);
return;
}
在C#中,它称为Type而不是Class。 事物的名称有所不同:
private static readonly Type[] mSetForegroundSignature = new Type[] { typeof(bool) };
相当于Class<T>
的c#是Type
,对于boolean.class
来说是typeof(bool)
-如果您想了解有关c#反射的更多信息,请看一下本教程 。 这是翻译后的代码:
private static readonly Type[] mSetForegroundSignature = new Type[] { typeof(bool) }; private static readonly Type[] mStartForegroundSignature = new Type[] { typeof(int), typeof(Notification) }; private static readonly Type[] mStopForegroundSignature = new Type[] { typeof(bool) };
System.Reflection.MethodInfo mStartForeground = new this.GetType().GetMethod("startForeground", mStartForegroundSignature);
if(mStartForeground != null) { mStartForegroundArgs[0] = Convert.ToInt32(id); mStartForegroundArgs[1] = notification; //invoke via reflection (it may be different to invokeMethod?) mStartForeground.Invoke(instance, mStartForegroundArgs); return; }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.