示例#1
0
    public string  getStatusAsString()
    {
        TypeStatus result = getStatus();

        if (result.in_known_list)
        {
            return(stringFromStatus(result.list_value));
        }
        else
        {
            return(result.string_value);
        }
    }
示例#2
0
        // GET: TypeStatus/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TypeStatus typeStatus = db.TypeStatus.Find(id);

            if (typeStatus == null)
            {
                return(HttpNotFound());
            }
            return(View(typeStatus));
        }
示例#3
0
    private void  fromJSONStatus(JSONValue json_value, bool ignore_extras)
    {
        Debug.Assert(json_value != null);
        JSONStringValue json_string = json_value.string_value();

        if (json_string == null)
        {
            throw new Exception("The value for field Status of SportsOlympicsGamesJSON is not a string.");
        }
        TypeStatus the_open_enum = new TypeStatus();

        switch (json_string.getData()[0])
        {
        case 'C':
            if ((String.Compare(json_string.getData(), 1, "ompleted", 0, 8, false) == 0) && (json_string.getData().Length == 9))
            {
                the_open_enum.in_known_list = true;
                the_open_enum.list_value    = TypeStatusKnownValues.Status_Completed;
                goto open_enum_is_done;
            }
            break;

        case 'O':
            if ((String.Compare(json_string.getData(), 1, "ngoing", 0, 6, false) == 0) && (json_string.getData().Length == 7))
            {
                the_open_enum.in_known_list = true;
                the_open_enum.list_value    = TypeStatusKnownValues.Status_Ongoing;
                goto open_enum_is_done;
            }
            break;

        case 'U':
            if ((String.Compare(json_string.getData(), 1, "pcoming", 0, 7, false) == 0) && (json_string.getData().Length == 8))
            {
                the_open_enum.in_known_list = true;
                the_open_enum.list_value    = TypeStatusKnownValues.Status_Upcoming;
                goto open_enum_is_done;
            }
            break;

        default:
            break;
        }
        the_open_enum.in_known_list = false;
        the_open_enum.string_value  = json_string.getData();
        open_enum_is_done :;
        setStatus(the_open_enum);
    }
示例#4
0
        public void setStatus(string chars)
        {
            TypeStatusKnownValues known     = stringToStatus(chars);
            TypeStatus            new_value = new TypeStatus();

            if (known == TypeStatusKnownValues.Status__none)
            {
                new_value.in_known_list = false;
                new_value.string_value  = chars;
            }
            else
            {
                new_value.in_known_list = true;
                new_value.list_value    = known;
            }
            setStatus(new_value);
        }
示例#5
0
        private void CompleteType(
            ITypeInitializationContext context)
        {
            if (_status == TypeStatus.Registered)
            {
                _status = TypeStatus.Completing;

                foreach (INeedsInitialization dependency in _dependencies)
                {
                    dependency.CompleteType(context);
                }

                OnCompleteType(context);

                _status = TypeStatus.Completed;
            }
        }
示例#6
0
        private void RegisterDependencies(
            ITypeInitializationContext context)
        {
            if (_status == TypeStatus.Created)
            {
                _status = TypeStatus.Registering;

                foreach (INeedsInitialization dependency in _dependencies)
                {
                    dependency.RegisterDependencies(context);
                }

                OnRegisterDependencies(context);

                _status = TypeStatus.Registered;
            }
        }
示例#7
0
                protected override void handle_result(string result)
                {
                    TypeStatusKnownValues known     = stringToStatus(result);
                    TypeStatus            new_value = new TypeStatus();

                    if (known == TypeStatusKnownValues.Status__none)
                    {
                        new_value.in_known_list = false;
                        new_value.string_value  = result;
                    }
                    else
                    {
                        new_value.in_known_list = true;
                        new_value.list_value    = known;
                    }
                    handle_result(new_value);
                }
