private PluginMethod CreateFrom(System.Reflection.MethodInfo method, string logicalname)
            {
                var result = new PluginMethod();

                result.method = method;
                var parameters = method.GetParameters().ToArray();

                result.Parameters = new TypeCache[parameters.Length];
                var ix = 0;

                foreach (var parameter in parameters)
                {
                    result.Parameters[ix] = TypeCache.ForParameter(parameter, logicalname);
                    ix++;
                }

                var sortAttr = method.GetCustomAttributes(Types.SortAttribute, false).SingleOrDefault();

                if (sortAttr != null)
                {
                    result.Sort = (int)sortAttr.GetType().GetProperty("Value").GetValue(sortAttr);
                }
                else
                {
                    result.Sort = 1;
                }
                return(result);
            }
Beispiel #2
0
        private static HttpResponse ExecuteAction(HttpRequest request, Type controllerType, System.Reflection.MethodInfo action, IServiceCollection serviceCollection)
        {
            var instance = serviceCollection.CreateInstance(controllerType) as Controller;

            instance.Request = request;
            var arguments  = new List <object>();
            var parameters = action.GetParameters();

            foreach (var parameter in parameters)
            {
                var httpParameterValue = GetParameterFromRequest(request, parameter.Name);
                var parameterValue     = Convert.ChangeType(httpParameterValue, parameter.ParameterType);
                if (parameterValue == null && parameter.ParameterType != typeof(string) && parameter.ParameterType != typeof(int?))
                {
                    // complex type
                    parameterValue = Activator.CreateInstance(parameter.ParameterType);
                    var properties = parameter.ParameterType.GetProperties();
                    foreach (var property in properties)
                    {
                        var propertyHttParameterValue = GetParameterFromRequest(request, property.Name);
                        var propertyParameterValue    = Convert.ChangeType(propertyHttParameterValue, property.PropertyType);
                        property.SetValue(parameterValue, propertyParameterValue);
                    }
                }

                arguments.Add(parameterValue);
            }


            var response = action.Invoke(instance, arguments.ToArray()) as HttpResponse;

            return(response);
        }
        /// <summary> Determines the name of the accessor method on the underlying object for a given
        /// conformance class. It is used to determine whether underlying accessors require
        /// a "rep" parameter.
        /// </summary>
        /// <param name="className">the Class name
        /// </param>
        /// <param name="accessorName">the Accessor ame
        /// </param>
        public UnderlyingAccessor(System.String className, System.String accessorName)
        {
            acceptsRep = false;

            track(className);

            try
            {
                System.Type c = getHapiModelClass(className);
                theAccessor = makeName(c, accessorName);

                //children of groups & segments repeat; children of composites don't
                if (typeof(Group).IsAssignableFrom(c))
                {
                    acceptsRep = true;
                }
                else if (typeof(Segment).IsAssignableFrom(c))
                {
                    System.Reflection.MethodInfo m = getMethod(c, accessorName);
                    if (m == null || m.GetParameters().Length == 1)
                    {
                        acceptsRep = true;
                    }
                }
            }
            catch (System.Exception e)
            {
                SupportClass.WriteStackTrace(e, Console.Error);
                throw new ConformanceError("Underlying class/method " + className + "." + accessorName + "() can not be found. The complete HAPI API must be installed prior to using this system.");
            }
        }
 private StringBuilder GetArgsString(System.Reflection.MethodInfo method)
 {
     var sb = new StringBuilder();
     foreach (var arg in method.GetParameters())
         sb.Append(string.Format("{0} {1}, ", arg.ParameterType.Name, arg.Name));
     return sb;
 }
Beispiel #5
0
        //------------------------------------------------------------------------------
        public static List <String> GetValidSubstitutionMethods(MonoScript script)
        {
            List <String> methods = new List <String>();

            Type scriptClass = script.GetClass();

            if (scriptClass == null)
            {
                return(methods);
            }

            System.Reflection.MethodInfo[] rawMethods = scriptClass.GetMethods(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);

            for (int i = 0; i < rawMethods.Length; ++i)
            {
                System.Reflection.MethodInfo info = rawMethods[i];

                if (info.GetParameters().Length > 0 || info.ReturnType != typeof(String))
                {
                    continue;
                }

                methods.Add(info.Name);
            }

            return(methods);
        }
