예제 #1
0
        public static int IndexOfReference <TValue>(this InlinedArray <TValue> array, TValue value)
            where TValue : class
        {
            for (var i = 0; i < array.length; ++i)
            {
                if (ReferenceEquals(array[i], value))
                {
                    return(i);
                }
            }

            return(-1);
        }
예제 #2
0
        public static bool ContainsReference <TValue>(this InlinedArray <TValue> array, TValue value)
            where TValue : class
        {
            for (var i = 0; i < array.length; ++i)
            {
                if (ReferenceEquals(array[i], value))
                {
                    return(true);
                }
            }

            return(false);
        }
        public static void InvokeCallbacksSafe <TValue1, TValue2>(ref InlinedArray <Action <TValue1, TValue2> > callbacks, TValue1 argument1, TValue2 argument2, string callbackName)
        {
            for (var i = 0; i < callbacks.length; ++i)
            {
                var lengthBefore = callbacks.length;

                try
                {
                    callbacks[i](argument1, argument2);
                }
                catch (Exception exception)
                {
                    Debug.LogError($"{exception.GetType().Name} while executing '{callbackName}' callbacks");
                    Debug.LogException(exception);
                }

                ////REVIEW: is this enough?
                if (callbacks.length == lengthBefore - 1)
                {
                    --i;
                }
            }
        }
예제 #4
0
        public void Merge(InlinedArray <TValue> other)
        {
            var comparer = EqualityComparer <TValue> .Default;

            for (var i = 0; i < other.length; ++i)
            {
                var value = other[i];
                if (Contains(value, comparer))
                {
                    continue;
                }

                ////FIXME: this is ugly as it repeatedly copies
                Append(value);
            }
        }
예제 #5
0
 public static bool ContainsReference <TValue>(this InlinedArray <TValue> array, TValue value)
     where TValue : class
 {
     return(IndexOfReference(array, value) != -1);
 }