示例#1
0
        public static void PostGenerateCode(object obj, StreamWriter stream, string indent, string var, object parent, string paramName)
        {
            Debug.Check(obj != null);

            Type type = obj.GetType();

            Debug.Check(Plugin.IsCustomClassType(type));

            MethodDef method = parent as MethodDef;
            IList <DesignerPropertyInfo> properties = DesignerProperty.GetDesignerProperties(type);

            foreach (DesignerPropertyInfo property in properties)
            {
                if (!property.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoSave))
                {
                    object member = property.GetValue(obj);
                    if (property.Attribute is DesignerStruct)
                    {
                        PostGenerateCode(member, stream, indent, var + "." + property.Property.Name, parent, paramName);
                    }
                    else
                    {
                        if (method != null)
                        {
                            MethodDef.Param param = method.GetParam(paramName, property);
                            if (param != null)
                            {
                                string nativeType = DataCppExporter.GetBasicGeneratedNativeType(param.NativeType);
                                ParameterCppExporter.PostGenerateCode(param, stream, indent, nativeType, var + "." + property.Property.Name, string.Empty, method);
                            }
                        }
                    }
                }
            }
        }
示例#2
0
        public static void GenerateCode(object obj, StreamWriter stream, string indent, string var, object parent, string paramName)
        {
            Debug.Check(obj != null);

            Type type = obj.GetType();

            Debug.Check(Plugin.IsCustomClassType(type));

            MethodDef method = parent as MethodDef;
            IList <DesignerPropertyInfo> properties = DesignerProperty.GetDesignerProperties(type);

            foreach (DesignerPropertyInfo property in properties)
            {
                if (!property.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoSave))
                {
                    object member = property.GetValue(obj);

                    Type memberType = member.GetType();

                    if (Plugin.IsArrayType(memberType))
                    {
                        string memberNativeType = Plugin.GetNativeTypeName(memberType);
                        string nativeTypeStr    = DataCppExporter.GetGeneratedNativeType(memberNativeType);
                        int    startIndex       = nativeTypeStr.IndexOf('<');
                        int    endIndex         = nativeTypeStr.LastIndexOf('>');
                        string itemType         = nativeTypeStr.Substring(startIndex + 1, endIndex - startIndex - 1);

                        ArrayCppExporter.GenerateCode(member, stream, indent, itemType, paramName);
                    }
                    else
                    {
                        if (property.Attribute is DesignerStruct)
                        {
                            GenerateCode(member, stream, indent, var + "." + property.Property.Name, parent, paramName);
                        }
                        else
                        {
                            bool bStructProperty = false;
                            if (method != null)
                            {
                                MethodDef.Param param = method.GetParam(paramName, property);
                                if (param != null)
                                {
                                    bStructProperty = true;
                                    ParameterCppExporter.GenerateCode(param, stream, indent, string.Empty, var + "." + property.Property.Name, string.Empty);
                                }
                            }

                            if (!bStructProperty)
                            {
                                DataCppExporter.GenerateCode(member, stream, indent, string.Empty, var + "." + property.Property.Name, string.Empty);
                            }
                        }
                    }
                }
            }
        }
示例#3
0
        public static bool IsPureConstDatum(object obj, object parent, string paramName)
        {
            Debug.Check(obj != null);

            if (obj != null)
            {
                Type type = obj.GetType();

                if (!Plugin.IsCustomClassType(type))
                {
                    return(false);
                }

                MethodDef method = parent as MethodDef;
                IList <DesignerPropertyInfo> properties = DesignerProperty.GetDesignerProperties(type, null);

                foreach (DesignerPropertyInfo property in properties)
                {
                    if (!property.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoSave))
                    {
                        object member = property.GetValue(obj);

                        if (property.Attribute is DesignerStruct)
                        {
                            if (!IsPureConstDatum(member, parent, paramName))
                            {
                                return(false);
                            }
                        }
                        else
                        {
                            if (method != null)
                            {
                                MethodDef.Param param = method.GetParam(paramName, property);

                                if (param != null)
                                {
                                    if (!param.IsPureConstDatum)
                                    {
                                        return(false);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(true);
        }
示例#4
0
        public static string RetrieveExportValue(object obj, object parent, string paramName, bool bSave, int indexInArray = -1)
        {
            string str = "";

            Debug.Check(obj != null);

            Type type = obj.GetType();

            if (Plugin.IsRefType(type))
            {
                return("null");
            }

            bool bStructAsBasic = Plugin.IsRegisteredTypeName(type.Name);

            //struct as basic type, like Tag::Vector3, etc.
            //these types are exported as (W=0 X=0 Y=0 Z=0)
            if (!bSave && bStructAsBasic)
            {
                str = "(";
            }
            else
            {
                str = "{";
            }

            if (Plugin.IsCustomClassType(type))
            {
                MethodDef method = parent as MethodDef;

                bool bFirst = true;

                IList <DesignerPropertyInfo> properties = DesignerProperty.GetDesignerProperties(type);
                foreach (DesignerPropertyInfo property in properties)
                {
                    if (!property.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoSave))
                    {
                        if (!bSave && bStructAsBasic && !bFirst)
                        {
                            str += " ";
                        }

                        bFirst = false;

                        if (!bSave)
                        {
                            if (bStructAsBasic)
                            {
                                str += property.Property.Name + "=";
                            }
                        }
                        else
                        {
                            str += property.Property.Name + "=";
                        }

                        object member = property.GetValue(obj);

                        Type memberType = null;

                        if (member != null)
                        {
                            memberType = member.GetType();
                        }
                        else
                        {
                            memberType = property.GetTypeFallback();
                        }

                        if (Plugin.IsArrayType(memberType))
                        {
                            str += DesignerArray.RetrieveExportValue(member);
                        }
                        else
                        {
                            if (property.Attribute is DesignerStruct)
                            {
                                str += RetrieveExportValue(member, parent, paramName, bSave);
                            }
                            else
                            {
                                bool bStructProperty = false;

                                if (method != null)
                                {
                                    MethodDef.Param param = method.GetParam(paramName, property, indexInArray);

                                    if (param != null)
                                    {
                                        bStructProperty = true;
                                        string s = param.GetExportValue(null);

                                        if (Plugin.IsStringType(param.Value.GetType()))
                                        {
                                            str += string.Format("\"{0}\"", s);
                                        }
                                        else
                                        {
                                            str += s;
                                        }
                                    }
                                }

                                if (!bStructProperty)
                                {
                                    string s = property.GetExportValue(obj);

                                    if (Plugin.IsStringType(property.Property.PropertyType))
                                    {
                                        str += string.Format("\"{0}\"", s);
                                    }
                                    else
                                    {
                                        str += s;
                                    }
                                }
                            }
                        }

                        if (!bSave && bStructAsBasic)
                        {
                        }
                        else
                        {
                            str += ";";
                        }
                    }
                }
            }
            else
            {
            }

            if (!bSave && bStructAsBasic)
            {
                str += ")";
            }
            else
            {
                str += "}";
            }

            return(str);
        }
示例#5
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);
            }
        }