Esempio n. 1
0
 /// <summary>
 /// Gets information about the cast between the current type
 /// and the given type.  This value is used in overload
 /// resolution. If this is not implemented; the default
 /// values will be used.
 /// </summary>
 /// <typeparam name="T">The type to cast to.</typeparam>
 /// <param name="type">The type of cast used.</param>
 /// <param name="distance">The type distance for the given cast.</param>
 /// <exception cref="System.NotSupportedException">If custom
 /// type distance is not implemented.</exception>
 /// <remarks>
 /// The distance must be a non-negative number.  The same value
 /// means an equivilent cast.  A larger number means that it is
 /// further away.  When determining overload resolution, a
 /// smaller value is attempted.  They are only used for
 /// comparison; their value is never used directly.
 /// </remarks>
 void ILuaValue.GetCastInfo <T>(out LuaCastType type, out int distance)
 {
     distance = 0;
     if (typeof(T).IsAssignableFrom(GetType()))
     {
         type = LuaCastType.SameType;
     }
     else
     {
         type = LuaCastType.NoCast;
     }
 }
Esempio n. 2
0
        public virtual void GetCastInfo <T>(out LuaCastType type, out int distance)
        {
            if (typeof(T).IsAssignableFrom(GetType()))
            {
                distance = 0;
                type     = LuaCastType.BaseClass;
                return;
            }

            // Sometimes this will return |this|; assume this is intended behavior.
            var value = GetValue();

            if (value == null)
            {
                type     = typeof(T).IsValueType ? LuaCastType.NoCast : LuaCastType.SameType;
                distance = 0;
                return;
            }

            type = Helpers.TypesCompatible(value.GetType(), typeof(T), out _, out distance);
        }