示例#8
0
        private void  fromJSONStatus(JSONValue json_value, bool ignore_extras)
        {
            Debug.Assert(json_value != null);
            JSONStringValue json_string = json_value.string_value();

            if (json_string == null)
            {
                throw new Exception("The value for field Status of TypeNativeDataJSON is not a string.");
            }
            TypeStatus the_open_enum = new TypeStatus();

            switch (json_string.getData()[0])
            {
            case 'f':
                if ((String.Compare(json_string.getData(), 1, "ailed", 0, 5, false) == 0) && (json_string.getData().Length == 6))
                {
                    the_open_enum.in_known_list = true;
                    the_open_enum.list_value    = TypeStatusKnownValues.Status_failed;
                    goto open_enum_is_done;
                }
                break;

            case 's':
                if ((String.Compare(json_string.getData(), 1, "et", 0, 2, false) == 0) && (json_string.getData().Length == 3))
                {
                    the_open_enum.in_known_list = true;
                    the_open_enum.list_value    = TypeStatusKnownValues.Status_set;
                    goto open_enum_is_done;
                }
                break;

            default:
                break;
            }
            the_open_enum.in_known_list = false;
            the_open_enum.string_value  = json_string.getData();
            open_enum_is_done :;
            setStatus(the_open_enum);
        }
示例#9
0
 public void setStatus(TypeStatus new_value)
 {
     flagHasStatus = true;
     storeStatus   = new_value;
 }