Beispiel #6
0
        /// <summary>
        /// Simpler get float property from Vive.
        /// </summary>
        /// <param name="prop">The property to get</param>
        /// <param name="error">An error reference</param>
        /// <returns>The float value</returns>
        internal static float GetFloatProperty(string property, ref int error)
        {
            var hmd = SteamVRHMD;

            if (hmd == null)
            {
                error = 5; // TrackedProp_InvalidDevice = 5
                return(0);
            }

            if (_steamGetFloatTrackedDevicePropertyMethod == null)
            {
                _steamGetFloatTrackedDevicePropertyMethod = hmd.GetType().GetMethod("GetFloatTrackedDeviceProperty");

                if (_steamGetFloatTrackedDevicePropertyMethod == null)
                {
                    error = 5; // TrackedProp_InvalidDevice = 5
                    return(0);
                }
            }

            var propertyType = _steamGetFloatTrackedDevicePropertyMethod.GetParameters()[1].ParameterType;
            var arguments    = new object[] { (uint)0, Enum.Parse(propertyType, property), error };
            var result       = (float)_steamGetFloatTrackedDevicePropertyMethod.Invoke(hmd, arguments);

            if (error != 0)
            {
                return(0);
            }

            return(result);
        }
Beispiel #7
0
        private void AddTestCaseAttributeTests(System.Reflection.MethodInfo methodInfo)
        {
            var methodParams = methodInfo.GetParameters();

            if (methodParams.Length == 0)
            {
                throw new System.InvalidOperationException("Test method has no parameters");
            }

            foreach (var testCaseAttr in Reflection.GetAttributes(methodInfo, typeof(NUnit.Framework.TestCaseAttribute), false))
            {
                string category = Reflection.GetProperty(testCaseAttr, "Category") as string;
                if (category != null)
                {
                    Categories.Add(category);
                }

                System.Collections.IList categories = Reflection.GetProperty(testCaseAttr, "Categories") as System.Collections.IList;
                if (categories != null)
                {
                    Categories.AddRange(categories.Cast <string>());
                }

                var methodArgs = Reflection.GetProperty(testCaseAttr, "Arguments") as object[];
                TestCases.Add(new TestCase(methodInfo, methodArgs));
            }
        }
Beispiel #8
0
        /// <summary>
        /// 根据方法命调用方法
        /// </summary>
        /// <param name="name">方法名</param>
        /// <param name="_paramer">string方法参数</param>
        /// <returns></returns>
        private string CallbackByFunctionName(string name, string _paramer)
        {
            Type T    = null;
            var  func = new Functions();

            if (func != null)
            {
                var tool = new Functions();
                T = tool.GetType();
            }
            else
            {
                var tool = new Tool.Functions();
                T = tool.GetType();
            }
            //反射出类的实例
            object o = Activator.CreateInstance(T);

            //System.Reflection.PropertyInfo pi = T.GetProperty("xq_id");
            //获得方法信息
            System.Reflection.MethodInfo mi = T.GetMethod(name);
            var param = mi.GetParameters();

            Object[] obj    = new Object[] { _paramer };
            string   strTmp = mi.Invoke(o, obj).ToString();

            return(strTmp);
        }
Beispiel #9
0
        /// <summary>
        /// Javascript 側で指定した Javascript.Array 型の引数配列を
        /// object[] 型に変換します。
        /// </summary>
        /// <param name="m">最終的に呼び出したいメソッド</param>
        /// <param name="arguments">呼び出しに用いる Javascript.Array の引数配列</param>
        /// <returns>実際に呼び出しに用いる事の出来る引数配列 object[]</returns>
        /// <remarks>
        /// 実装: ConvertParamsCompat の処理と似た処理を行うので、
        /// ConvertParamsCompat の際に System.Type[] を作って置くのも手。
        /// </remarks>
        public static object[] ConvertParams(System.Reflection.MethodInfo m, JavaScript.Array arguments)
        {
            System.Reflection.ParameterInfo[] arrParam = m.GetParameters();
            int iM = arrParam.Length;

            object[] r = new object[iM];
            for (int i = 0; i < iM; i++)
            {
                if (i + 1 == iM && arrParam[iM - 1].GetCustomAttributes(typeof(System.ParamArrayAttribute), false).Length > 0)
                {
                    //変換
                    System.Collections.ArrayList list = new System.Collections.ArrayList();
                    System.Type t = arrParam[iM - 1].ParameterType.GetElementType();
                    for (; i < arguments.length; i++)
                    {
                        list.Add(arguments[i].Convert(t));
                    }

                    r[iM - 1] = list.ToArray(t);
                }
                else
                {
                    r[i] = arguments[i].Convert(arrParam[i].ParameterType);
                }
            }
            return(r);
        }
Beispiel #10
0
        private object Invoke(object excute, string action, DataTable data, string tableName)
        {
            System.Reflection.MethodInfo methodInfo = null;
            try
            {
                methodInfo = excute.GetType().GetMethod(action);
                object[] parameters;
                var      paraTypes = methodInfo.GetParameters();
                parameters = new object[paraTypes.Length];

                if (parameters.Length == 0)
                {
                }
                else
                {
                    parameters[0] = data;
                    parameters[1] = tableName;
                }
                var result = methodInfo.Invoke(excute, parameters);
                return(result);
            }
            catch (Exception ex)
            {
                return("[]");
            }
        }
