Beispiel #1
0
        public IQueryable <T> Get <T>() where T : class
        {
            // get component instance
            var registration = Catalog.GetRegistration(ComponentName);
            var instance     = Catalog.GetComponentInstance(registration);
            var type         = instance.GetType();

            // create generic method
            var genericMethodInfo = type.GetMethod(MethodInfo.Name, new[] { typeof(T) }, new Type[0]);

            if (genericMethodInfo == null)
            {
                var methodSignature  = MessageHelpers.GetMethodSignature(type, MethodInfo.Name, new Type[0]);
                var exceptionMessage = String.Format(LanguageResource.MissingMethodException_MethodNotFound, methodSignature);
                throw new MissingMethodException(exceptionMessage);
            }

            // invoke Get<T> method and return IQueryable<T>
            object result = genericMethodInfo.Invoke(instance, new object[0]);

            if (result is IQueryable <T> )
            {
                return(result as IQueryable <T>);
            }
            if (result is IEnumerable <T> )
            {
                return((result as IEnumerable <T>).AsQueryable());
            }
            return(null);
        }
Beispiel #2
0
 /// <summary>
 /// Obtains metadata of the invoked method via reflection.
 /// </summary>
 /// <param name="details">Invocation details</param>
 private void Invoke_ObtainMethodMetadata(InvocationDetails details)
 {
     if (!details.FindMethodInfo())
     {
         var methodSignature  = MessageHelpers.GetMethodSignature(details.Type, details.MethodName, details.ParamTypes);
         var exceptionMessage = String.Format(LanguageResource.MissingMethodException_MethodNotFound, methodSignature);
         throw new MissingMethodException(exceptionMessage);
     }
 }
Beispiel #3
0
        public IQueryable <T> Get <T>() where T : class
        {
            if (querySession == null)
            {
                throw new InvalidOperationException("Session is not started. ZyanMethodQueryHandler requires that StartSession method is called before Get<T>.");
            }

            // get component instance created by
            var instance     = querySession.Instance;
            var instanceType = instance.GetType();

            // create generic method
            var genericMethodInfo = instanceType.GetMethod(MethodInfo.Name, new[] { typeof(T) }, new Type[0]);

            if (genericMethodInfo == null)
            {
                var methodSignature  = MessageHelpers.GetMethodSignature(instanceType, MethodInfo.Name, new Type[0]);
                var exceptionMessage = string.Format(LanguageResource.MissingMethodException_MethodNotFound, methodSignature);
                throw new MissingMethodException(exceptionMessage);
            }

            // invoke Get<T> method and return IQueryable<T>
            object result = genericMethodInfo.Invoke(instance, new object[0]);

            if (result is IQueryable <T> )
            {
                return(result as IQueryable <T>);
            }

            if (result is IEnumerable <T> )
            {
                return((result as IEnumerable <T>).AsQueryable());
            }

            return(null);
        }