示例#10
0
        private void  fromJSONStatus(JSONValue json_value, bool ignore_extras)
        {
            Debug.Assert(json_value != null);
            JSONStringValue json_string = json_value.string_value();

            if (json_string == null)
            {
                throw new Exception("The value for field Status of TypeNativeDataJSON is not a string.");
            }
            TypeStatus the_open_enum = new TypeStatus();

            switch (json_string.getData()[0])
            {
            case 'c':
                if ((String.Compare(json_string.getData(), 1, "ancel_cash_trip_not_allowed", 0, 27, false) == 0) && (json_string.getData().Length == 28))
                {
                    the_open_enum.in_known_list = true;
                    the_open_enum.list_value    = TypeStatusKnownValues.Status_cancel_cash_trip_not_allowed;
                    goto open_enum_is_done;
                }
                break;

            case 'f':
                if ((String.Compare(json_string.getData(), 1, "ailure", 0, 6, false) == 0) && (json_string.getData().Length == 7))
                {
                    the_open_enum.in_known_list = true;
                    the_open_enum.list_value    = TypeStatusKnownValues.Status_failure;
                    goto open_enum_is_done;
                }
                break;

            case 'n':
                if ((String.Compare(json_string.getData(), 1, "o_current_trip", 0, 14, false) == 0) && (json_string.getData().Length == 15))
                {
                    the_open_enum.in_known_list = true;
                    the_open_enum.list_value    = TypeStatusKnownValues.Status_no_current_trip;
                    goto open_enum_is_done;
                }
                break;

            case 's':
                if ((String.Compare(json_string.getData(), 1, "uccess", 0, 6, false) == 0) && (json_string.getData().Length == 7))
                {
                    the_open_enum.in_known_list = true;
                    the_open_enum.list_value    = TypeStatusKnownValues.Status_success;
                    goto open_enum_is_done;
                }
                break;

            case 'u':
                if ((String.Compare(json_string.getData(), 1, "nauthorized", 0, 11, false) == 0) && (json_string.getData().Length == 12))
                {
                    the_open_enum.in_known_list = true;
                    the_open_enum.list_value    = TypeStatusKnownValues.Status_unauthorized;
                    goto open_enum_is_done;
                }
                break;

            default:
                break;
            }
            the_open_enum.in_known_list = false;
            the_open_enum.string_value  = json_string.getData();
            open_enum_is_done :;
            setStatus(the_open_enum);
        }
        public static void GenWraps(Type[] arrEnums, Type[] arrClasses, HashSet <string> bridgeTypes)
        {
            GeneratorHelp.ClearTypeInfo();

            Dictionary <Type, TypeStatus> dict = new Dictionary <Type, TypeStatus>();
            Action <Type> onNewType            = null;

            onNewType = (nt) =>
            {
                while (true)
                {
                    if (nt.IsByRef || nt.IsArray)
                    {
                        nt = nt.GetElementType();
                        continue;
                    }
                    if (nt.IsGenericType && !nt.IsGenericTypeDefinition)
                    {
                        foreach (var ga in nt.GetGenericArguments())
                        {
                            onNewType(ga);
                        }

                        nt = nt.GetGenericTypeDefinition();
                        continue;
                    }
                    if (nt.IsGenericParameter)
                    {
                        return;
                    }
                    break;
                }

                if (!bridgeTypes.Contains(nt.FullName) &&
                    !dict.ContainsKey(nt))
                {
                    dict.Add(nt, new TypeStatus());
                }
            };

            Func <Type, TypeStatus> getParent = (type) =>
            {
                if (dict.ContainsKey(type))
                {
                    return(dict[type]);
                }
                return(null);
            };

            foreach (var type in arrEnums)
            {
                onNewType(type);
            }

            foreach (var type in arrClasses)
            {
                onNewType(type);
            }

            while (true)
            {
                Type[] keys = new Type[dict.Count];
                dict.Keys.CopyTo(keys, 0);

                foreach (Type type in keys)
                {
                    TypeStatus ts = dict[type];
                    if (ts.status != TypeStatus.Status.Wait)
                    {
                        continue;
                    }

                    if (ShouldIgnoreType(type))
                    {
                        ts.status = TypeStatus.Status.Ignored;
                        continue;
                    }

                    if (type.IsEnum)
                    {
                        GenEnum(type, ts, getParent, onNewType);
                    }
                    else if (typeof(Delegate).IsAssignableFrom(type))
                    {
                        GenDelegate(type, ts, getParent, onNewType);
                    }
                    else
                    {
                        GenInterfaceOrStructOrClass(type, ts, getParent, onNewType);
                    }
                }

                bool bContinue = false;
                foreach (var kv in dict)
                {
                    if (kv.Value.status == TypeStatus.Status.Wait)
                    {
                        bContinue = true;
                        break;
                    }
                }

                if (!bContinue)
                {
                    break;
                }
            }

            TextFile tfAll = new TextFile();

            tfAll.Add("#pragma warning disable 626, 824");
            foreach (var kv in dict)
            {
                if (kv.Value.status == TypeStatus.Status.Exported &&
                    !kv.Value.IsInnerType)
                {
                    tfAll.Add(kv.Value.tf.Ch);
                    tfAll.AddLine();
                }
            }
            tfAll.Add("#pragma warning restore 626, 824");
            File.WriteAllText(JSBindingSettings.CswFilePath, tfAll.Format(-1));
        }
        static void GenEnum(Type type, TypeStatus ts,
                            Func <Type, TypeStatus> getParent, Action <Type> onNewType)
        {
            TextFile tfFile = null;

            if (type.DeclaringType != null)
            {
                onNewType(type.DeclaringType);
                ts.IsInnerType = true;

                TypeStatus tsParent = getParent(type.DeclaringType);
                if (tsParent == null || tsParent.status == TypeStatus.Status.Wait)
                {
                    return;
                }

                if (tsParent.status == TypeStatus.Status.Ignored)
                {
                    ts.status = TypeStatus.Status.Ignored;
                    return;
                }

                tfFile = tsParent.tf.FindByTag("epos");
            }

            if (tfFile == null)
            {
                tfFile = new TextFile();
            }

            ts.tf     = tfFile;
            ts.status = TypeStatus.Status.Exported;

            //GeneratorHelp.ATypeInfo ti = GeneratorHelp.CreateTypeInfo(type);

            StringBuilder sb   = new StringBuilder();
            TextFile      tfNs = tfFile;

            if (type.DeclaringType == null &&
                !string.IsNullOrEmpty(type.Namespace))
            {
                tfNs = tfFile.Add("namespace {0}", type.Namespace).BraceIn();
                tfNs.BraceOut();
            }

            tfNs.Add("[Bridge.FileName(\"csw\")]");

            Type     uType   = Enum.GetUnderlyingType(type);
            TextFile tfClass = null;

            sb.Remove(0, sb.Length);
            {
                if (type.IsPublic || type.IsNestedPublic)
                {
                    sb.Append("public ");
                }

                sb.Append("enum ");
                sb.Append(type.Name);
                if (uType != typeof(int))
                {
                    sb.AppendFormat(" : {0}", uType.CsFullName());
                }

                tfClass = tfNs.Add(sb.ToString()).BraceIn();
                tfClass.BraceOut();
            }

            FieldInfo[] fields = type.GetFields(BindingFlags.GetField | BindingFlags.Public | BindingFlags.Static);
            for (int i = 0; i < fields.Length; i++)
            {
                FieldInfo field = fields[i];
                string    v     = "";
                if (uType == typeof(ulong))
                {
                    v = System.Convert.ToUInt64(field.GetValue(null)).ToString();
                }
                else
                {
                    v = System.Convert.ToInt64(field.GetValue(null)).ToString();
                }

                tfClass.Add("{0} = {1},", field.Name, v);
            }
        }
