コード例 #1
0
 public T6Function(string pName, string pNameSpace, CSharpGenerator.CSharpType pReturnType)
 {
     Parameters = new List <T6Parameter>();
     Name       = pName;
     NameSpace  = pNameSpace;
     ReturnType = pReturnType;
 }
コード例 #2
0
 public T6Getter(string pPropGetterName, CSharpGenerator.CSharpType pPropReturnType, string pGetterName,
                 CSharpGenerator.CSharpType pGetterType)
     : base(pGetterName, null, pGetterType)
 {
     PropGetterName = pPropGetterName;
     PropReturnType = pPropReturnType;
     GetterName     = pGetterName;
     GetterType     = pGetterType;
     HasIndex       = false;
 }
コード例 #3
0
        public static T6Function ParseFunction(XmlReader pReader)
        {
            if (pReader.Name != "Function" || !pReader.IsStartElement())
            {
                return(null);
            }
            string Name = pReader["Name"];

            CSharpGenerator.CSharpType ReturnType = CSharpGenerator.CSharpType.ToCSharpType(pReader["ReturnType"]);
            string     NameSpace = pReader["NameSpace"];
            T6Function function  = new T6Function(Name, NameSpace, ReturnType);

            pReader.Read();
            pReader.Read();
            if (pReader.Name == "Params" && !pReader.IsEmptyElement)
            {
                while (pReader.Read())
                {
                    if (!pReader.IsStartElement() && pReader.Name == "Params")
                    {
                        break;
                    }
                    string paramName    = pReader["Name"];
                    string defaultvalue = pReader["DefaultValue"];
                    CSharpGenerator.CSharpType paramType = CSharpGenerator.CSharpType.ToCSharpType(pReader["Type"]);
                    T6Parameter parameter = new T6Parameter(paramName, paramType, defaultvalue == "N/A" ? null : defaultvalue);
                    function.Parameters.Add(parameter);
                }
            }
            if (function.Name == "WrapObject")
            {
                function.Parameters[0].ParamType = CSharpGenerator.CSharpType.ToCSharpType("IntPtr");
            }
            Debug.Assert(NameSpace != null, "NameSpace != null");
            return(function);
        }
コード例 #4
0
        public static T6Class ParseClass(XmlReader pReader)
        {
            T6Class t6Class = new T6Class();

            while (pReader.Read())
            {
                if (!pReader.IsStartElement())
                {
                    continue;
                }
                switch (pReader.Name)
                {
                case "Class":
                    t6Class.Name      = pReader["Name"];
                    t6Class.Namespace = pReader["Namespace"];
                    break;

                case "Class.Parents":
                    while (pReader.Read())
                    {
                        if (!pReader.IsStartElement() && pReader.Name == "Class.Parents")
                        {
                            break;
                        }
                        t6Class.ParentList.Add(pReader["Name"]);
                    }
                    break;

                case "Functions":
                    while (pReader.Read())
                    {
                        if (!pReader.IsStartElement() && pReader.Name == "Functions")
                        {
                            break;
                        }
                        if (pReader.Name != "Function" || !pReader.IsStartElement())
                        {
                            continue;
                        }
                        string Name = pReader["Name"];
                        CSharpGenerator.CSharpType ReturnType = CSharpGenerator.CSharpType.ToCSharpType(pReader["ReturnType"]);
                        T6Function function = new T6Function(Name, null, ReturnType);
                        pReader.Read();
                        pReader.Read();
                        if (pReader.Name == "Params" && !pReader.IsEmptyElement)
                        {
                            while (pReader.Read())
                            {
                                if (!pReader.IsStartElement() && pReader.Name == "Params")
                                {
                                    break;
                                }
                                string paramName    = pReader["Name"];
                                string defaultvalue = pReader["DefaultValue"];
                                CSharpGenerator.CSharpType paramType = CSharpGenerator.CSharpType.ToCSharpType(pReader["Type"]);
                                T6Parameter parameter = new T6Parameter(paramName, paramType, defaultvalue == "N/A" ? null : defaultvalue);
                                function.Parameters.Add(parameter);
                            }
                        }
                        t6Class.Functions.Add(function);
                    }
                    break;

                case "Properties":
                    if (pReader.IsEmptyElement)
                    {
                        continue;
                    }
                    while (pReader.Read())
                    {
                        if (!pReader.IsStartElement() && pReader.Name == "Properties")
                        {
                            break;
                        }
                        if (pReader.IsEmptyElement)
                        {
                            continue;
                        }
                        string PropertyName = pReader["Name"];

                        T6Property property = new T6Property(PropertyName)
                        {
                            Type  = CSharpGenerator.CSharpType.ToCSharpType(pReader["Type"]),
                            Out   = bool.Parse(pReader["Out"]),
                            Count = int.Parse(pReader["Count"])
                        };
                        pReader.Read();
                        pReader.Read();
                        if (pReader.Name == "Property.Getter")
                        {
                            string propGetterName = pReader["Name"];
                            CSharpGenerator.CSharpType propGetterType = CSharpGenerator.CSharpType.ToCSharpType(pReader["ReturnType"]);
                            property.Getter = new T6Getter(PropertyName, property.Type, propGetterName, propGetterType);
                            if (property.Out)
                            {
                                property.Getter = new T6OutParamGetter(PropertyName, property.Type, propGetterName, propGetterType);
                            }
                            if (property.Count > 1)
                            {
                                property.Getter.HasIndex = true;
                            }
                            pReader.Read();
                            pReader.Read();

                            while (pReader.Read())
                            {
                                if (!pReader.IsStartElement() && pReader.Name == "Getter.Params")
                                {
                                    break;
                                }
                                string paramName    = pReader["Name"];
                                string defaultvalue = pReader["DefaultValue"];
                                CSharpGenerator.CSharpType paramType = CSharpGenerator.CSharpType.ToCSharpType(pReader["Type"]);
                                T6Parameter parameter = new T6Parameter(paramName, paramType, defaultvalue == "N/A" ? null : defaultvalue);
                                property.Getter.Parameters.Add(parameter);
                            }

                            pReader.Read();
                            pReader.Read();
                            pReader.Read();
                            pReader.Read();
                        }
                        if (pReader.Name == "Property.Setter")
                        {
                            string propSetterName = pReader["Name"];
                            CSharpGenerator.CSharpType propSetterType = CSharpGenerator.CSharpType.ToCSharpType(pReader["ReturnType"]);
                            property.Setter = new T6Setter(PropertyName, property.Type, propSetterName, propSetterType);
                            pReader.Read();
                            pReader.Read();

                            if (property.Count > 1)
                            {
                                property.Setter.HasIndex = true;
                            }
                            while (pReader.Read())
                            {
                                if (!pReader.IsStartElement() && pReader.Name == "Setter.Params")
                                {
                                    break;
                                }
                                string paramName    = pReader["Name"];
                                string defaultvalue = pReader["DefaultValue"];
                                CSharpGenerator.CSharpType paramType = CSharpGenerator.CSharpType.ToCSharpType(pReader["Type"]);
                                T6Parameter parameter = new T6Parameter(paramName, paramType, defaultvalue == "N/A" ? null : defaultvalue);
                                property.Setter.Parameters.Add(parameter);
                            }

                            pReader.Read();
                            pReader.Read();
                            pReader.Read();
                            pReader.Read();
                        }
                        if (property.Getter != null || property.Setter != null)
                        {
                            t6Class.Properties.Add(property);
                        }
                    }
                    break;
                }
            }
            return(t6Class);
        }
