Fan.Sys.Map.toImmutable C# (CSharp) Méthode

toImmutable() public méthode

public toImmutable ( ) : object
Résultat object
        public override object toImmutable()
        {
            if (m_immutable) return this;

              // make safe copy
              IDictionary temp;
              if (caseInsensitive()) temp = new Hashtable(new CIEqualityComparer());
              else if (ordered()) temp = new OrderedDictionary();
              else temp = new Hashtable();

              IDictionaryEnumerator en = m_map.GetEnumerator();
              while (en.MoveNext())
              {
            object key = en.Key;
            object val = en.Value;

            if (val != null)
            {
              if (val is List)
            val = ((List)val).toImmutable();
              else if (val is Map)
            val = ((Map)val).toImmutable();
              else if (!isImmutable(val))
            throw NotImmutableErr.make("Item [" + key + "] not immutable " + @typeof(val)).val;
            }

            temp[key] = val;
              }

              // return new m_immutable m_map
              Map ro = new Map(m_type, temp);
              ro.m_isReadonly = true;
              ro.m_immutable = true;
              ro.m_caseInsensitive = m_caseInsensitive;
              ro.m_def = m_def;
              return ro;
        }

Usage Example

Exemple #1
0
        private static Map initVars()
        {
            Map vars = new Map(Sys.StrType, Sys.StrType);

            try
            {
                vars.caseInsensitive(true);

                // predefined
                vars.set("os.name", Environment.OSVersion.Platform.ToString());
                vars.set("os.version", Environment.OSVersion.Version.ToString());

                // environment variables
                IDictionary getenv = Environment.GetEnvironmentVariables();
                foreach (DictionaryEntry de in getenv)
                {
                    string key = (string)de.Key;
                    string val = (string)de.Value;
                    vars.set(key, val);
                }
            }
            catch (Exception e)
            {
                Err.dumpStack(e);
            }
            return((Map)vars.toImmutable());
        }
All Usage Examples Of Fan.Sys.Map::toImmutable