示例#13
0
    private void  fromJSONStatus(JSONValue json_value, bool ignore_extras)
    {
        Debug.Assert(json_value != null);
        JSONStringValue json_string = json_value.string_value();

        if (json_string == null)
        {
            throw new Exception("The value for field Status of UberCompositeRequestJSON is not a string.");
        }
        TypeStatus the_open_enum = new TypeStatus();

        switch (json_string.getData()[0])
        {
        case 'a':
            switch (json_string.getData()[1])
            {
            case 'c':
                if ((String.Compare(json_string.getData(), 2, "cepted", 0, 6, false) == 0) && (json_string.getData().Length == 8))
                {
                    the_open_enum.in_known_list = true;
                    the_open_enum.list_value    = TypeStatusKnownValues.Status_accepted;
                    goto open_enum_is_done;
                }
                break;

            case 'r':
                if ((String.Compare(json_string.getData(), 2, "riving", 0, 6, false) == 0) && (json_string.getData().Length == 8))
                {
                    the_open_enum.in_known_list = true;
                    the_open_enum.list_value    = TypeStatusKnownValues.Status_arriving;
                    goto open_enum_is_done;
                }
                break;

            default:
                break;
            }
            break;

        case 'c':
            if ((String.Compare(json_string.getData(), 1, "ompleted", 0, 8, false) == 0) && (json_string.getData().Length == 9))
            {
                the_open_enum.in_known_list = true;
                the_open_enum.list_value    = TypeStatusKnownValues.Status_completed;
                goto open_enum_is_done;
            }
            break;

        case 'd':
            if ((String.Compare(json_string.getData(), 1, "river_canceled", 0, 14, false) == 0) && (json_string.getData().Length == 15))
            {
                the_open_enum.in_known_list = true;
                the_open_enum.list_value    = TypeStatusKnownValues.Status_driver_canceled;
                goto open_enum_is_done;
            }
            break;

        case 'i':
            if ((String.Compare(json_string.getData(), 1, "n_progress", 0, 10, false) == 0) && (json_string.getData().Length == 11))
            {
                the_open_enum.in_known_list = true;
                the_open_enum.list_value    = TypeStatusKnownValues.Status_in_progress;
                goto open_enum_is_done;
            }
            break;

        case 'n':
            if ((String.Compare(json_string.getData(), 1, "o_drivers_available", 0, 19, false) == 0) && (json_string.getData().Length == 20))
            {
                the_open_enum.in_known_list = true;
                the_open_enum.list_value    = TypeStatusKnownValues.Status_no_drivers_available;
                goto open_enum_is_done;
            }
            break;

        case 'p':
            if ((String.Compare(json_string.getData(), 1, "rocessing", 0, 9, false) == 0) && (json_string.getData().Length == 10))
            {
                the_open_enum.in_known_list = true;
                the_open_enum.list_value    = TypeStatusKnownValues.Status_processing;
                goto open_enum_is_done;
            }
            break;

        case 'r':
            if ((String.Compare(json_string.getData(), 1, "ider_canceled", 0, 13, false) == 0) && (json_string.getData().Length == 14))
            {
                the_open_enum.in_known_list = true;
                the_open_enum.list_value    = TypeStatusKnownValues.Status_rider_canceled;
                goto open_enum_is_done;
            }
            break;

        default:
            break;
        }
        the_open_enum.in_known_list = false;
        the_open_enum.string_value  = json_string.getData();
        open_enum_is_done :;
        setStatus(the_open_enum);
    }
