IInspector GetInspector <T>()
            {
                IInspector <T> inspector = default;

                switch (Target)
                {
                case InspectorTarget.Inspector:
                    inspector = InspectorRegistry.GetInspector <T>();
                    break;

                case InspectorTarget.PropertyInspector:
                    inspector = InspectorRegistry.GetPropertyInspector <T>(Property);
                    break;

                case InspectorTarget.AttributeInspector:
                    inspector = InspectorRegistry.GetAttributeInspector <T>(Property);
                    break;

                case InspectorTarget.None:
                default:
                    throw new ArgumentOutOfRangeException();
                }

                if (null != inspector)
                {
                    inspector.Context = new InspectorContext <T>(
                        Root,
                        PropertyPath,
                        Property,
                        Property.GetAttributes()
                        );
                }

                return(inspector);
            }
Example #2
0
        IInspector GetCustomInspector <TValue>(
            IProperty property,
            ref TValue value,
            PropertyPath path,
            bool root)
        {
            if (Context.NextInspectorIsIgnored())
            {
                return(null);
            }

            if (root && Context.Root is InspectorElement)
            {
                return(InspectorRegistry.GetInspector(Context, property, ref value, path));
            }
            return(InspectorRegistry.GetAttributeInspector(Context, property, ref value, path)
                   ?? InspectorRegistry.GetPropertyInspector(Context, property, ref value, path));
        }
        public static IInspector GetInspector <TValue>(InspectorVisitor.InspectorContext inspectorContext,
                                                       IProperty property,
                                                       ref TValue value, PropertyPath path)
        {
            if (RuntimeTypeInfoCache <TValue> .CanBeNull && EqualityComparer <TValue> .Default.Equals(value, default))
            {
                return(null);
            }

            if (!RuntimeTypeInfoCache <TValue> .IsContainerType)
            {
                var inspector = InspectorRegistry.GetInspector <TValue>();
                if (null != inspector)
                {
                    inspector.Context = new InspectorContext <TValue>(
                        inspectorContext.Root,
                        path,
                        property,
                        property.GetAttributes()
                        );
                }

                return(inspector);
            }

            using (var scoped = ScopedVisitor <CustomInspectorVisitor <TValue> > .Make())
            {
                var visitor = scoped.Visitor;
                visitor.Target       = InspectorTarget.Inspector;
                visitor.PropertyPath = path;
                visitor.Root         = inspectorContext.Root;
                visitor.Property     = property;
                PropertyContainer.Accept(visitor, ref value);
                return(visitor.Inspector);
            }
        }