Exemplo n.º 1
0
        private static void parseStringValue(List <Nodes.Node.ErrorCheck> result, DefaultObject node, object obj, Type type, string paramName, string str, int startIndex, int endIndex)
        {
            string propertyName  = string.Empty;
            string propertyValue = string.Empty;

            try {
                if (startIndex >= endIndex)
                {
                    return;
                }

                if (!string.IsNullOrEmpty(str))
                {
                    if (startIndex < str.Length && str[startIndex] == '{')
                    {
                        startIndex++;

                        if (endIndex < str.Length && str[endIndex] == '}')
                        {
                            endIndex--;
                        }
                    }
                }

                int valueIndex = getProperty(str, startIndex, endIndex, out propertyName, out propertyValue);

                //if (propertyName == "code")
                //{
                //    Debug.Check(true);
                //}

                if (valueIndex >= 0)
                {
                    Debug.Check(!string.IsNullOrEmpty(propertyName));

                    DesignerPropertyInfo property;

                    if (getPropertyInfo(type, propertyName, out property))
                    {
                        // Primitive type
                        if (string.IsNullOrEmpty(propertyValue) || propertyValue[0] != '{')
                        {
                            MethodDef.Param parParam = null;
                            Nodes.Action    action   = node as Nodes.Action;

                            if (action != null)
                            {
                                MethodDef method = action.Method;

                                if (method != null)
                                {
                                    string pn = "";
                                    if (paramName == null)
                                    {
                                        pn = propertyName;
                                    }

                                    parParam = method.GetParam(pn, type, obj, property);
                                }
                            }

                            bool     bParamFromStruct = false;
                            string[] tokens           = Plugin.Split(propertyValue, ' ');

                            if (tokens != null && tokens.Length > 1)
                            {
                                //par
                                if (parParam != null)
                                {
                                    int propertyNameIndex = 1;

                                    if (tokens.Length == 2)
                                    {
                                        propertyNameIndex = 1;
                                    }
                                    else if (tokens.Length == 3)
                                    {
                                        Debug.Check(tokens[0] == "static");
                                        propertyNameIndex = 2;
                                    }
                                    else
                                    {
                                        Debug.Check(false);
                                    }

                                    parParam.Value   = DesignerMethodEnum.setParameter(result, node, tokens[propertyNameIndex]);
                                    bParamFromStruct = true;
                                }
                            }

                            if (!bParamFromStruct)
                            {
                                property.SetValueFromString(result, obj, propertyValue, node);

                                if (parParam != null && parParam.Value == null)
                                {
                                    parParam.Value = property.GetValue(obj);
                                }
                            }
                        }

                        // Struct type
                        else
                        {
                            object member = property.GetValue(obj);
                            Debug.Check(member != null);

                            string structStr = str.Substring(valueIndex + 1, propertyValue.Length - 2);
                            parseStringValue(result, node, member, member.GetType(), paramName, structStr, 0, structStr.Length - 1);
                        }
                    }

                    // Parse next property
                    parseStringValue(result, node, obj, type, paramName, str, valueIndex + propertyValue.Length + 1, str.Length - 1);
                }
            } catch (Exception ex) {
                string msg = string.Format("{0}\n{1}:{2}", ex.Message, propertyName, propertyValue);
                MessageBox.Show(msg, Resources.LoadError, MessageBoxButtons.OK);
            }
        }