コード例 #1
0
        /// <summary>
        /// Deserializes a call expression where the target is an array expression.
        ///
        /// System.Array[String](["a", "b"])
        /// </summary>
        object DeserializeCreateArrayExpression(CallExpression callExpression, IndexExpression target)
        {
            ListExpression list      = callExpression.Args[0].Expression as ListExpression;
            Type           arrayType = GetType(target.Index as MemberExpression);
            Array          array     = Array.CreateInstance(arrayType, list.Items.Count);

            for (int i = 0; i < list.Items.Count; ++i)
            {
                Expression         listItemExpression     = list.Items[i];
                ConstantExpression constantExpression     = listItemExpression as ConstantExpression;
                MemberExpression   memberExpression       = listItemExpression as MemberExpression;
                NameExpression     nameExpression         = listItemExpression as NameExpression;
                CallExpression     listItemCallExpression = listItemExpression as CallExpression;
                if (constantExpression != null)
                {
                    array.SetValue(constantExpression.Value, i);
                }
                else if (memberExpression != null)
                {
                    string name = PythonControlFieldExpression.GetVariableName(memberExpression.Name);
                    array.SetValue(componentCreator.GetComponent(name), i);
                }
                else if (nameExpression != null)
                {
                    array.SetValue(componentCreator.GetInstance(nameExpression.Name), i);
                }
                else if (listItemCallExpression != null)
                {
                    Type   arrayInstanceType = GetType(listItemCallExpression.Target as MemberExpression);
                    object instance          = componentCreator.CreateInstance(arrayInstanceType, GetArguments(listItemCallExpression), null, false);
                    array.SetValue(instance, i);
                }
            }
            return(array);
        }
コード例 #2
0
        object CreateInstance(string name, MethodCall methodCall)
        {
            RubyControlFieldExpression field = RubyControlFieldExpression.Create(methodCall);
            Type type = GetType(field);

            if (type != null)
            {
                if (type.IsEnum)
                {
                    return(Enum.Parse(type, methodCall.MethodName));
                }

                BindingFlags propertyBindingFlags = BindingFlags.Public | BindingFlags.GetField | BindingFlags.Static | BindingFlags.Instance;
                PropertyInfo propertyInfo         = type.GetProperty(methodCall.MethodName, propertyBindingFlags);
                if (propertyInfo != null)
                {
                    return(propertyInfo.GetValue(type, null));
                }

                if (type.IsAssignableFrom(typeof(ComponentResourceManager)))
                {
                    return(componentCreator.CreateInstance(type, new object[0], name, false));
                }

                if (methodCall.Arguments != null)
                {
                    return(CreateInstance(type, name, methodCall));
                }
            }
            else
            {
                return(componentCreator.GetInstance(field.MethodName));
            }
            return(null);
        }
コード例 #3
0
        /// <summary>
        /// Creates a new instance with the specified name.
        /// </summary>
        object CreateInstance(string name, CallExpression node)
        {
            MemberExpression memberExpression = node.Target as MemberExpression;

            if (memberExpression != null)
            {
                string typeName = PythonControlFieldExpression.GetMemberName(memberExpression);
                Type   type     = componentCreator.GetType(typeName);
                if (type != null)
                {
                    if (type.IsAssignableFrom(typeof(ComponentResourceManager)))
                    {
                        return(componentCreator.CreateInstance(type, new object[0], name, false));
                    }
                    List <object> args = deserializer.GetArguments(node);
                    return(componentCreator.CreateInstance(type, args, name, false));
                }
            }
            return(null);
        }