示例#14
0
 protected override void handle_result(TypeStatus result)
 {
     //@@@        Debug.Assert(!have_value);
     have_value = true;
     value      = result;
 }
        static void GenInterfaceOrStructOrClass(Type type, TypeStatus ts,
                                                Func <Type, TypeStatus> getParent, Action <Type> onNewType)
        {
            TextFile tfFile = null;

            if (type.DeclaringType != null)
            {
                ts.IsInnerType = true;

                TypeStatus tsParent = getParent(type.DeclaringType);
                if (tsParent == null || tsParent.status == TypeStatus.Status.Wait)
                {
                    if (tsParent == null)
                    {
                        onNewType(type.DeclaringType);
                    }
                    return;
                }

                if (tsParent.status == TypeStatus.Status.Ignored)
                {
                    ts.status = TypeStatus.Status.Ignored;
                    return;
                }

                tfFile = tsParent.tf.FindByTag("epos");
            }

            if (tfFile == null)
            {
                tfFile = new TextFile();
            }

            ts.tf     = tfFile;
            ts.status = TypeStatus.Status.Exported;

            GeneratorHelp.ATypeInfo ti = GeneratorHelp.CreateTypeInfo(type);

            StringBuilder sb   = new StringBuilder();
            TextFile      tfNs = tfFile;

            //string dir = Dir;

            // // ignore Experimental @eugenejiang
            // if (type.Namespace != null && type.Namespace.IndexOf("UnityEngine.Experimental.") >= 0) {
            //  return;
            // }
            if (type.DeclaringType == null &&
                !string.IsNullOrEmpty(type.Namespace))
            {
                tfNs = tfFile.Add("namespace {0}", type.Namespace).BraceIn();
                tfNs.BraceOut();
            }

            GenAttributeForClassIfNeeded(type, tfNs);

            // multiple attributes

//            tfNs.Add("[Bridge.External]");
            TextFile tfClass = null;

            sb.Remove(0, sb.Length);
            {
                // force public
                if (type.IsPublic || type.IsNestedPublic || type.IsNested || type.IsNestedFamily)
                {
                    sb.Append("public ");
                }

                // if (type.IsNestedFamily) {
                //     sb.Append("protected ");
                // }

                // if (type.FullName.IndexOf("DropdownItem") >= 0) {
                //  Debug.Assert(false);
                // }

                if (type.IsClass)
                {
                    if (type.IsAbstract && type.IsSealed)
                    {
                        sb.Append("static ");
                    }
                    //else if (type.IsAbstract)
                    //    sb.Append("abstract ");
                    //else if (type.IsSealed)
                    //    sb.Append("sealed ");

                    //if (type.is)
                }

                if (type.IsInterface)
                {
                    sb.Append("interface ");
                }
                else if (type.IsValueType)
                {
                    sb.Append("struct ");
                }
                else
                {
                    sb.Append("class ");
                }

                string className = type.CsFullName(CsNameOption.CompilableWithT);
                int    dot       = className.LastIndexOf(".");
                if (dot >= 0)
                {
                    className = className.Substring(dot + 1);
                }
                sb.Append(className);

                Type   vBaseType  = type.ValidBaseType();
                Type[] interfaces = type.GetDeclaringInterfaces();
                if (vBaseType != null || interfaces.Length > 0)
                {
                    sb.Append(" : ");

                    args a = new args();
                    if (vBaseType != null)
                    {
                        a.Add(typefn(vBaseType, type.Namespace, CsNameOption.CompilableWithT));
                        onNewType(vBaseType);
                    }
                    foreach (var i in interfaces)
                    {
                        a.Add(typefn(i, type.Namespace, CsNameOption.CompilableWithT));
                        onNewType(i);
                    }

                    sb.Append(a.ToString());
                }

                tfClass = tfNs.Add(sb.ToString()).BraceIn();
                tfClass.BraceOut();
            }

            tfClass.AddTag("epos");

            if (handleEvents(tfClass, type, onNewType))
            {
                tfClass.AddLine();
            }

            for (int i = 0; i < ti.Fields.Count; i++)
            {
                MemberInfoEx infoEx            = ti.Fields[i];
                FieldInfo    field             = infoEx.member as FieldInfo;
                var          publicOrProtected = "public";
                if (field.IsFamily)
                {
                    // publicOrProtected = "protected";
                }
                if (field.IsLiteral && !field.IsInitOnly)
                {
                    {
                        var attributes = field.GetCustomAttributes();
                        foreach (var attr in attributes)
                        {
                            tfClass.Add("[{0}]", attr.GetType().Name);
                            onNewType(attr.GetType());
                        }
                    }



                    if ("string" == typefn(field.FieldType, type.Namespace))
                    {
                        tfClass.Add(publicOrProtected + " const {0} {1} = \"{2}\";", typefn(field.FieldType, type.Namespace), field.Name, field.GetValue(null));
                    }
                    else if ("float" == typefn(field.FieldType, type.Namespace))
                    {
                        var    fv = (float)field.GetValue(null);
                        string defaultvalue;
                        if (float.IsNaN(fv))
                        {
                            defaultvalue = "float.NaN";
                        }
                        else if (float.IsPositiveInfinity(fv))
                        {
                            defaultvalue = "float.PositiveInfinity";
                        }
                        else if (float.IsNegativeInfinity(fv))
                        {
                            defaultvalue = "float.NegativeInfinity";
                        }
                        else
                        {
                            defaultvalue = fv + "f";
                        }
                        tfClass.Add(publicOrProtected + " const {0} {1} = {2};", typefn(field.FieldType, type.Namespace), field.Name, defaultvalue);
                    }
                    else
                    {
                        tfClass.Add(publicOrProtected + " const {0} {1} = {2};", typefn(field.FieldType, type.Namespace), field.Name, field.GetValue(null));
                    }
                }
                else
                {
                    tfClass.Add(publicOrProtected + " {0}{1} {2};", (field.IsStatic ? "static " : ""), typefn(field.FieldType, type.Namespace), field.Name);
                }

                onNewType(field.FieldType);
            }
            if (ti.Fields.Count > 0)
            {
                tfClass.AddLine();
            }

            // Constructors
            for (int i = 0; i < ti.Cons.Count; i++)
            {
                MemberInfoEx    infoEx = ti.Cons[i];
                ConstructorInfo con    = infoEx.member as ConstructorInfo;

                if (type.IsValueType)
                {
                    // 结构体不需要无参数构造函数
                    if (con == null || con.GetParameters().Length == 0)
                    {
                        continue;
                    }
                }

                string ctorName = type.Name;
                if (type.IsGenericTypeDefinition)
                {
                    int flag = ctorName.LastIndexOf('`');
                    if (flag >= 0)
                    {
                        ctorName = ctorName.Substring(0, flag);
                    }
                }

                var constructorBuilder = new StringBuilder();
                var paras = con == null ? "" : Ps2String(type, con.GetParameters());
                constructorBuilder.Append($"public {ctorName}({paras})");
                var baseType = type.ValidBaseType();
                if (baseType != null && !HasDefaultConstructor(baseType))
                {
                    constructorBuilder.Append($" : base({BaseConstructorParameters(baseType)})");
                }
                constructorBuilder.Append(" { throw new Exception(\"not impl\"); }");

                tfClass.Add(constructorBuilder.ToString());

                if (con != null)
                {
                    foreach (var p in con.GetParameters())
                    {
                        onNewType(p.ParameterType);
                    }
                }
            }
            if (ti.Cons.Count > 0)
            {
                tfClass.AddLine();
            }

            handlePros(tfClass, type, ti, onNewType);

            if (ti.Pros.Count > 0)
            {
                tfClass.AddLine();
            }

            handleMethods(tfClass, type, ti, onNewType);
            if (!type.IsInterface)
            {
                handleInterfaceProblems(tfClass, type, onNewType);
            }
        }
