Esempio n. 1
0
 static void WriteGetter(StringBuilder header, StringBuilder source, PropertyPair property, ClassInfo clazz, List <ClassInfo> classes, List <EnumData> enums)
 {
     if (property.Getter != null)      //return value, typename, propertyname, gettername
     {
         string getText = TypeHandling.CPPTypeToCSharpValue(property.Getter.GetReturnValue(), String.Format("{0}_->{1}()", clazz.Name.ToLower(), property.Getter.CMethodName), classes, enums);
         source.AppendFormat(SOURCE_PROPERTY_GET,
                             TypeHandling.ASToCSharpType(property.Getter.GetReturnValue(), classes), // Return type name
                             clazz.Name,                                                             //Class name
                             property.GetPropertyName(),                                             //Name of property
                             getText);                                                               // Value being set
     }
 }
Esempio n. 2
0
 public static void WriteFields(StringBuilder header, StringBuilder source, ClassInfo clazz, List <ClassInfo> classes, List <EnumData> enums)
 {
     foreach (FieldInfo fi in clazz.Fields)
     {
         string fieldName = fi.BoundName;
         string typeName  = TypeHandling.ASToCSharpType(fi.Typename, classes);
         string retValue  = TypeHandling.CPPTypeToCSharpValue(fi.Typename, String.Format("{0}_->{1}_", clazz.Name.ToLower(), fi.BoundName), classes, enums);
         string setValue  = TypeHandling.CPPTypeFromCSharpValue(fi.Typename, "value", classes, enums);
         header.AppendFormat("        property {0} {1} {{ {0} get(); void set({0} value); }}\r\n", typeName, fieldName);
         source.AppendFormat("{0} {1}::{2}::get() {{ return {3}; }}\r\n", typeName, clazz.Name, fieldName, retValue);
         source.AppendFormat("void {0}::{1}::set({2} value) {{ {4}_->{1}_ = {3}; }}\r\n\r\n", clazz.Name, fieldName, typeName, setValue, clazz.Name.ToLower());
     }
 }
Esempio n. 3
0
        static void WriteSetter(StringBuilder header, StringBuilder source, PropertyPair property, ClassInfo clazz, List <ClassInfo> classes, List <EnumData> enums)
        {
            if (property.Setter != null)      //input value, typename, propertyname, settername
            {
                string setValue = TypeHandling.CPPTypeFromCSharpValue(property.Setter.ParameterTypes[0], "value", classes, enums);

                source.AppendFormat(SOURCE_PROPERTY_SET,
                                    TypeHandling.ASToCSharpType(property.Setter.HeaderDeclaration(classes), classes), // Type of setter
                                    clazz.Name,                                                                       //Name of class
                                    property.GetPropertyName(),                                                       //Name of property
                                    property.Setter.CMethodName,                                                      //Method to invoke
                                    setValue,
                                    clazz.Name.ToLower());                                                            //Conversion into CPP
            }
        }
Esempio n. 4
0
        public string HeaderDeclaration(List <ClassInfo> classes)
        {
            StringBuilder sb = new StringBuilder();

            if (ParameterTypes != null && ParameterTypes.Length > 0)
            {
                for (int i = 0; i < ParameterTypes.Length; ++i)
                {
                    if (sb.Length > 0)
                    {
                        sb.Append(", ");
                    }
                    sb.Append(TypeHandling.ASToCSharpType(ParameterTypes[i], classes));
                }
            }
            return(sb.ToString());
        }
Esempio n. 5
0
 public static void WriteMethods(StringBuilder header, StringBuilder source, ClassInfo clazz, List <ClassInfo> classes, List <EnumData> enums)
 {
     foreach (MethodInfo method in clazz.Methods)
     {
         string methodName = method.GetMethodName();
         string tail       = methodName.Equals("ToString") ? " override" : "";
         header.AppendFormat(HEADER_METHOD,
                             TypeHandling.ASToCSharpType(method.GetReturnValue(), classes),
                             methodName,
                             method.HeaderDeclaration(classes),
                             tail);
         //return, clazz, methodname, parameters, RETURN IF NOT VOID, CMethodName, parameter names
         string getText = TypeHandling.CPPTypeToCSharpValue(method.GetReturnValue(), String.Format("{0}_->{1}({2})", clazz.Name.ToLower(), method.CMethodName, method.SourceCall(classes, enums)), classes, enums);
         source.AppendFormat(SOURCE_METHOD,
                             TypeHandling.ASToCSharpType(method.GetReturnValue(), classes), //Return type
                             clazz.Name,
                             methodName,
                             method.SourceDeclaration(classes), //
                             method.GetReturnValue().Equals("void") ? "" : "return ",
                             getText,
                             "");
     }
 }
