Example #1
0
        void readComplexSet(Type t, int line, string name, Map toSet)
        {
            // resolve field
            Field field = t.field(name, false);

            if (field == null)
            {
                throw err("Field not found: " + t.qname() + "." + name, line);
            }

            // parse value
            object val = readObj(field, null, false);

            try
            {
                // if const field, then make val immutable
                if (field.isConst())
                {
                    val = OpUtil.toImmutable(val);
                }
            }
            catch (System.Exception ex)
            {
                throw err("Cannot make object const for " + field.qname() + ": " + ex, line, ex);
            }

            // add to map
            toSet.set(field, val);
        }
Example #2
0
 public void verifyNotEq(object expected, object actual, string msg)
 {
     if (!OpUtil.compareNE(expected, actual))
     {
         if (msg == null)
         {
             msg = s(expected) + " == " + s(actual);
         }
         fail(msg);
     }
     verifyCount++;
 }
Example #3
0
 void complexSet(object obj, Field field, object val, int line)
 {
     try
     {
         if (field.isConst())
         {
             field.set(obj, OpUtil.toImmutable(val), false);
         }
         else
         {
             field.set(obj, val);
         }
     }
     catch (System.Exception ex)
     {
         throw err("Cannot set field " + field.qname() + ": " + ex, line, ex);
     }
 }
Example #4
0
 public void verifyEq(object expected, object actual, string msg)
 {
     if (!OpUtil.compareEQ(expected, actual))
     {
         //if (msg == null) msg = s(expected) + " != " + s(actual);
         if (msg == null)
         {
             msg = s(expected) +
                   " [" + (expected != null ? expected.GetType().ToString() : "null") + "] != "
                   + s(actual) + " [" + (actual != null ? actual.GetType().ToString() : "null") + "]";
         }
         fail(msg);
     }
     if (expected != null && actual != null)
     {
         if (hash(expected) != hash(actual))
         {
             fail("Equal but different hash codes: " +
                  expected + " (0x" + FanInt.toHex(hash(expected)) + ") ?= " +
                  actual + " (0x" + FanInt.toHex(hash(actual)) + ")");
         }
     }
     verifyCount++;
 }
Example #5
0
 public override bool Equals(object that)
 {
     if (that is List)
     {
         List x = (List)that;
         if (!m_of.Equals(x.m_of))
         {
             return(false);
         }
         if (m_size != x.m_size)
         {
             return(false);
         }
         for (int i = 0; i < m_size; i++)
         {
             if (!OpUtil.compareEQ(m_values[i], x.m_values[i]))
             {
                 return(false);
             }
         }
         return(true);
     }
     return(false);
 }
Example #6
0
        //////////////////////////////////////////////////////////////////////////
        // Complex
        //////////////////////////////////////////////////////////////////////////

        private void writeComplex(Type type, object obj, Serializable ser)
        {
            wType(type);

            bool   first  = true;
            object defObj = null;

            if (skipDefaults)
            {
                defObj = FanObj.@typeof(obj).make();
            }

            List fields = type.fields();

            for (int i = 0; i < fields.sz(); ++i)
            {
                Field f = (Field)fields.get(i);

                // skip static, transient, and synthetic (once) fields
                if (f.isStatic() || f.isSynthetic() || f.hasFacet(Sys.TransientType))
                {
                    continue;
                }

                // get the value
                object val = f.get(obj);

                // if skipping defaults
                if (defObj != null)
                {
                    object defVal = f.get(defObj);
                    if (OpUtil.compareEQ(val, defVal))
                    {
                        continue;
                    }
                }

                // if first then open braces
                if (first)
                {
                    w('\n').wIndent().w('{').w('\n'); level++; first = false;
                }

                // field name =
                wIndent().w(f.name()).w('=');

                // field value
                curFieldType = f.type().toNonNullable();
                writeObj(val);
                curFieldType = null;

                w('\n');
            }

            // if collection
            if (ser.m_collection)
            {
                first = writeCollectionItems(type, obj, first);
            }

            // if we output fields, then close braces
            if (!first)
            {
                level--; wIndent().w('}');
            }
        }
Example #7
0
 public int Compare(object a, object b)
 {
     return((int)OpUtil.compare(b, a));
 }