public void SetValue(object target, object value)
        {
            if (OptimizedReflection.safeMode)
            {
                OptimizedReflection.VerifyStaticTarget(targetType, target);

                if (setter == null)
                {
                    throw new TargetException($"The field '{targetType}.{fieldInfo.Name}' cannot be assigned.");
                }

                if (!typeof(TField).IsAssignableFrom(value))
                {
                    throw new ArgumentException($"The provided value for '{targetType}.{fieldInfo.Name}' does not match the field type.\nProvided: {value?.GetType()?.ToString() ?? "null"}\nExpected: {typeof(TField)}");
                }

                try
                {
                    SetValueUnsafe(target, value);
                }
                catch (TargetInvocationException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    throw new TargetInvocationException(ex);
                }
            }
            else
            {
                SetValueUnsafe(target, value);
            }
        }
        public object GetValue(object target)
        {
            if (OptimizedReflection.safeMode)
            {
                OptimizedReflection.VerifyStaticTarget(targetType, target);

                if (getter == null)
                {
                    throw new TargetException($"The property '{targetType}.{propertyInfo.Name}' has no get accessor.");
                }

                try
                {
                    return(GetValueUnsafe(target));
                }
                catch (TargetInvocationException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    throw new TargetInvocationException(ex);
                }
            }
            else
            {
                return(GetValueUnsafe(target));
            }
        }
示例#3
0
        public void SetValue(object target, object value)
        {
            if (OptimizedReflection.safeMode)
            {
                OptimizedReflection.VerifyInstanceTarget <TTarget>(target);

                if (setter == null)
                {
                    throw new TargetException($"The property '{typeof(TTarget)}.{propertyInfo.Name}' has no set accessor.");
                }

                if (!typeof(TProperty).IsAssignableFrom(value))
                {
                    throw new ArgumentException($"The provided value for '{typeof(TTarget)}.{propertyInfo.Name}' does not match the property type.\nProvided: {value?.GetType()?.ToString() ?? "null"}\nExpected: {typeof(TProperty)}");
                }

                try
                {
                    SetValueUnsafe(target, value);
                }
                catch (TargetInvocationException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    throw new TargetInvocationException(ex);
                }
            }
            else
            {
                SetValueUnsafe(target, value);
            }
        }
示例#4
0
        private static void RuntimeInitializeOnLoadBeforeSceneLoad()
        {
            UnityThread.RuntimeInitialize();

            Ensure.OnRuntimeMethodLoad();

            Recursion.OnRuntimeMethodLoad();

            OptimizedReflection.OnRuntimeMethodLoad();

            SavedVariables.OnEnterPlayMode();

            ApplicationVariables.OnEnterPlayMode();

            ReferenceCollector.Initialize();
        }
        public object GetValue(object target)
        {
            if (OptimizedReflection.safeMode)
            {
                OptimizedReflection.VerifyStaticTarget(targetType, target);

                try
                {
                    return(GetValueUnsafe(target));
                }
                catch (TargetInvocationException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    throw new TargetInvocationException(ex);
                }
            }
            else
            {
                return(GetValueUnsafe(target));
            }
        }
示例#6
0
 protected override void VerifyTarget(object target)
 {
     OptimizedReflection.VerifyInstanceTarget <TTarget>(target);
 }
 protected override void VerifyTarget(object target)
 {
     OptimizedReflection.VerifyStaticTarget(targetType, target);
 }