Esempio n. 6
0
        public static void WriteProperties(StringBuilder header, StringBuilder source, ClassInfo clazz, List <ClassInfo> classes, List <EnumData> enums)
        {
            foreach (PropertyPair property in clazz.Properties)
            {
                if (property.IsIndexer)
                {
                    if (property.Setter != null && property.Getter != null)
                    {
                        header.AppendFormat(HEADER_INDEXER_GET_SET,
                                            TypeHandling.ASToCSharpType(property.Getter.GetReturnValue(), classes),
                                            property.GetPropertyName(),
                                            property.Getter.HeaderDeclaration(classes));


                        string getText = TypeHandling.CPPTypeToCSharpValue(property.Getter.GetReturnValue(), String.Format("{0}_->{1}({2})", clazz.Name.ToLower(), property.Getter.CMethodName, property.Getter.SourceCall(classes, enums)), classes, enums);
                        source.AppendFormat(SOURCE_INDEX_GET,
                                            TypeHandling.ASToCSharpType(property.Getter.GetReturnValue(), classes),
                                            clazz.Name,
                                            property.GetPropertyName(),
                                            property.Getter.SourceDeclaration(classes),
                                            getText);

                        source.AppendFormat(SOURCE_INDEX_SET,
                                            clazz.Name,
                                            property.GetPropertyName(),
                                            property.Setter.SourceDeclaration(classes),
                                            clazz.Name.ToLower(),
                                            property.Setter.CMethodName,
                                            property.Setter.SourceCall(classes, enums));
                    }
                    else if (property.Getter != null)
                    {
                        header.AppendFormat(HEADER_INDEXER_GET,
                                            TypeHandling.ASToCSharpType(property.Getter.GetReturnValue(), classes),
                                            property.GetPropertyName(),
                                            property.Getter.HeaderDeclaration(classes));

                        //"{0} {1}::{2}::get({3} value) {{ return {4}; }}\r\n\r\n";
                        string getText = TypeHandling.CPPTypeToCSharpValue(property.Getter.GetReturnValue(), String.Format("{0}_->{1}({2})", clazz.Name.ToLower(), property.Getter.CMethodName, property.Getter.SourceCall(classes, enums)), classes, enums);
                        source.AppendFormat(SOURCE_INDEX_GET,
                                            TypeHandling.ASToCSharpType(property.Getter.GetReturnValue(), classes),
                                            clazz.Name,
                                            property.GetPropertyName(),
                                            property.Getter.SourceDeclaration(classes),
                                            getText);
                    }
                    else if (property.Setter != null)
                    {
                        header.AppendFormat(HEADER_INDEXER_SET,
                                            TypeHandling.ASToCSharpType(property.Setter.GetReturnValue(), classes),
                                            property.GetPropertyName(),
                                            property.Setter.HeaderDeclaration(classes));

                        //"void {0}::{1}::set({2}) {{ {3}_->{4}({5}); }}\r\n\r\n";
                        source.AppendFormat(SOURCE_INDEX_SET,
                                            clazz.Name,
                                            property.GetPropertyName(),
                                            property.Setter.SourceDeclaration(classes),
                                            clazz.Name.ToLower(),
                                            property.Setter.CMethodName,
                                            property.Setter.SourceCall(classes, enums));
                    }
                }
                else
                {
                    string body  = "";
                    string value = "";
                    if (property.Setter != null && property.Getter != null)
                    {
                        body = String.Format(HEADER_BODY_GETSET,
                                             TypeHandling.ASToCSharpType(property.Getter.GetReturnValue(), classes)); //return/assignment type
                        value = TypeHandling.ASToCSharpType(property.Getter.GetReturnValue(), classes);
                    }
                    else if (property.Setter != null)
                    {
                        body = String.Format(HEADER_BODY_SET,
                                             TypeHandling.ASToCSharpType(property.Setter.HeaderDeclaration(classes), classes)); // assignment type
                        value = TypeHandling.ASToCSharpType(property.Setter.HeaderDeclaration(classes), classes);
                    }
                    else
                    {
                        body = String.Format(HEADER_BODY_GET,
                                             TypeHandling.ASToCSharpType(property.Getter.GetReturnValue(), classes)); // return type
                        value = TypeHandling.ASToCSharpType(property.Getter.GetReturnValue(), classes);
                    }

                    header.AppendFormat(HEADER_PROPERTY,
                                        value,                      // Type of the property
                                        property.GetPropertyName(), //name of the property
                                        body);                      // get() set() contents
                    //return value, typename, propertyname, gettername, settername

                    WriteGetter(header, source, property, clazz, classes, enums);
                    WriteSetter(header, source, property, clazz, classes, enums);
                }
            }
        }