From 9e754b4e588ed9f3cda3613c897bac86533b09c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20=22Intentor=22=20Martins?= Date: Wed, 1 Mar 2017 08:14:29 -0300 Subject: [PATCH] Update evaluation of null values [Issue #73] --- .../Adic/Scripts/Framework/Injection/Injector.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Assets/Adic/Scripts/Framework/Injection/Injector.cs b/src/Assets/Adic/Scripts/Framework/Injection/Injector.cs index 9640463..bef51d7 100644 --- a/src/Assets/Adic/Scripts/Framework/Injection/Injector.cs +++ b/src/Assets/Adic/Scripts/Framework/Injection/Injector.cs @@ -339,7 +339,10 @@ protected void InjectFields(object instance, AcessorInfo[] fields) { var field = fields[fieldIndex]; var value = field.getter(instance); - if (value == null || "null".Equals(value.ToString())) { + + //The Equals(null) comparison is used to ensure correct null evaluation due to the null trick + //Unity uses for objects derived from UnityEngine.Object. + if (value == null || value.Equals(null)) { var valueToSet = this.Resolve(field.type, InjectionMember.Field, field.name, instance, field.identifier, false); field.setter(instance, valueToSet); @@ -360,7 +363,10 @@ protected void InjectProperties(object instance, AcessorInfo[] properties) { var property = properties[propertyIndex]; var value = property.getter == null ? null : property.getter(instance); - if (value == null || "null".Equals(value.ToString())) { + + //The Equals(null) comparison is used to ensure correct null evaluation due to the null trick + //Unity uses for objects derived from UnityEngine.Object. + if (value == null || value.Equals(null)) { var valueToSet = this.Resolve(property.type, InjectionMember.Property, property.name, instance, property.identifier, false); property.setter(instance, valueToSet);