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


C# Builder.Marshal方法代码示例

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


在下文中一共展示了Builder.Marshal方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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>();
        }
开发者ID:pvginkel,项目名称:Jint2,代码行数:36,代码来源:ProxyHelper.cs

示例2: 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>();
        }
开发者ID:pvginkel,项目名称:Jint2,代码行数:39,代码来源:ProxyHelper.cs

示例3: 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?
//.........这里部分代码省略.........
开发者ID:pvginkel,项目名称:Jint2,代码行数:101,代码来源:ProxyHelper.cs

示例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>();
        }
开发者ID:pvginkel,项目名称:Jint2,代码行数:20,代码来源:ProxyHelper.cs

示例5: 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>();
        }
开发者ID:pvginkel,项目名称:Jint2,代码行数:70,代码来源:ProxyHelper.cs

示例6: 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>();
        }
开发者ID:pvginkel,项目名称:Jint2,代码行数:45,代码来源:ProxyHelper.cs


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