/// <summary> /// fetches all the relevant AbstractTypeInspectors for target including fields, properties and methods. /// </summary> /// <param name="target"></param> /// <returns></returns> public static List <AbstractTypeInspector> getInspectableProperties(object target) { var props = new List <AbstractTypeInspector>(); var targetType = target.GetType(); var fields = ReflectionUtils.getFields(targetType); foreach (var field in fields) { if (!field.IsPublic && IEnumerableExt.count(field.GetCustomAttributes <InspectableAttribute>()) == 0) { continue; } if (field.IsInitOnly) { continue; } // skip enabled which is handled elsewhere if (field.Name == "enabled" || field.Name == "entity") { continue; } var inspector = getInspectorForType(field.FieldType, target, field); if (inspector != null) { inspector.setTarget(target, field); inspector.initialize(); props.Add(inspector); } } var properties = ReflectionUtils.getProperties(targetType); foreach (var prop in properties) { if (!prop.CanRead || !prop.CanWrite) { continue; } if ((!prop.GetMethod.IsPublic || !prop.SetMethod.IsPublic) && IEnumerableExt.count(prop.GetCustomAttributes <InspectableAttribute>()) == 0) { continue; } // skip Component.enabled which is handled elsewhere if (prop.Name == "enabled" || prop.Name == "entity") { continue; } var inspector = getInspectorForType(prop.PropertyType, target, prop); if (inspector != null) { inspector.setTarget(target, prop); inspector.initialize(); props.Add(inspector); } } var methods = ReflectionUtils.getMethods(targetType); foreach (var method in methods) { var attr = method.GetCustomAttribute <InspectorCallableAttribute>(); if (attr == null) { continue; } if (!MethodInspector.areParametersValid(method.GetParameters())) { continue; } var inspector = new MethodInspector(); inspector.setTarget(target, method); inspector.initialize(); props.Add(inspector); } return(props); }
/// <summary> /// fetches all the relevant AbstractTypeInspectors for target including fields, properties and methods. /// </summary> /// <param name="target"></param> /// <returns></returns> public static List <AbstractTypeInspector> getInspectableProperties(object target) { var inspectors = new List <AbstractTypeInspector>(); var targetType = target.GetType(); var isComponentSubclass = target is Component; var fields = ReflectionUtils.getFields(targetType); foreach (var field in fields) { if (field.IsStatic || field.IsDefined(notInspectableAttrType)) { continue; } var hasInspectableAttribute = field.IsDefined(inspectableAttrType); // private fields must have the InspectableAttribute if (!field.IsPublic && !hasInspectableAttribute) { continue; } // similarly, readonly fields must have the InspectableAttribute if (field.IsInitOnly && !hasInspectableAttribute) { continue; } // skip enabled and entity which is handled elsewhere if this is a Component if (isComponentSubclass && (field.Name == "enabled" || field.Name == "entity")) { continue; } var inspector = getInspectorForType(field.FieldType, target, field); if (inspector != null) { inspector.setTarget(target, field); inspector.initialize(); inspectors.Add(inspector); } } var properties = ReflectionUtils.getProperties(targetType); foreach (var prop in properties) { if (prop.IsDefined(notInspectableAttrType)) { continue; } // Transforms and Component subclasses arent useful to inspect if (prop.PropertyType == transformType || prop.PropertyType.IsSubclassOf(componentType)) { continue; } if (!prop.CanRead || prop.GetGetMethod(true).IsStatic) { continue; } var hasInspectableAttribute = prop.IsDefined(inspectableAttrType); // private props must have the InspectableAttribute if (!prop.GetMethod.IsPublic && !hasInspectableAttribute) { continue; } // similarly, readonly props must have the InspectableAttribute if (!prop.CanWrite && !hasInspectableAttribute) { continue; } // skip Component.enabled and entity which is handled elsewhere if (isComponentSubclass && (prop.Name == "enabled" || prop.Name == "entity")) { continue; } var inspector = getInspectorForType(prop.PropertyType, target, prop); if (inspector != null) { inspector.setTarget(target, prop); inspector.initialize(); inspectors.Add(inspector); } } var methods = GetAllMethodsWithAttribute <InspectorCallableAttribute>(targetType); foreach (var method in methods) { if (!MethodInspector.areParametersValid(method.GetParameters())) { continue; } var inspector = new MethodInspector(); inspector.setTarget(target, method); inspector.initialize(); inspectors.Add(inspector); } return(inspectors); }