コード例 #1
0
ファイル: Array.cs プロジェクト: NinZine/playscript-mono
            public int Compare(object x, object y)
            {
                if (x == null)
                {
                    if (y == null)
                    {
                        return(0);
                    }
                    return(-1);
                }
                else if (y == null)
                {
                    return(1);
                }

                // Do the field look up before doing the normal comparison
                IDynamicClass left = x as IDynamicClass;

                if (left != null)
                {
                    x = left.__GetDynamicValue(mFieldName);
                }
                else
                {
                    var field = x.GetType().GetField(mFieldName);                       // This could be cached
                    x = field.GetValue(x);
                }

                IDynamicClass right = x as IDynamicClass;

                if (right != null)
                {
                    y = right.__GetDynamicValue(mFieldName);
                }
                else
                {
                    var field = y.GetType().GetField(mFieldName);                       // This could be cached
                    y = field.GetValue(y);
                }

                //$$TODO examine options
                var xc = x as System.IComparable;
                int result;

                if (xc != null)
                {
                    result = xc.CompareTo(y);
                }
                else
                {
                    throw new System.NotImplementedException();
                }
                return(mDescending ? -result : result);
            }
コード例 #2
0
ファイル: Array.cs プロジェクト: NinZine/playscript-mono
            public int Compare(object x, object y)
            {
                if (x == null)
                {
                    if (y == null)
                    {
                        return(0);
                    }
                    return(-1);
                }
                else if (y == null)
                {
                    return(1);
                }

                // Do the field look up before doing the normal comparison
                IDynamicClass left = x as IDynamicClass;

                if (left != null)
                {
                    x = left.__GetDynamicValue(mFieldName);
                }
                else
                {
                    var field = x.GetType().GetField(mFieldName);                       // This could be cached
                    x = field.GetValue(x);
                }

                IDynamicClass right = x as IDynamicClass;

                if (right != null)
                {
                    y = right.__GetDynamicValue(mFieldName);
                }
                else
                {
                    var field = y.GetType().GetField(mFieldName);                       // This could be cached
                    y = field.GetValue(y);
                }

                // Second check for null, this time for the field value
                if (x == null)
                {
                    if (y == null)
                    {
                        return(0);
                    }
                    return(-1);
                }
                else if (y == null)
                {
                    return(1);
                }

                // From doc:
                //	http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Vector.html#sort%28%29
                // All elements, regardless of data type, are sorted as if they were strings, so 100 precedes 99, because "1" is a lower string value than "9".
                // That's going to be slow...

                return(x.ToString().CompareTo(y.ToString()));
            }