Example #1
0
        static void ConstructFromDeclaredType <TValue>(ref TValue value, ISerializedTypeProvider provider)
        {
#if !UNITY_DOTSPLAYER
            if (typeof(UnityEngine.Object).IsAssignableFrom(typeof(TValue)))
            {
                return;
            }
#endif

            if (typeof(TValue).IsArray)
            {
                var count = provider.GetArrayLength();

                if (null == value || (value as Array)?.Length != count)
                {
                    var elementType = typeof(TValue).GetElementType();

                    if (elementType == null)
                    {
                        throw new ArgumentException("Failed to construct type. Missing array element type.");
                    }

                    value = (TValue)(object)Array.CreateInstance(elementType, count);
                }

                return;
            }

            if (null == value)
            {
                value = Activator.CreateInstance <TValue>();
            }
        }
Example #2
0
        static void ConstructFromSerializedType <TValue>(ref TValue value, Type type, ISerializedTypeProvider provider)
        {
            if (type.IsArray)
            {
                var count = provider.GetArrayLength();
                value = TypeConstruction.ConstructArray <TValue>(type, count);
                return;
            }

            if (null != value && value.GetType() == type)
            {
                return;
            }

            value = TypeConstruction.Construct <TValue>(type);
        }
Example #3
0
        static void ConstructFromDeclaredType <TValue>(ref TValue value, ISerializedTypeProvider provider)
        {
            if (typeof(TValue).IsArray)
            {
                var count = provider.GetArrayLength();

                if (null == value || (value as Array)?.Length != count)
                {
                    value = TypeConstruction.ConstructArray <TValue>(count);
                    return;
                }

                return;
            }

            if (null == value)
            {
                value = TypeConstruction.Construct <TValue>();
            }
        }