当前位置: 首页>>代码示例>>C#>>正文


C# Method.Invoke方法代码示例

本文整理汇总了C#中Method.Invoke方法的典型用法代码示例。如果您正苦于以下问题:C# Method.Invoke方法的具体用法?C# Method.Invoke怎么用?C# Method.Invoke使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Method的用法示例。


在下文中一共展示了Method.Invoke方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Evaluate

        public SGLValue Evaluate()
        {
            String key = identifier;

            // Convert the list of Nodes into Values
            List<SGLValue> paramValues = new List<SGLValue>();
            foreach (SGLNode currentNode in parameters)
            {
                paramValues.Add(currentNode.Evaluate());
            }

            // Test if the type of parameters are the same as the identifiers
            String argString = "";
            for (int i = 0; i < paramValues.Count; i++)
            {
                String argType = paramValues[i].GetVarType();
                key += "-" + argType;
                argString += argType;
                if (i < paramValues.Count - 1)
                {
                    argString += ", ";
                }
            }

            // Test if the method is a static, predefined SGL method and executes it
            try
            {
                SGLValue val = IsStaticMethod(key, paramValues, sb);
                if (val != SGLValue.INVALID) return val;
            }
            catch (SGLCompilerException sce)
            {
                sce.Line = GetLine();
                throw sce;
            }

            if (!methods.ContainsKey(key)) {
                // TODO: Think about convertion from int to float and vice versa
                throw new SGLCompilerException(GetLine(), "method undefined", "the method '" + identifier + "' is undefined or is not applicable for the arguments (" + argString + ")");

            }

            // Method is not static (user-defined) and exists
            Method m = methods[key];

            Method method = new Method(m);

            return method.Invoke(parameters, methods, sb, globalScope);
        }
开发者ID:peppy,项目名称:sgl4cs,代码行数:49,代码来源:MethodCallNode.cs

示例2: CreateInstanceOf

 protected ActionResult CreateInstanceOf(Type modelType, Method method, Func<object, ActionResult> onSuccess, Func<Exception, ActionResult> onException)
 {
     try
     {
         var mapping = ModelMappingManager.MappingFor(modelType);
         using (var repository = mapping.Configuration.Repository())
         {
             var instance = method.Invoke(null);
             repository.Add(instance);
             repository.SaveChanges();
             return onSuccess(instance);
         }
     }
     catch (Exception ex)
     {
         HandleException(ex);
         return onException(ex);
     }
 }
开发者ID:edurdias,项目名称:RunningObjects,代码行数:19,代码来源:ControllerBase.cs

示例3: CreateInstanceOf

 protected ActionResult CreateInstanceOf(Type modelType, Method method, Func<object, ActionResult> onSuccess, Func<Exception, ActionResult> onException)
 {
     using (var context = ModelAssemblies.GetContext(modelType))
     {
         try
         {
             var instance = method.Invoke(null);
             var set = context.Set(modelType);
             set.Add(instance);
             context.SaveChanges();
             return onSuccess(instance);
         }
         catch (Exception ex)
         {
             HandleException(ex);
             return onException(ex);
         }
     }
 }
开发者ID:alexmreis,项目名称:RunningObjects,代码行数:19,代码来源:ControllerBase.cs

示例4: ExecuteMethodOf

        protected ActionResult ExecuteMethodOf(Type modelType, Method model, Func<ActionResult> onSuccess, Func<object, ActionResult> onSuccessWithReturn, Func<Exception, ActionResult> onException, Func<ActionResult> onNotFound, string key = null)
        {
            var mapping = ModelMappingManager.MappingFor(modelType);
            using (var repository = mapping.Configuration.Repository())
            {
                try
                {
                    object @return;
                    if (!model.Descriptor.Method.IsStatic)
                    {
                        var descriptor = new ModelDescriptor(ModelMappingManager.MappingFor(modelType));
                        var instance = repository.Find(GetKeyValues(key, descriptor));

                        if (instance == null)
                            return onNotFound();

                        @return = model.Invoke(instance);
                        instance = repository.Update(instance);
                        repository.SaveChanges();

                        if (@return == instance)
                            @return = null;
                    }
                    else
                        @return = model.Invoke(null);

                    foreach (var parameter in model.Parameters.Where(p => (p.IsModel || p.IsModelCollection) && p.Value != null))
                    {
                        var paramRepository = parameter.UnderliningModel.Descriptor.ModelMapping.Configuration.Repository();
                        if (parameter.IsModelCollection)
                        {

                            //TODO:Update parameters from collection
                            //foreach (var paramItem in parameter.ToModelCollection().Items)
                            //{
                            //    paramRepository.Update(paramItem.Instance);
                            //}
                        }
                        else
                            paramRepository.Update(parameter.Value);
                        paramRepository.SaveChanges();
                    }

                    if (@return != null)
                        return onSuccessWithReturn(@return);
                }
                catch (Exception ex)
                {
                    HandleException(ex);
                    return onException(ex);
                }

                return onSuccess();
            }
        }
开发者ID:edurdias,项目名称:RunningObjects,代码行数:55,代码来源:ControllerBase.cs

示例5: ExecuteMethodOf

        protected ActionResult ExecuteMethodOf(Type modelType, Method model, Func<ActionResult> onSuccess, Func<object, ActionResult> onSuccessWithReturn, Func<Exception, ActionResult> onException, Func<ActionResult> onNotFound, string key = null)
        {
            using (var context = ModelAssemblies.GetContext(modelType))
            {
                try
                {
                    object @return;
                    if (!model.Descriptor.Method.IsStatic)
                    {
                        var descriptor = new ModelDescriptor(ModelMappingManager.FindByType(modelType));
                        var set = context.Set(modelType);
                        var instance = set.Find(Convert.ChangeType(key, descriptor.KeyProperty.PropertyType));

                        if (instance == null)
                            return onNotFound();

                        @return = model.Invoke(instance);
                        context.SaveChanges();

                        if (@return == instance)
                            @return = null;
                    }
                    else
                        @return = model.Invoke(null);

                    if (@return != null)
                        return onSuccessWithReturn(@return);
                }
                catch (Exception ex)
                {
                    HandleException(ex);
                    return onException(ex);
                }

                return onSuccess();
            }
        }
开发者ID:alexmreis,项目名称:RunningObjects,代码行数:37,代码来源:ControllerBase.cs


注:本文中的Method.Invoke方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。