コード例 #5
0
        private string GeneratePropertiesCodeBlock()
        {
            StringBuilder SB = new StringBuilder();

            foreach (T6Property t6Property in Properties)
            {
                CSharpGenerator.CSharpType propType = t6Property.Getter?.GetterType ?? t6Property.Setter?.ValueParameter.ParamType;

                if (t6Property.Out)
                {
                    propType = (t6Property.Getter as T6OutParamGetter)?.OutParam.ParamType ?? t6Property.Setter?.ValueParameter.ParamType;
                }

                if (t6Property.Count > 1)
                {
                    string fieldVectorType = "";
                    string typeArg         = $"<{t6Property.Type.ManagedType}>";
                    if (t6Property.Type.ManagedType.Equals("int") ||
                        t6Property.Type.ManagedType.Equals("float") ||
                        t6Property.Type.ManagedType.Equals("double") ||
                        t6Property.Type.ManagedType.Equals("char"))
                    {
                        fieldVectorType = "Primitive";
                    }
                    if (t6Property.Type.ManagedType.Equals("string"))
                    {
                        fieldVectorType = "String";
                        typeArg         = "";
                    }
                    string append = String.Format(@"
      public {5}FieldVector{0} {1}
      {{
         get
         {{
            return new {5}FieldVector{0}(this, {2}, InternalUnsafeMethods.{3},
               InternalUnsafeMethods.{4});
         }}
      }}
", typeArg, t6Property.Name, t6Property.Count, t6Property.Getter.GetterName,
                                                  t6Property.Setter.SetterName, fieldVectorType);

                    SB.Append(append);
                }
                else
                {
                    string append = String.Format(@"      public {1} {0}
      {{
", t6Property.Name, propType.ManagedType);

                    string get = "";
                    if (t6Property.Getter != null)
                    {
                        if (t6Property.Out)
                        {
                            get = String.Format(@"         get
         {{
            if (IsDead()) throw new Exceptions.SimObjectPointerInvalidException();
            {1} outVal;
            InternalUnsafeMethods.{0}(ObjectPtr->ObjPtr, out outVal);
            return outVal;
         }}
", t6Property.Getter.GetterName, propType.ManagedType);
                        }
                        else
                        {
                            get = String.Format(@"         get
         {{
            if (IsDead()) throw new Exceptions.SimObjectPointerInvalidException();
            return {0};
         }}
",
                                                propType.GetReturn(String.Format("InternalUnsafeMethods.{0}(ObjectPtr->ObjPtr)",
                                                                                 t6Property.Getter.GetterName)));
                        }
                    }

                    string set = "";
                    if (t6Property.Setter != null)
                    {
                        set = String.Format(@"         set
         {{
            if (IsDead()) throw new Exceptions.SimObjectPointerInvalidException();
            InternalUnsafeMethods.{0}(ObjectPtr->ObjPtr, {1});
         }}", t6Property.Setter.SetterName, propType.GetArg("value"));
                    }

                    append += get;
                    append += set;
                    append += @"
      }
";
                    SB.Append(append);
                }
            }
            return(SB.ToString().Trim());
        }