Beispiel #11
0
        public static MethodName FromMethodInfo(System.Reflection.MethodInfo method)
        {
            if (method == null)
            {
                throw new ArgumentNullException(nameof(method));
            }

            if (method.IsGenericMethod && !method.IsGenericMethodDefinition)
            {
                return(new GenericInstanceMethodName(
                           FromMethodInfo(method.GetGenericMethodDefinition()),
                           method.GetGenericArguments().Select(TypeName.FromType).ToArray()
                           ));
            }

            var generics = DefaultMethodName.SetGenericMangle(0);

            if (method.IsGenericMethodDefinition)
            {
                generics = DefaultMethodName.SetGenericArguments(method.GetGenericArguments());
            }

            var result = new DefaultMethodName(
                TypeName.FromType(method.DeclaringType),
                method.Name,
                generics,
                DefaultMethodName.SetParameters(method.GetParameters()),
                DefaultMethodName.SetReturnType(TypeName.FromType(method.ReturnType))
                );

            return(result);
        }
Beispiel #12
0
            public object Invoke(object target, System.Reflection.MethodInfo method, object[] parameters)
            {
                var arguments = method.GetParameters();
                var argCount  = arguments.Length;
                var args      = new DictionaryWrapper();

                for (int i = 0; i < argCount; i++)
                {
                    args[arguments[i].Name] = parameters[i];
                }


                var operationName = method.Name;

                var req = ServiceRequest.Create(ServiceName, operationName, args);

                if (ServiceDispatcherName.HasValue())
                {
                    req.Arguments.Add(ServiceDispatcher.ServiceDispatcherParameterName, ServiceDispatcherName);
                }

                var resp = ServiceDispatcher.Dispatch(req);

                if (resp.Success)
                {
                    return(resp.Result);
                }
                else
                {
                    throw resp.Exception;
                }
            }
Beispiel #13
0
        /// <summary>
        /// Checks the callback signature of a method is compatible for callbacks
        /// </summary>
        public static bool CheckCallbackSignature(System.Reflection.MethodInfo mi, bool requirePublicVisibility)
        {
            System.Reflection.ParameterInfo[] pi = mi.GetParameters();

            return(pi.Length == 2 && pi[0].ParameterType == typeof(ScriptExecutionContext) &&
                   pi[1].ParameterType == typeof(CallbackArguments) && mi.ReturnType == typeof(DynValue) && (requirePublicVisibility || mi.IsPublic));
        }
