public static Class getPrimitiveClass(Type clazz, string name) { switch (name) { case "void": return((Class)ReflectionBridge.GetClass(typeof(void))); case "byte": return((Class)ReflectionBridge.GetClass(typeof(sbyte))); case "boolean": return((Class)ReflectionBridge.GetClass(typeof(bool))); case "char": return((Class)ReflectionBridge.GetClass(typeof(char))); case "short": return((Class)ReflectionBridge.GetClass(typeof(short))); case "int": return((Class)ReflectionBridge.GetClass(typeof(int))); case "float": return((Class)ReflectionBridge.GetClass(typeof(float))); case "long": return((Class)ReflectionBridge.GetClass(typeof(long))); case "double": return((Class)ReflectionBridge.GetClass(typeof(double))); default: return(null); } }
public static Class forName0(Type clazz, string classname, bool initialize, ClassLoader loader, Class caller) { Class found; Console.WriteLine(" searching for {0}", classname); if (loader != null) { found = _loadClass[loader](classname, initialize); } else { if (classname == null) { throw new NullReferenceException(nameof(classname)); } if (classname.StartsWith("[")) { classname = classname.TrimStart('['); initialize = false; } if (classname.StartsWith("L") && classname.EndsWith(";")) { classname = classname.Substring(1, classname.Length - 2); } Type t = null; foreach (var type in typeof(Class).Assembly.GetTypes()) { if (type.FullName == classname) { t = type; } if (type.GetCustomAttribute <JavaNameAttribute>()?.Name.Replace('/', '.') == classname) { t = type; } } if (t == null) { throw new ClassNotFoundException(classname); } if (initialize) { RuntimeHelpers.RunClassConstructor(t.TypeHandle); } found = (Class)ReflectionBridge.GetClass(t); } return(found); }
public static Class getSuperclass(Class @this) { var bt = _nativeData[@this].BaseType; if (bt == null) { return(null); } return((Class)ReflectionBridge.GetClass(bt)); }
public void FindInterfaces_CommandTimeoutExceptionHandler_HandlesTimeoutException() { var interfaces = ReflectionBridge.FindInterfaces( typeof(CommandTimeoutExceptionHandler), x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IQueryExceptionHandler <, ,>) ); interfaces.Should().HaveCount(1); var actual = ReflectionBridge.GetGenericArguments(interfaces[0])[2]; actual.Should().Be(typeof(TimeoutException)); }
public int Compare(Type x, Type y) { if (ReflectionBridge.CheckIsAssignable(x, y)) { return(-1); } if (ReflectionBridge.CheckIsAssignable(y, x)) { return(1); } return(0); }
private static Type GetExceptionType(IQueryExceptionHandler <TRequest, TResponse> handler) { var interfaceType = ReflectionBridge .FindInterfaces( handler.GetType(), x => ReflectionBridge.CheckIsGeneric(x) && x.GetGenericTypeDefinition() == typeof(IQueryExceptionHandler <, ,>) ) .SingleOrDefault(); return(interfaceType is null ? typeof(Exception) : ReflectionBridge.GetGenericArguments(interfaceType)[2]); }
public static Class getCallerClass(Type reflection, int offset) { var st = new StackTrace(); var gcc = 0; while (st.GetFrame(gcc).GetMethod()?.DeclaringType?.FullName != TypeName) { gcc++; } // gcc is now index of lava.lang.Class::getCallerClass return((Class)ReflectionBridge.GetClass(st.GetFrame(gcc + offset).GetMethod().DeclaringType)); }
/// <summary> /// Executes the current component in the pipeline. /// </summary> /// <param name="request">The request to <see cref="IMediator"/>.</param> /// <param name="nextAsync">The request handler.</param> /// <param name="cancellationToken"> /// A cancellation token that should be used to cancel the work. /// </param> /// <returns>A task that represents a pipeline step.</returns> public async Task <TResult> ExecuteAsync( TQuery request, Func <Task <TResult> > nextAsync, CancellationToken cancellationToken) { try { return(await nextAsync().ConfigureAwait(false)); } catch (Exception exception) { var exceptionType = exception.GetType(); var context = new ExceptionHandlerContext <TResult>(); while (!context.Handled || exceptionType != typeof(object)) { foreach (var wrapper in _wrappers) { if (!wrapper.Skip) { if (wrapper.CanHandle(exceptionType)) { await wrapper.Handler .HandleAsync(request, exception, context, cancellationToken) .ConfigureAwait(false); if (context.Handled) { return(context.Result); } wrapper.Skip = true; } } } exceptionType = ReflectionBridge.GetBaseType(exceptionType); } throw; } }
internal static Method CreateMethod(MethodInfo m) { var modifiers = 0; if (m.IsPublic) { modifiers |= Modifier.PUBLIC; } else if (m.IsPrivate) { modifiers |= Modifier.PRIVATE; } else if (m.IsFamilyOrAssembly) { modifiers |= Modifier.PROTECTED; } if (!m.IsVirtual) { modifiers |= Modifier.FINAL; } if (m.IsStatic) { modifiers |= Modifier.STATIC; } return(new Method( (Class)ReflectionBridge.GetClass(m.DeclaringType), string.Intern(m.Name), m.GetParameters().Select(p => (Class)ReflectionBridge.GetClass(p.ParameterType)).ToArray(), (Class)ReflectionBridge.GetClass(m.ReturnType), new Class[0], modifiers, 0, "", new sbyte[0], new sbyte[0], new sbyte[0] ) { __nativeData = m }); }
internal static Field CreateField(FieldInfo f) { var modifiers = 0; if (f.IsStatic) { modifiers |= Modifier.STATIC; } if (f.IsPublic) { modifiers |= Modifier.PUBLIC; } else if (f.IsPrivate) { modifiers |= Modifier.PRIVATE; } else if (f.IsFamilyOrAssembly) { modifiers |= Modifier.PROTECTED; } if (f.GetRequiredCustomModifiers().Any(t => t == typeof(IsVolatile))) { modifiers |= Modifier.VOLATILE; } return(new Field( (Class)ReflectionBridge.GetClass(f.DeclaringType), string.Intern(f.Name), (Class)ReflectionBridge.GetClass(f.FieldType), modifiers, 0, string.Empty, new sbyte[0]) { __nativeData = f }); }
public static Class findBootstrapClass(ClassLoader @this, string name) { return((Class)ReflectionBridge.GetClass(Type.GetType(name + ", JavaNet.Runtime"))); }
public void GetGenericArguments(Type type, int index, Type target) { ReflectionBridge.GetGenericArguments(type)[index].Should().Be(target); }
public void GetBaseType(Type type, Type parent) { ReflectionBridge.GetBaseType(type).Should().Be(parent); }
public void CheckIsGeneric(Type type, bool isGeneric) { ReflectionBridge.CheckIsGeneric(type).Should().Be(isGeneric); }
public void CheckIsAssignable(Type from, Type to, bool isAssignable) { ReflectionBridge.CheckIsAssignable(from, to).Should().Be(isAssignable); }
public bool CanHandle(Type exceptionType) { return(ReflectionBridge.CheckIsAssignable(ExceptionType, exceptionType)); }