本文整理汇总了C#中Builder.AddParameter方法的典型用法代码示例。如果您正苦于以下问题:C# Builder.AddParameter方法的具体用法?C# Builder.AddParameter怎么用?C# Builder.AddParameter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Builder
的用法示例。
在下文中一共展示了Builder.AddParameter方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WrapSetPropertyCore
private static JsFunction WrapSetPropertyCore(PropertyInfo property)
{
var builder = new Builder();
builder.AddRuntimeParameter();
builder.AddThisParameter(typeof(object));
builder.AddParameter(typeof(JsObject), "callee");
var argumentsParameter = builder.AddParameter(typeof(object[]), "arguments");
var method = property.GetSetMethod();
var local = builder.AddLocal(typeof(object), "value");
builder.AddStatement(Expression.Assign(
local,
Expression.ArrayAccess(
argumentsParameter,
Expression.Constant(0)
)
));
builder.AddStatement(Expression.Assign(
Expression.Property(
builder.MarshalThis(method.DeclaringType, method.IsStatic),
property
),
builder.Marshal(
local,
property.PropertyType
)
));
builder.AddStatement(local);
return builder.Compile<JsFunction>();
}
示例2: WrapMethodCore
private static JsFunction WrapMethodCore(MethodInfo method)
{
var builder = new Builder();
builder.AddRuntimeParameter();
builder.AddThisParameter(typeof(object));
builder.AddParameter(typeof(JsObject), "callee");
var argumentsParameter = builder.AddParameter(typeof(object[]), "arguments");
var methodThis = builder.MarshalThis(method.DeclaringType, method.IsStatic);
var arguments = new List<Expression>();
var parameters = method.GetParameters();
bool skipFirst = false;
if (parameters.Length > 0 && typeof(JsGlobal).IsAssignableFrom(parameters[0].ParameterType))
{
skipFirst = true;
arguments.Add(builder.Global);
}
var outParameters = new List<Tuple<ParameterInfo, ParameterExpression, int>>();
int index = 0;
foreach (var parameter in parameters)
{
// Skip over the global parameter.
if (skipFirst)
{
skipFirst = false;
continue;
}
// Get the argument from the array, or undefined there is none.
Expression argument = Expression.Condition(
Expression.GreaterThan(
Expression.ArrayLength(argumentsParameter),
Expression.Constant(index)
),
Expression.ArrayAccess(
argumentsParameter,
Expression.Constant(index)
),
Expression.Field(null, typeof(JsUndefined).GetField("Instance")),
typeof(object)
);
// If this is a ref or out parameter, we need to create a local.
if (parameter.ParameterType.IsByRef)
{
var parameterType = parameter.ParameterType.GetElementType();
argument = builder.Marshal(argument, parameterType);
// Create a local to hold the value.
var tmpLocal = builder.AddLocal(
parameterType,
"tmp"
);
// Add the assignment to the statements.
builder.AddStatement(Expression.Assign(tmpLocal, argument));
// And use the temp local as the parameter.
argument = tmpLocal;
// Register it so that we do a write-back later on.
outParameters.Add(Tuple.Create(parameter, tmpLocal, index));
}
else
{
argument = builder.Marshal(argument, parameter.ParameterType);
}
// Add the argument to the list.
arguments.Add(argument);
// Move on to the next argument.
index++;
}
// Call the method.
Expression methodCall = Expression.Call(
methodThis,
method,
arguments
);
// Are we returning a value?
//.........这里部分代码省略.........
示例3: WrapSetFieldCore
private static JsFunction WrapSetFieldCore(FieldInfo field)
{
if (field == null)
throw new ArgumentNullException("field");
var builder = new Builder();
builder.AddRuntimeParameter();
builder.AddThisParameter(typeof(object));
builder.AddParameter(typeof(JsObject), "callee");
var argumentsParameter = builder.AddParameter(typeof(object[]), "arguments");
var local = builder.AddLocal(typeof(object), "value");
builder.AddStatement(Expression.Assign(
local,
Expression.ArrayAccess(
argumentsParameter,
Expression.Constant(0)
)
));
// Can't assign to constants.
if (!field.IsLiteral && !field.IsInitOnly)
{
builder.AddStatement(Expression.Assign(
Expression.Field(
builder.MarshalThis(field.DeclaringType, field.IsStatic),
field
),
builder.Marshal(local, field.FieldType)
));
}
builder.AddStatement(local);
return builder.Compile<JsFunction>();
}
示例4: WrapIndexerSetterCore
private static WrappedIndexerSetter WrapIndexerSetterCore(MethodInfo method)
{
var builder = new Builder();
builder.AddGlobalParameter();
builder.AddThisParameter(typeof(JsObject));
var indexParameter = builder.AddParameter(typeof(object), "index");
var argument = builder.AddParameter(typeof(object), "value");
var parameters = method.GetParameters();
builder.AddStatement(Expression.Call(
builder.MarshalThis(method.DeclaringType, method.IsStatic),
method,
builder.Marshal(indexParameter, parameters[0].ParameterType),
builder.Marshal(argument, parameters[1].ParameterType)
));
return builder.Compile<WrappedIndexerSetter>();
}
示例5: WrapGetPropertyCore
private static JsFunction WrapGetPropertyCore(PropertyInfo property)
{
var builder = new Builder();
builder.AddRuntimeParameter();
builder.AddThisParameter(typeof(object));
builder.AddParameter(typeof(JsObject), "callee");
builder.AddParameter(typeof(object[]), "arguments");
var method = property.GetGetMethod();
builder.AddStatement(builder.UnMarshal(
Expression.Property(
builder.MarshalThis(method.DeclaringType, method.IsStatic),
property
),
method.ReturnType
));
return builder.Compile<JsFunction>();
}
示例6: WrapGetFieldCore
private static JsFunction WrapGetFieldCore(FieldInfo field)
{
var builder = new Builder();
builder.AddRuntimeParameter();
builder.AddThisParameter(typeof(object));
builder.AddParameter(typeof(JsObject), "callee");
builder.AddParameter(typeof(object[]), "arguments");
builder.AddStatement(builder.UnMarshal(
Expression.Field(
builder.MarshalThis(field.DeclaringType, field.IsStatic),
field
),
field.FieldType
));
return builder.Compile<JsFunction>();
}
示例7: WrapDelegate
private static JsFunction WrapDelegate(Delegate @delegate)
{
var builder = new Builder();
builder.AddRuntimeParameter();
builder.AddThisParameter(typeof(object));
builder.AddParameter(typeof(JsObject), "callee");
var argumentsParameter = builder.AddParameter(typeof(object[]), "arguments");
var method = @delegate.Method;
var arguments = new List<Expression>();
var parameters = method.GetParameters();
bool skipFirst = false;
if (parameters.Length > 0 && typeof(JsGlobal).IsAssignableFrom(parameters[0].ParameterType))
{
skipFirst = true;
arguments.Add(builder.Global);
}
int index = 0;
foreach (var parameter in parameters)
{
// Skip over the global parameter.
if (skipFirst)
{
skipFirst = false;
continue;
}
// Get the argument from the array, or undefined there is none.
Expression argument = Expression.Condition(
Expression.GreaterThan(
Expression.ArrayLength(argumentsParameter),
Expression.Constant(index)
),
Expression.ArrayAccess(
argumentsParameter,
Expression.Constant(index)
),
Expression.Field(null, typeof(JsUndefined).GetField("Instance")),
typeof(object)
);
// Add the argument to the list.
arguments.Add(builder.Marshal(argument, parameter.ParameterType));
// Move on to the next argument.
index++;
}
// Call the delegate.
builder.AddStatement(builder.UnMarshalReturn(
Expression.Invoke(
Expression.Constant(@delegate),
arguments
),
method.ReturnType
));
return builder.Compile<JsFunction>();
}
示例8: WrapConstructorCore
private static WrappedConstructor WrapConstructorCore(ConstructorInfo constructor)
{
var builder = new Builder();
builder.AddGlobalParameter();
var argumentsParameter = builder.AddParameter(typeof(object[]), "arguments");
var parameters = constructor.GetParameters();
var arguments = new List<Expression>();
for (int i = 0; i < parameters.Length; i++)
{
// Get the argument from the array, or undefined there is none,
// and marshal it.
arguments.Add(builder.Marshal(
Expression.Condition(
Expression.GreaterThan(
Expression.ArrayLength(argumentsParameter),
Expression.Constant(i)
),
Expression.ArrayAccess(
argumentsParameter,
Expression.Constant(i)
),
Expression.Field(null, typeof(JsUndefined).GetField("Instance")),
typeof(object)
),
parameters[i].ParameterType
));
}
// Construct the new object. This does **NOT** un-marshal the
// result; this is done at the call site.
builder.AddStatement(Expression.Convert(
Expression.New(
constructor,
arguments
),
typeof(object)
));
return builder.Compile<WrappedConstructor>();
}