Exemplo n.º 1
0
 public void putAllTreeMap(TreeMap <K, V> _m)
 {
     //setModified();
     foreach (Entry <K, V> e in _m.entryList())
     {
         put(e.getKey(), e.getValue());
     }
 }
Exemplo n.º 2
0
        public static Type dynamicClassForName(Assembly _assembly, String _name)
        {
            TreeMap <MyList <int>, String> types_;
            int    indexDot_ = _name.IndexOf(".");
            string libType_  = _name.Substring(0, indexDot_);
            string typeName_ = _name.Substring(indexDot_ + 1);

            types_ = new TreeMap <MyList <int>, string>(new ComparatorNumberList());
            types_.put(new MyList <int>(0), libType_ + " " + typeName_);
            TreeMap <MyList <int>, Type> typesBuilt_;

            typesBuilt_ = new TreeMap <MyList <int>, Type>(new ComparatorNumberList());
            if (_assembly == null)
            {
                Assembly as_ = Assembly.Load(libType_);
                typesBuilt_.put(new MyList <int>(0), as_.GetType(typeName_, false));
            }
            else
            {
                try
                {
                    typesBuilt_.put(new MyList <int>(0), _assembly.GetType(typeName_, true));
                }
                catch (Exception)
                {
                    Assembly as_ = Assembly.Load(libType_);
                    typesBuilt_.put(new MyList <int>(0), as_.GetType(typeName_, false));
                }
            }
            //typesBuilt_.put(new MyList<int>(0), null);
            int deep_ = 0;

            while (true)
            {
                bool containsBracket_ = false;
                foreach (IEntry <MyList <int>, string> e in types_.entryList())
                {
                    if (e.getValue().Contains("["))
                    {
                        containsBracket_ = true;
                        break;
                    }
                }
                if (!containsBracket_)
                {
                    break;
                }
                deep_++;
                foreach (MyList <int> k in types_.getKeys())
                {
                    String     v_        = types_.getVal(k);
                    StringList typesStr_ = StringList.getTypes(v_);

                    /*foreach (string t in typesStr_) {
                     *  Console.WriteLine("%" + t);
                     * }*/
                    string prefix_ = v_;
                    int    index_  = v_.IndexOf("[");
                    if (index_ >= 0)
                    {
                        prefix_ = v_.Substring(0, index_);
                        types_.put(k, prefix_);
                        if (_assembly == null)
                        {
                            libType_ = prefix_.Split(' ').ElementAt(0);
                            Assembly as_ = Assembly.Load(libType_);
                            typeName_ = prefix_.Split(' ').ElementAt(1);
                            typesBuilt_.put(k, as_.GetType(typeName_, false));
                        }
                        else
                        {
                            try
                            {
                                typeName_ = prefix_.Split(' ').ElementAt(1);
                                typesBuilt_.put(k, _assembly.GetType(typeName_, true));
                            }
                            catch (Exception)
                            {
                                libType_ = prefix_.Split(' ').ElementAt(0);
                                Assembly as_ = Assembly.Load(libType_);
                                typeName_ = prefix_.Split(' ').ElementAt(1);
                                typesBuilt_.put(k, as_.GetType(typeName_, false));
                            }
                        }
                        int indexType_ = 0;
                        foreach (string t in typesStr_)
                        {
                            string t_ = t.Trim();
                            t_ = t_.Substring(1, t_.Length - 2);
                            MyList <int> l_ = new MyList <int>(k);
                            l_.Add(indexType_);
                            int    lastIndex_ = t_.LastIndexOf(',');
                            string as_        = t_.Substring(lastIndex_ + 2);
                            string type_      = t_.Substring(0, lastIndex_);
                            types_.put(l_, as_ + " " + type_);
                            if (_assembly == null)
                            {
                                typesBuilt_.put(l_, Assembly.Load(as_).GetType(type_, false));
                            }
                            else
                            {
                                try
                                {
                                    typesBuilt_.put(l_, _assembly.GetType(type_, true));
                                }
                                catch (Exception)
                                {
                                    typesBuilt_.put(l_, Assembly.Load(as_).GetType(type_, false));
                                }
                            }
                            indexType_++;
                        }
                    }
                }
            }

            /*foreach (MyList<int> k in typesBuilt_.getKeys())
             * {
             *  Console.WriteLine(k.join(",")+";"+ typesBuilt_.getVal(k));
             * }*/
            //deep_--;
            //Console.WriteLine(deep_);
            //Type typeRet_ = null;
            while (true)
            {
                if (types_.size() == 1)
                {
                    break;
                }
                foreach (MyList <int> k in types_.getKeys())
                {
                    if (k.size() != deep_)
                    {
                        continue;
                    }
                    Type          type_        = typesBuilt_.getVal(k);
                    MyList <Type> typesStruct_ = new MyList <Type>();
                    foreach (MyList <int> s in types_.getKeys())
                    {
                        if (s.size() != deep_ + 1)
                        {
                            continue;
                        }
                        bool startsWith_ = true;
                        for (int i = 0; i < deep_; i++)
                        {
                            if (k.get(i) != s.get(i))
                            {
                                startsWith_ = false;
                                break;
                            }
                        }
                        if (!startsWith_)
                        {
                            continue;
                        }
                        types_.removeKey(s);
                        typesStruct_.Add(typesBuilt_.getVal(s));
                    }
                    //Console.WriteLine("%" + k+"%"+ type_);
                    if (!type_.IsGenericType)
                    {
                        continue;
                    }
                    typesBuilt_.put(k, type_.MakeGenericType(typesStruct_.ToArray()));
                }
                deep_--;
            }
            return(typesBuilt_.getValue(0));
        }