示例#16
0
 public void SetTextStatusColor(TypeStatus status)
 {
     switch (status)
     {
         case TypeStatus.Normal:
             TypeText.color = Color.black;
             break;
         case TypeStatus.Success:
             TypeText.color = Color.green;
             break;
         case TypeStatus.Error:
             TypeText.color = Color.red;
             break;
     }
 }
示例#17
0
 protected abstract void handle_result(TypeStatus result);
        static void GenDelegate(Type type, TypeStatus ts,
                                Func <Type, TypeStatus> getParent, Action <Type> onNewType)
        {
            TextFile tfFile = null;

            if (type.DeclaringType != null)
            {
                ts.IsInnerType = true;

                TypeStatus tsParent = getParent(type.DeclaringType);
                if (tsParent == null || tsParent.status == TypeStatus.Status.Wait)
                {
                    return;
                }

                if (tsParent.status == TypeStatus.Status.Ignored)
                {
                    ts.status = TypeStatus.Status.Ignored;
                    return;
                }

                tfFile = tsParent.tf.FindByTag("epos");
            }

            if (tfFile == null)
            {
                tfFile = new TextFile();
            }

            ts.tf     = tfFile;
            ts.status = TypeStatus.Status.Exported;

            StringBuilder sb   = new StringBuilder();
            TextFile      tfNs = tfFile;

            if (type.DeclaringType == null &&
                !string.IsNullOrEmpty(type.Namespace))
            {
                tfNs = tfFile.Add("namespace {0}", type.Namespace).BraceIn();
                tfNs.BraceOut();
            }

            if (type.IsPublic || type.IsNestedPublic)
            {
                sb.Append("public ");
            }

            sb.Append("delegate ");

            MethodInfo method = type.GetMethod("Invoke");

            sb.Append(typefn(method.ReturnType, type.Namespace));
            sb.Append(" ");
            onNewType(method.ReturnType);

            ParameterInfo[] ps = method.GetParameters();
            {
                sb.AppendFormat("{0}({1});",
                                // type.Name,
                                typefn(type, "no-namespace", CsNameOption.CompilableWithT),
                                Ps2String(type, ps));

                foreach (var p in ps)
                {
                    onNewType(p.ParameterType);
                }
            }

            tfNs.Add(sb.ToString());
        }
