public static PropertyInfo GetNativeProperty(Type classType, string name) { PropertyInfo propertyInfo = classType.GetProperties().FirstOrDefault(property => { JsiiPropertyAttribute attribute = property.GetCustomAttribute <JsiiPropertyAttribute>(); return(attribute != null && attribute.Name == name); }); if (propertyInfo == null) { throw new ArgumentNullException($"Class {classType.Name} does not have a property called {name}", nameof(name)); } return(propertyInfo); }
static CallbackResult InvokeGetter(GetRequest request, IReferenceMap referenceMap) { request = request ?? throw new ArgumentNullException(nameof(request)); DeputyBase deputy = referenceMap.GetOrCreateNativeReference(request.ObjectReference); PropertyInfo propertyInfo = ReflectionUtils.GetNativeProperty(deputy.GetType(), request.Property); if (propertyInfo == null) { throw new InvalidOperationException($"Received callback for {deputy.GetType().Name}.{request.Property} getter, but this property does not exist"); } JsiiPropertyAttribute attribute = propertyInfo.GetCustomAttribute <JsiiPropertyAttribute>(); MethodInfo methodInfo = propertyInfo.GetGetMethod(); if (methodInfo == null) { throw new InvalidOperationException($"Received callback for {deputy.GetType().Name}.{request.Property} getter, but this property does not have a getter"); } return(new CallbackResult(attribute, methodInfo.Invoke(deputy, new object[] { }))); }