本文整理汇总了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);
}
示例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);
}
}
示例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);
}
}
}
示例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();
}
}
示例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();
}
}