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


C# Builder.UnMarshal方法代码示例

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


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

示例1: WrapMethodCore


//.........这里部分代码省略.........
                {
                    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?

            ParameterExpression returnLocal = null;

            if (method.ReturnType != typeof(void))
            {
                returnLocal = builder.AddLocal(method.ReturnType, "return");

                methodCall = Expression.Assign(
                    returnLocal,
                    methodCall
                );
            }

            // Add the method call to the statements.

            builder.AddStatement(methodCall);

            // Process any out parameters.

            foreach (var outParameter in outParameters)
            {
                // Put the result back into the arguments array if the array
                // is long enough.

                builder.AddStatement(Expression.IfThen(
                    Expression.GreaterThan(
                        Expression.ArrayLength(argumentsParameter),
                        Expression.Constant(outParameter.Item3)
                    ),
                    Expression.Assign(
                        Expression.ArrayAccess(
                            argumentsParameter,
                            Expression.Constant(outParameter.Item3)
                        ),
                        Expression.Call(
                            builder.Marshaller,
                            _marshalClr.MakeGenericMethod(outParameter.Item1.ParameterType.GetElementType()),
                            outParameter.Item2
                        )
                    )
                ));
            }

            // Create the result.

            builder.AddStatement(
                returnLocal != null
                ? builder.UnMarshal(returnLocal, method.ReturnType)
                : Expression.Field(null, typeof(JsUndefined).GetField("Instance"))
            );

            return builder.Compile<JsFunction>();
        }
开发者ID:pvginkel,项目名称:Jint2,代码行数:101,代码来源:ProxyHelper.cs

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

示例3: WrapIndexerGetterCore

        private static WrappedIndexerGetter WrapIndexerGetterCore(MethodInfo method)
        {
            var builder = new Builder();

            builder.AddGlobalParameter();
            builder.AddThisParameter(typeof(JsObject));
            var indexParameter = builder.AddParameter(typeof(object), "index");

            builder.AddStatement(builder.UnMarshal(
                Expression.Call(
                    builder.MarshalThis(method.DeclaringType, method.IsStatic),
                    method,
                    builder.Marshal(indexParameter, method.GetParameters()[0].ParameterType)
                ),
                method.ReturnType
            ));

            return builder.Compile<WrappedIndexerGetter>();
        }
开发者ID:pvginkel,项目名称:Jint2,代码行数:19,代码来源:ProxyHelper.cs

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


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