/// <summary> /// null checks the Effect and creates an Inspector only if it is not null /// </summary> /// <returns>The effect inspector.</returns> /// <param name="target">Target.</param> /// <param name="memberInfo">Member info.</param> static Inspector GetEffectInspector(object target, MemberInfo memberInfo) { var fieldInfo = memberInfo as FieldInfo; if (fieldInfo != null) { if (fieldInfo.GetValue(target) != null) { return(new EffectInspector()); } } var propInfo = memberInfo as PropertyInfo; if (propInfo != null) { var getter = ReflectionUtils.GetPropertyGetter(propInfo); if (getter.Invoke(target, new object[] { }) != null) { return(new EffectInspector()); } } return(null); }
public void SetTarget(object target, PropertyInfo prop) { _memberInfo = prop; _target = target; _name = prop.Name; _valueType = prop.PropertyType; _getter = () => { return(ReflectionUtils.GetPropertyGetter(prop).Invoke(target, null)); }; _setter = (val) => { ReflectionUtils.GetPropertySetter(prop).Invoke(target, new object[] { val }); }; }
/// <summary> /// this version will first fetch the struct before getting/setting values on it when invoking the getter/setter /// </summary> /// <returns>The struct target.</returns> /// <param name="target">Target.</param> /// <param name="structName">Struct name.</param> /// <param name="field">Field.</param> public void SetStructTarget(object target, Inspector parentInspector, PropertyInfo prop) { _target = target; _memberInfo = prop; _name = prop.Name; _valueType = prop.PropertyType; _getter = () => { var structValue = parentInspector.GetValue(); return(ReflectionUtils.GetPropertyGetter(prop).Invoke(structValue, null)); }; _setter = (val) => { var structValue = parentInspector.GetValue(); prop.SetValue(structValue, val); parentInspector.SetValue(structValue); }; }
/// <summary> /// null checks the Material and Material.effect and ony returns an Inspector if we have data /// </summary> /// <returns>The material inspector.</returns> /// <param name="target">Target.</param> static Inspector GetMaterialInspector(object target) { var materialProp = ReflectionUtils.GetPropertyInfo(target, "Material"); var materialMethod = ReflectionUtils.GetPropertyGetter(materialProp); var material = materialMethod.Invoke(target, new object[] { }) as Material; if (material == null || material.Effect == null) { return(null); } // we only want subclasses of Effect. Effect itself is not interesting if (material.Effect.GetType().GetTypeInfo().IsSubclassOf(typeof(Effect))) { return(new EffectInspector()); } return(null); }