示例#19
0
 protected override void handle_result(TypeStatus result)
 {
     top.value.Add(result);
 }
        static void GenInterfaceOrStructOrClass(Type type, TypeStatus ts,
                                                Func <Type, TypeStatus> getParent, Action <Type> onNewType)
        {
            TextFile tfFile = null;

            if (type.DeclaringType != null)
            {
                ts.IsInnerType = true;

                TypeStatus tsParent = getParent(type.DeclaringType);
                if (tsParent == null || tsParent.status == TypeStatus.Status.Wait)
                {
                    return;
                }

                if (tsParent.status == TypeStatus.Status.Ignored)
                {
                    ts.status = TypeStatus.Status.Ignored;
                    return;
                }

                tfFile = tsParent.tf.FindByTag("epos");
            }

            if (tfFile == null)
            {
                tfFile = new TextFile();
            }

            ts.tf     = tfFile;
            ts.status = TypeStatus.Status.Exported;

            GeneratorHelp.ATypeInfo ti = GeneratorHelp.CreateTypeInfo(type);

            StringBuilder sb   = new StringBuilder();
            TextFile      tfNs = tfFile;

            //string dir = Dir;
            if (type.DeclaringType == null &&
                !string.IsNullOrEmpty(type.Namespace))
            {
                tfNs = tfFile.Add("namespace {0}", type.Namespace).BraceIn();
                tfNs.BraceOut();
            }

            tfNs.Add("[Bridge.FileName(\"csw\")]");

            TextFile tfClass = null;

            sb.Remove(0, sb.Length);
            {
                if (type.IsPublic || type.IsNestedPublic)
                {
                    sb.Append("public ");
                }

                if (type.IsClass)
                {
                    if (type.IsAbstract && type.IsSealed)
                    {
                        sb.Append("static ");
                    }
                    //else if (type.IsAbstract)
                    //    sb.Append("abstract ");
                    //else if (type.IsSealed)
                    //    sb.Append("sealed ");

                    //if (type.is)
                }

                if (type.IsInterface)
                {
                    sb.Append("interface ");
                }
                else if (type.IsValueType)
                {
                    sb.Append("struct ");
                }
                else
                {
                    sb.Append("class ");
                }

                string className = type.CsFullName(CsNameOption.CompilableWithT);
                int    dot       = className.LastIndexOf(".");
                if (dot >= 0)
                {
                    className = className.Substring(dot + 1);
                }
                sb.Append(className);

                Type   vBaseType  = type.ValidBaseType();
                Type[] interfaces = type.GetDeclaringInterfaces();
                if (vBaseType != null || interfaces.Length > 0)
                {
                    sb.Append(" : ");

                    args a = new args();
                    if (vBaseType != null)
                    {
                        a.Add(typefn(vBaseType, type.Namespace));
                        onNewType(vBaseType);
                    }
                    foreach (var i in interfaces)
                    {
                        a.Add(typefn(i, type.Namespace));
                        onNewType(i);
                    }

                    sb.Append(a.ToString());
                }

                tfClass = tfNs.Add(sb.ToString()).BraceIn();
                tfClass.BraceOut();
            }

            tfClass.AddTag("epos");

            for (int i = 0; i < ti.Fields.Count; i++)
            {
                MemberInfoEx infoEx = ti.Fields[i];
                FieldInfo    field  = infoEx.member as FieldInfo;
                tfClass.Add("public {0}{1} {2};", (field.IsStatic ? "static " : ""), typefn(field.FieldType, type.Namespace), field.Name);

                onNewType(field.FieldType);
            }
            if (ti.Fields.Count > 0)
            {
                tfClass.AddLine();
            }

            for (int i = 0; i < ti.Cons.Count; i++)
            {
                MemberInfoEx    infoEx = ti.Cons[i];
                ConstructorInfo con    = infoEx.member as ConstructorInfo;

                if (type.IsValueType)
                {
                    // 结构体不需要无参数构造函数
                    if (con == null || con.GetParameters().Length == 0)
                    {
                        continue;
                    }
                }

                string ctorName = type.Name;
                if (type.IsGenericTypeDefinition)
                {
                    int flag = ctorName.LastIndexOf('`');
                    if (flag >= 0)
                    {
                        ctorName = ctorName.Substring(0, flag);
                    }
                }
                tfClass.Add("public extern {0}({1});", ctorName, con == null ? "" : Ps2String(type, con.GetParameters()));

                if (con != null)
                {
                    foreach (var p in con.GetParameters())
                    {
                        onNewType(p.ParameterType);
                    }
                }
            }
            if (ti.Cons.Count > 0)
            {
                tfClass.AddLine();
            }

            handlePros(tfClass, type, ti, onNewType);

            if (ti.Pros.Count > 0)
            {
                tfClass.AddLine();
            }

            handleMethods(tfClass, type, ti, onNewType);
            if (!type.IsInterface)
            {
                handleInterfaceProblems(tfClass, type, onNewType);
            }
        }