Beispiel #14
0
        /// <summary>
        /// 指定したイベントに追加出来るようなイベントハンドラを作成し、<see cref="System.Delegate"/> として返します。
        /// イベントハンドラ内では、 this.OnChanged(sender) を呼び出します。
        /// </summary>
        /// <param name="e">追加先のイベントの情報を指定します。</param>
        /// <returns>作成したメソッドを参照するデリゲートを返します。</returns>
        protected System.Delegate CreateEventHandler(System.Reflection.EventInfo e)
        {
            System.Reflection.MethodInfo minfo = e.EventHandlerType.GetMethod("Invoke");
            if (minfo.ReturnType != typeof(void))
            {
                throw new System.ApplicationException(@"このイベントには返値を指定しなければ為りません。
現在、返値を必要とするイベントへのフックには対応していません。");
            }

            //-- 引数の型
            System.Reflection.ParameterInfo[] infoParams = minfo.GetParameters();
            System.Type[] tParams = new System.Type[infoParams.Length];
            tParams[0] = typeof(PropertyAccessor);           // this-parameter
            for (int i = 0; i < infoParams.Length; i++)
            {
                tParams[i + 1] = infoParams[i].ParameterType;
            }

            Emit.DynamicMethod eh = new Emit.DynamicMethod("eh", null, tParams, typeof(PropertyAccessor));

            System.Reflection.Emit.ILGenerator ilgen = eh.GetILGenerator();
            ilgen.Emit(Emit.OpCodes.Ldarg_0);                                                   // load this
            ilgen.Emit(infoParams.Length == 0?Emit.OpCodes.Ldnull:Emit.OpCodes.Ldarg_1);        // load sender (引数がない場合には null)
            ilgen.Emit(Emit.OpCodes.Callvirt, typeof(PropertyAccessor).GetMethod("OnChanged")); // this.OnChnaged(sender);
            ilgen.Emit(Emit.OpCodes.Ret);                                                       // return;

            return(eh.CreateDelegate(e.EventHandlerType, this));
        }
        private void appendMethod(TypeBuilder typeBuilder, System.Reflection.MethodInfo methodInfo)
        {
            var requaredParameters = methodInfo.GetParameters();
            var methodParameters   = new SystemCF.Type[requaredParameters.Length];
            var inputParameters    = new System.Collections.Generic.List <Type>();
            var outputParameters   = new System.Collections.Generic.List <Type>();

            for (int parameterIndex = 0; parameterIndex < requaredParameters.Length; parameterIndex++)
            {
                var requaredParameterInfo = requaredParameters[parameterIndex];

                if ((requaredParameterInfo.Attributes & System.Reflection.ParameterAttributes.Out) > 0)
                {
                    var type = requaredParameterInfo.ParameterType.GetElementType();
                    outputParameters.Add(type);
                    methodParameters[parameterIndex] = ((SystemCF.Type)type).MakeByRefType();
                }
                else
                {
                    inputParameters.Add(requaredParameterInfo.ParameterType);
                    methodParameters[parameterIndex] = requaredParameterInfo.ParameterType;
                }
            }

            var methodBuilder = typeBuilder.DefineMethod(methodInfo.Name,
                                                         System.Reflection.MethodAttributes.Public, methodInfo.ReturnType, methodParameters);

            appendMethodBody(methodBuilder, inputParameters, outputParameters);

            typeBuilder.DefineMethodOverride(methodBuilder, methodInfo);
        }
Beispiel #16
0
        public void SetName(System.Reflection.MethodInfo method)
        {
            Name = "Method: ";
            if (method.ReturnType.IsGenericType)
            {
                Name += $"{PrettyName(method.ReturnType)} {method.Name}(";
            }
            else
            {
                Name += $"{method.ReturnType.Name} {method.Name}(";
            }

            foreach (var param in method.GetParameters())
            {
                if (param.ParameterType.IsGenericType)
                {
                    Name += $"{PrettyName(param.ParameterType)}";
                }
                else
                {
                    Name += param.Name;
                }
            }
            Name += ")";
        }
Beispiel #17
0
        public override bool IsValidForRequest(ControllerContext controllerContext, System.Reflection.MethodInfo methodInfo)
        {
            var methodParams = methodInfo.GetParameters();

            foreach (var parameterInfo in methodParams)
            {
                if (parameterInfo.HasDefaultValue)
                {
                    continue;
                }

                var paramType = parameterInfo.ParameterType;
                if (!IsSimpleType(paramType))
                {
                    continue;
                }

                var value = controllerContext.Controller.ValueProvider.GetValue(parameterInfo.Name);
                if (value == null || value.AttemptedValue == null || !CanParse(value.AttemptedValue, paramType, value.Culture))
                {
                    return(false);
                }
            }

            return(true);
        }
        /// <param name="theParentClass">
        /// </param>
        /// <param name="theChildName">must be an integer when the parent is a composite
        /// </param>
        /// <returns> the accessor name on the given parent that returns the the given child
        /// </returns>
        private System.String makeName(System.Type theParentClass, System.String theChildName)
        {
            System.String result = null;
            if (typeof(Group).IsAssignableFrom(theParentClass))
            {
                result = "get(\"" + guessCompName(theChildName) + "\", rep)";
            }
            else if (typeof(Segment).IsAssignableFrom(theParentClass))
            {
                System.Reflection.MethodInfo method = getMethod(theParentClass, theChildName);

                //use number if we can't find the field by name (could be site-defined)
                if (method == null)
                {
                    result = "getField(" + ourCurrentChild + ", rep)";
                }
                else
                {
                    result = (method.GetParameters().Length == 1)?theChildName + "( rep )":theChildName + "()";
                }
            }
            else if (typeof(Composite).IsAssignableFrom(theParentClass))
            {
                result = "get(" + theChildName + ")";
            }
            else
            {
                throw new ConformanceError("The parent class " + theParentClass + " is not recognized as a Group, Segment, or Composite");
            }
            return(result);
        }
        public void ArrayListHoldsObjects()
        {
            ArrayList list = new ArrayList();

            System.Reflection.MethodInfo method = list.GetType().GetMethod("Add");
            Assert.Equal(typeof(System.Object), method.GetParameters()[0].ParameterType);
        }
        public override CodeWriter BeginOverride(System.Reflection.MethodInfo method)
        {
            WriteLine();
            if (method.IsPublic)
            {
                Write("public override ");
            }
            else if (method.IsFamilyOrAssembly)
            {
                Write("protected internal override ");
            }
            else if (method.IsFamily)
            {
                Write("protected override ");
            }
            else if (method.IsAssembly)
            {
                Write("internal override ");
            }
            Write(method.ReturnType).Write(" ").Write(method.Name).Write("(");
            var args = method.GetParameters();

            for (int i = 0; i < args.Length; i++)
            {
                if (i != 0)
                {
                    Write(", ");
                }
                Write(args[0].ParameterType).Write(" ").Write(Escape(args[0].Name));
            }
            Write(")");
            return(Indent());
        }
Beispiel #21
0
        /// <summary>
        /// <see cref="ContainerControlTreeNode"/> を保持する
        /// TreeNode を取得し、<see cref="SettingTreePanel"/> に登録します。
        /// </summary>
        /// <param name="mem">
        /// <see cref="ContainerControlTreeNode"/> を保持する
        /// TreeNode を取得する為のメソッドを指定します。
        /// </param>
        protected override void Read(System.Reflection.MemberInfo mem)
        {
            if (mem.MemberType != System.Reflection.MemberTypes.Method)
            {
                afh.Application.Log.AfhOut.WriteLine("    error:メソッドを指定して下さい");
                return;
            }
            System.Reflection.MethodInfo m = (System.Reflection.MethodInfo)mem;
            if (m.GetParameters().Length > 0)
            {
                afh.Application.Log.AfhOut.WriteLine("    error:指定したメソッドはパラメータを要求します。パラメータを要求しないメソッドを指定して下さい。");
                return;
            }
            object result = m.Invoke(null, new object[] {});

            if (result is System.Windows.Forms.TreeNode)
            {
                Plugin.SettingTreePanel.AddTreeNode((System.Windows.Forms.TreeNode)result);
            }
            else if (result is System.Windows.Forms.TreeNode[])
            {
                Plugin.SettingTreePanel.AddTreeNode((System.Windows.Forms.TreeNode[])result);
            }
            else
            {
                afh.Application.Log.AfhOut.WriteLine(ERROR_CAST);
            }
        }
Beispiel #22
0
        /// <summary>
        /// 处理输出参数
        /// </summary>
        /// <param name="resMsg"></param>
        /// <param name="method"></param>
        private void HandleEnd(ResponseMessage resMsg, System.Reflection.MethodInfo method)
        {
            if (resMsg.IsError)
            {
                return;
            }

            var invokeData = resMsg.Value as InvokeData;
            var pis        = method.GetParameters().Where(p => p.ParameterType.IsByRef);

            if (pis.Count() > 0)
            {
                if (!string.IsNullOrEmpty(invokeData.OutParameters))
                {
                    var jobject = JObject.Parse(invokeData.OutParameters);
                    if (jobject != null && jobject.Count > 0)
                    {
                        foreach (var p in pis)
                        {
                            var type       = GetElementType(p.ParameterType);
                            var jsonString = jobject[p.Name].ToString(Formatting.Indented);
                            var obj        = SerializationManager.DeserializeJson(type, jsonString);
                            resMsg.Parameters[p.Name] = obj;
                        }
                    }
                }
            }

            //处理返回值
            var returnType = GetElementType(method.ReturnType);

            resMsg.Value = SerializationManager.DeserializeJson(returnType, invokeData.Value);
        }
        private static System.Type CreateDelegateType(System.Reflection.MethodInfo methodInfo)
        {
            System.Func <System.Type[], System.Type> getType;
            bool isAction = methodInfo.ReturnType.Equals((typeof(void)));

            System.Reflection.ParameterInfo[] pis = methodInfo.GetParameters();
            System.Type[] types = new System.Type[pis.Length + (isAction ? 0: 1)];

            for (int i = 0; i < pis.Length; ++i)
            {
                types[i] = pis[i].ParameterType;
            }

            if (isAction)
            {
                getType = System.Linq.Expressions.Expression.GetActionType;
            }
            else
            {
                getType           = System.Linq.Expressions.Expression.GetFuncType;
                types[pis.Length] = methodInfo.ReturnType;
            }

            return(getType(types));
        }
Beispiel #24
0
        /// <summary>
        /// Javascript 側で指定した引数と、指定した MethodInfo の引数の適合性を判定します
        /// </summary>
        /// <returns>
        /// 計算した適合性を返します。
        /// 引数を変換する事が出来ない場合には float.NegativeInfinity を返します
        /// </returns>
        /// <remarks>
        /// TODO: params 修飾子が付いている時、一つも要素を指定しない場合の動作を実装
        /// 1. arrParam.Length>arguments.length の判定だけでは不十分
        /// 2. 点数を低くする(params の付いた引数だけ除いた別のオーバーロードの可能性)
        /// </remarks>
        public static float ConvertParamsCompat(System.Reflection.MethodInfo m, JavaScript.Array arguments)
        {
            System.Reflection.ParameterInfo[] arrParam = m.GetParameters();
            if (arrParam.Length == 0)
            {
                return(0);
            }
            if (arrParam.Length > arguments.length)
            {
                return(float.NegativeInfinity);
            }
            int   iM = arrParam.Length;
            float r  = 0;

            for (int i = 0; i < iM; i++)
            {
                //CHECK>OK: params の入った関数を識別出来るか実際に確認する事
                if (i + 1 == iM && arrParam[iM - 1].GetCustomAttributes(typeof(System.ParamArrayAttribute), false).Length > 0)
                {
                    System.Type t = arrParam[iM - 1].ParameterType.GetElementType();
                    iM = arguments.length;
                    for (; i < iM; i++)
                    {
                        r += arguments[i].ConvertCompat(t);
                    }
                    break;
                }
                r += arguments[i].ConvertCompat(arrParam[i].ParameterType);
            }
            return(r + (arguments.length - iM) * COMPAT_OVERPARAM);
        }
Beispiel #25
0
 public void GetNParams(int lMethodNum, ref int plParams)
 {
     //Здесь 1С получает количество параметров у метода (процедуры или функции)
     if (lMethodNum >= 0 && lMethodNum < meths.Length)
     {
         try
         {
             System.Reflection.MethodInfo mi = this.GetType().GetMethod(meths[lMethodNum].name_en);
             if (mi == null)
             {
                 logFile.Add(String.Format("Метод {0} не найден", meths[lMethodNum].name_en));
                 plParams = 0;
             }
             else
             {
                 plParams = mi.GetParameters().Length;
                 logFile.Add(String.Format("Возвращаем количество параметров для метода \"{0}\" ({1}): {2}", meths[lMethodNum].name_ru, lMethodNum, plParams));
             }
         }
         catch (Exception e)
         {
             logFile.Add(String.Format("Ошибка при получении списка параметров для метода \"{0}\" ({1})\", парам:{2} ", meths[lMethodNum].name_ru, e.Message, plParams), true);
         }
     }
 }
Beispiel #26
0
        public static bool MatchGenericParameters(this System.Reflection.MethodInfo m, Type[] genericArguments, Type returnType, params Type[] parameters)
        {
            var param = m.GetParameters();

            if (param.Length == parameters.Length)
            {
                var args = m.GetGenericArguments();
                if (args.Length != genericArguments.Length)
                {
                    return(false);
                }
                if (args.MatchGenericParameters(m.ReturnType, returnType, genericArguments))
                {
                    for (int i = 0; i < param.Length; i++)
                    {
                        if (!args.MatchGenericParameters(param[i].ParameterType, parameters[i], genericArguments))
                        {
                            return(false);
                        }
                    }

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Beispiel #27
0
        protected void OutputArgs(System.Text.StringBuilder sb,
                                  System.Reflection.MemberInfo mi,
                                  System.Boolean isTupled)
        {
            System.Reflection.MethodInfo m = (System.Reflection.MethodInfo)mi;
            Int32 i = 0;

            System.Reflection.ParameterInfo[] ps = m.GetParameters();

            if (isTupled && ps.Length != 1)
            {
                sb.Append("(");
            }

            for (i = 0; i < ps.Length; i++)
            {
                sb.AppendFormat("arg{0}", i);
                if (isTupled && (i + 1) < ps.Length)
                {
                    sb.Append(",");
                }
                else
                {
                    if (!isTupled)
                    {
                        sb.Append(" ");
                    }
                }
            }
            if (isTupled && ps.Length != 1)
            {
                sb.Append(")");
            }
        }
 private void cboMethodName_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (txtServiceURL.Text.Trim().Length > 0 && cboEndPoint.Text.Trim().Length > 0 && cboMethodName.Text.Trim().Length > 0)
     {
         try
         {
             lblParameterCount.Text      = "Parameters info...";
             lblParameterCount.BackColor = SystemColors.Control;
             if (factoryCache == null || factoryCache.WsdlUri != txtServiceURL.Text)
             {
                 factoryCache = new DynamicProxyFactory(txtServiceURL.Text);
             }
             ServiceEndpoint endpoint = (from ep in factoryCache.Endpoints
                                         where ep.Name.ToLower() == cboEndPoint.Text.ToLower()
                                         select ep).FirstOrDefault();
             if (endpoint != null)
             {
                 string               contractName = endpoint.Contract.Name;
                 DynamicProxy         proxy        = factoryCache.CreateProxy(contractName);
                 Type                 proxyType    = proxy.ProxyType;
                 OperationDescription operation    = (from OperationDescription m in endpoint.Contract.Operations
                                                      where m.Name.ToLower() == cboMethodName.Text.ToLower()
                                                      select m).FirstOrDefault();
                 if (operation != null)
                 {
                     System.Reflection.MethodInfo method = (from m in proxyType.GetMethods()
                                                            where m.Name == operation.Name
                                                            select m).FirstOrDefault();
                     lblParameterCount.Text = "Count: " + method.GetParameters().Length.ToString() + " ";
                     foreach (System.Reflection.ParameterInfo parInfo in method.GetParameters())
                     {
                         if (!parInfo.ParameterType.IsValueType && parInfo.ParameterType.Name != "String" && parInfo.ParameterType.Name != "Object")
                         {
                             lblParameterCount.BackColor = Color.Yellow;
                         }
                         lblParameterCount.Text += string.Format("<{0}:{1}>,", parInfo.Name, parInfo.ParameterType.Name);
                     }
                     lblParameterCount.Text = lblParameterCount.Text.TrimEnd(',');
                 }
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
 public override bool ProcessParams(MethodInfo method, int paramNum, IFacetHolder holder) {
     ParameterInfo parameter = method.GetParameters()[paramNum];
     Attribute attribute = parameter.GetCustomAttributeByReflection<DescriptionAttribute>();
     if (attribute == null) {
         attribute = parameter.GetCustomAttributeByReflection<DescribedAsAttribute>();
     }
     return FacetUtils.AddFacet(Create(attribute, holder));
 }
        private string GetMethodCallString(System.Reflection.MethodInfo methodInfo)
        {
            var pars       = methodInfo.GetParameters();
            var parameters = pars.Select(x => this.TypeToString(x.ParameterType) + " " + x.Name).ToArray();
            var parsStr    = string.Join(", ", parameters);

            return("<color=#3af>" + methodInfo.Name.ToLower() + "</color>(" + parsStr + ")" + this.GetHelpString(this.GetSpace(4) + methodInfo.Name.ToLower() + "(" + parsStr + ")", methodInfo));
        }
Beispiel #31
0
        public MethodInfo(System.Reflection.MethodInfo methodInfo, XElement xmlDocs)
        {
            Method = methodInfo;

            Parameters = methodInfo.GetParameters().ToList();

            GenericArguments = methodInfo.GetGenericArguments().ToList();
        }
Beispiel #32
0
 public override bool ProcessParams(MethodInfo method, int paramNum, IFacetHolder holder) {
     ParameterInfo parameter = method.GetParameters()[paramNum];
     if (TypeUtils.IsString(parameter.ParameterType)) {
         var attribute = parameter.GetCustomAttributeByReflection<MultiLineAttribute>();
         return FacetUtils.AddFacet(Create(attribute, holder));
     }
     return false;
 }
Beispiel #33
0
        public override bool ProcessParams(MethodInfo method, int paramNum, IFacetHolder holder) {
            ParameterInfo parameter = method.GetParameters()[paramNum];
            if (TypeUtils.IsString(parameter.ParameterType)) {
                Attribute attribute = parameter.GetCustomAttributeByReflection<RegularExpressionAttribute>();
                if (attribute == null) {
                    attribute = parameter.GetCustomAttributeByReflection<RegExAttribute>();
                }

                return FacetUtils.AddFacet(Create(attribute, holder));
            }
            return false;
        }
Beispiel #34
0
 public override bool ProcessParams(MethodInfo method, int paramNum, IFacetHolder holder) {
     ParameterInfo parameter = method.GetParameters()[paramNum];
     if ((parameter.ParameterType.IsPrimitive || TypeUtils.IsEnum(parameter.ParameterType))) {
         if (method.GetCustomAttribute<OptionallyAttribute>() != null) {
             Log.Warn("Ignoring Optionally annotation on primitive parameter " + paramNum + " on " + method.ReflectedType + "." +
                      method.Name);
         }
         return false;
     }
     var attribute = parameter.GetCustomAttributeByReflection<OptionallyAttribute>();
     return FacetUtils.AddFacet(Create(attribute, holder));
 }
        public override bool Process(MethodInfo actionMethod, IMethodRemover methodRemover, IFacetHolder action) {
            string capitalizedName = NameUtils.CapitalizeName(actionMethod.Name);

            Type type = actionMethod.DeclaringType;
            var facets = new List<IFacet>();
            INakedObjectSpecification onType = Reflector.LoadSpecification(type);
            INakedObjectSpecification returnSpec = Reflector.LoadSpecification(actionMethod.ReturnType);

            RemoveMethod(methodRemover, actionMethod);
            facets.Add(new ActionInvocationFacetViaMethod(actionMethod, onType, returnSpec, action));

            MethodType methodType = actionMethod.IsStatic ? MethodType.Class : MethodType.Object;
            Type[] paramTypes = actionMethod.GetParameters().Select(p => p.ParameterType).ToArray();
            FindAndRemoveValidMethod(facets, methodRemover, type, methodType, capitalizedName, paramTypes, action);

            DefaultNamedFacet(facets, capitalizedName, action); // must be called after the checkForXxxPrefix methods

            AddHideForSessionFacetNone(facets, action);
            AddDisableForSessionFacetNone(facets, action);
            FindDefaultHideMethod(facets, methodRemover, type, methodType, "ActionDefault", paramTypes, action);
            FindAndRemoveHideMethod(facets, methodRemover, type, methodType, capitalizedName, paramTypes, action);
            FindDefaultDisableMethod(facets, methodRemover, type, methodType, "ActionDefault", paramTypes, action);
            FindAndRemoveDisableMethod(facets, methodRemover, type, methodType, capitalizedName, paramTypes, action);

            if (action is DotNetNakedObjectActionPeer) {
                var nakedObjectActionPeer = (DotNetNakedObjectActionPeer) action;
                // Process the action's parameters names, descriptions and optional
                // an alternative design would be to have another facet factory processing just ActionParameter, and have it remove these
                // supporting methods.  However, the FacetFactory API doesn't allow for methods of the class to be removed while processing
                // action parameters, only while processing Methods (ie actions)
                INakedObjectActionParamPeer[] actionParameters = nakedObjectActionPeer.Parameters;
                string[] paramNames = actionMethod.GetParameters().Select(p => p.Name).ToArray();

                FindAndRemoveParametersAutoCompleteMethod(methodRemover, type, capitalizedName, paramTypes, actionParameters);
                FindAndRemoveParametersChoicesMethod(methodRemover, type, capitalizedName, paramTypes, paramNames, actionParameters);
                FindAndRemoveParametersDefaultsMethod(methodRemover, type, capitalizedName, paramTypes, paramNames, actionParameters);
                FindAndRemoveParametersValidateMethod(methodRemover, type, capitalizedName, paramTypes, paramNames, actionParameters);
            }
            return FacetUtils.AddFacets(facets);
        }
        public void DisplayMethodProperties(System.Reflection.MethodInfo Method)
        {
            ThisMethod = Method;

            // Show the method name

            Label2.Text = ThisMethod.Name;

            // Show the calling convention

            Label4.Text = "0x" + ThisMethod.CallingConvention.ToString("x") +
                " = " + ThisMethod.CallingConvention.ToString();

            // Show the method's standard attributes

            Label6.Text = "0x" + ThisMethod.Attributes.ToString("x") +
                " = " + ThisMethod.Attributes.ToString();

            // Show the return type

            Label8.Text = ThisMethod.ReturnType.FullName;

            // Show the parameters

            foreach (System.Reflection.ParameterInfo parm in ThisMethod.GetParameters())
            {
                //ListBox1.Items.Add(parm.Name + " as " + parm.ParameterType.FullName);
                ListBox1.Items.Add(parm.ParameterType);//changed because I need the type later
            }

            // Show the custom attributes

            foreach (object attr in ThisMethod.GetCustomAttributes(true))
            {
                ListBox2.Items.Add(attr);
            }
        }
        public override bool ProcessParams(MethodInfo method, int paramNum, IFacetHolder holder) {
            ParameterInfo parameter = method.GetParameters()[paramNum];
            var attribute = parameter.GetCustomAttributeByReflection<EnumDataTypeAttribute>();

            return AddEnumFacet(attribute, holder, parameter.ParameterType);
        }
        public override bool ProcessParams(MethodInfo method, int paramNum, IFacetHolder holder) {
            ParameterInfo parameter = method.GetParameters()[paramNum];
            IFacet facet = null;

            if (parameter.ParameterType.IsGenericType && (parameter.ParameterType.GetGenericTypeDefinition() == typeof (Nullable<>))) {
                facet = new NullableFacetAlways(holder);
            }

            return FacetUtils.AddFacet(facet);
        }
 public override bool ProcessParams(MethodInfo method, int paramNum, IFacetHolder holder) {
     ParameterInfo parameter = method.GetParameters()[paramNum];
     Attribute attribute = parameter.GetCustomAttributeByReflection<DisplayNameAttribute>() ?? (Attribute) parameter.GetCustomAttributeByReflection<NamedAttribute>();
     return FacetUtils.AddFacet(Create(attribute, holder));
 }
 public override bool ProcessParams(MethodInfo method, int paramNum, IFacetHolder holder) {
     ParameterInfo parameter = method.GetParameters()[paramNum];
     var attribute = parameter.GetCustomAttributeByReflection<PresentationHintAttribute>();
     return FacetUtils.AddFacet(Create(attribute, holder));
 }
Beispiel #41
0
 public override bool ProcessParams(MethodInfo method, int paramNum, IFacetHolder holder) {
     ParameterInfo parameter = method.GetParameters()[paramNum];
     bool isDate = parameter.ParameterType.IsAssignableFrom(typeof (DateTime));
     var range = parameter.GetCustomAttributeByReflection<RangeAttribute>();
     return FacetUtils.AddFacet(Create(range, isDate, holder));
 }