Exemple #1
0
        public static VisitStatus TryVisitValue <TProperty, TContainer, TValue>(this IPropertyVisitorAdapter self, IPropertyVisitor visitor, TProperty property, ref TContainer container,
                                                                                ref TValue value, ref ChangeTracker changeTracker)
            where TProperty : IProperty <TContainer, TValue>
        {
            VisitStatus status;

            if (self is IVisitAdapter <TContainer, TValue> visitAdapterTypedContainerValue)
            {
                if ((status = visitAdapterTypedContainerValue.Visit(visitor, property, ref container, ref value, ref changeTracker)) != VisitStatus.Unhandled)
                {
                    return(status);
                }
            }

            if (self is IVisitAdapter <TValue> visitAdapterTypedValue)
            {
                if ((status = visitAdapterTypedValue.Visit(visitor, property, ref container, ref value, ref changeTracker)) != VisitStatus.Unhandled)
                {
                    return(status);
                }
            }

            if (self is IVisitAdapter visitAdapter)
            {
                if ((status = visitAdapter.Visit(visitor, property, ref container, ref value, ref changeTracker)) != VisitStatus.Unhandled)
                {
                    return(status);
                }
            }

            return(VisitStatus.Unhandled);
        }
        public void AddAdapter(IPropertyVisitorAdapter adapter)
        {
            if (null == m_Adapters)
            {
                m_Adapters = new List <IPropertyVisitorAdapter>();
            }

            m_Adapters.Add(adapter);
        }
            public bool MoveNext()
            {
                if (null == m_Adapters)
                {
                    return(false);
                }

                if (m_Index >= m_Adapters.Count)
                {
                    return(false);
                }

                Current = m_Adapters[m_Index];
                ++m_Index;
                return(true);
            }
Exemple #4
0
    public static bool TryGetAdapter(Type componentType, out IPropertyVisitorAdapter visitor)
    {
        var method = componentType.GetMethod("OnEditorGUI", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

        if (method != null && method.ReturnType == typeof(void))
        {
            var args = method.GetParameters();
            if (args.Length == 1 && args[0].ParameterType == typeof(string))
            {
                var result = (Visitor)Activator.CreateInstance(typeof(Visitor <>).MakeGenericType(componentType));
                result.Init(method);
                visitor = result;
                return(true);
            }
        }
        visitor = null;
        return(false);
    }
Exemple #5
0
        public static bool TryGetAdapterForValue(Type componentType, out IPropertyVisitorAdapter visitor)
        {
            var method = componentType.GetMethod(
                nameof(IComponentEditor <int> .OnInspectorGUI),
                BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

            if (method != null && method.ReturnType == typeof(void))
            {
                var args = method.GetParameters();
                if (args.Length == 0)
                {
                    var result = (IVisitor)Activator.CreateInstance(typeof(Visitor <>).MakeGenericType(componentType));
                    result.LoadValueMethod(method);
                    visitor = result;
                    return(true);
                }
            }
            visitor = null;
            return(false);
        }
Exemple #6
0
        public static bool TryGetAdapterForClass(Type componentType, out IPropertyVisitorAdapter visitor)
        {
            MethodInfo method = null;

            if (IsSubClassOfGeneric(componentType, typeof(BufferElementDataEditor <>)))
            {
                method = componentType.GetMethods().SingleOrDefault(
                    m =>
                    m.ReturnType == typeof(void) &&
                    m.Name == nameof(IComponentEditor <int> .OnInspectorGUI) &&
                    m.GetParameters().Length == 2 &&
                    m.GetParameters()[1].ParameterType == typeof(string));
            }
            else
            {
                method = componentType.GetMethods().SingleOrDefault(
                    m =>
                    m.ReturnType == typeof(void) &&
                    m.Name == nameof(IComponentEditor <int> .OnInspectorGUI) &&
                    m.GetParameters().Length == 1);
            }

            if (method != null)
            {
                var args       = method.GetParameters();
                var targetType = args[0].ParameterType;
                var result     = (IVisitor)Activator.CreateInstance(typeof(Visitor <>).MakeGenericType(targetType));
                if (args.Length == 1)
                {
                    result.LoadClassMethod(method);
                }
                else if (args.Length == 2)
                {
                    result.LoadClassMethodWithIndex(method);
                }
                visitor = result;
                return(true);
            }
            visitor = null;
            return(false);
        }
Exemple #7
0
 /// <summary>
 /// Removes an adapter from the visitor.
 /// </summary>
 /// <param name="adapter">The adapter to remove.</param>
 public void RemoveAdapter(IPropertyVisitorAdapter adapter) => m_Adapters.Remove(adapter);
Exemple #8
0
 /// <summary>
 /// Adds an adapter to the visitor.
 /// </summary>
 /// <param name="adapter">The adapter to add.</param>
 public void AddAdapter(IPropertyVisitorAdapter adapter) => m_Adapters.Add(adapter);
Exemple #9
0
        public static VisitStatus TryVisitCollection <TProperty, TContainer, TValue>(this IPropertyVisitorAdapter self, IPropertyVisitor visitor, TProperty property, ref TContainer container, ref TValue value, ref ChangeTracker changeTracker)
            where TProperty : ICollectionProperty <TContainer, TValue>
        {
            VisitStatus status;

            if (self is IVisitAdapter <TContainer, TValue> visitAdapterTypedContainerValue)
            {
                if ((status = visitAdapterTypedContainerValue.Visit(visitor, property, ref container, ref value, ref changeTracker)) != VisitStatus.Unhandled)
                {
                    return(status);
                }
            }

            if (self is IVisitAdapter <TValue> visitAdapterTypedValue)
            {
                if ((status = visitAdapterTypedValue.Visit(visitor, property, ref container, ref value, ref changeTracker)) != VisitStatus.Unhandled)
                {
                    return(status);
                }
            }

            if (self is IVisitCollectionAdapter <TContainer, TValue> visitCollectionAdapterTypedContainerValue)
            {
                if ((status = visitCollectionAdapterTypedContainerValue.BeginCollection(visitor, property, ref container, ref value, ref changeTracker)) == VisitStatus.Handled)
                {
                    VisitCollectionElements <TProperty, TContainer, TValue>(visitor, property, ref container, changeTracker);
                }

                visitCollectionAdapterTypedContainerValue.EndCollection(visitor, property, ref container, ref value, ref changeTracker);

                if (status != VisitStatus.Unhandled)
                {
                    return(status);
                }
            }

            if (self is IVisitCollectionAdapterC <TContainer> visitCollectionAdapterTypedContainer)
            {
                if ((status = visitCollectionAdapterTypedContainer.BeginCollection(visitor, property, ref container, ref value, ref changeTracker)) == VisitStatus.Handled)
                {
                    VisitCollectionElements <TProperty, TContainer, TValue>(visitor, property, ref container, changeTracker);
                }

                visitCollectionAdapterTypedContainer.EndCollection(visitor, property, ref container, ref value, ref changeTracker);

                if (status != VisitStatus.Unhandled)
                {
                    return(status);
                }
            }

            if (self is IVisitCollectionAdapter <TValue> visitCollectionAdapterTypedValue)
            {
                if ((status = visitCollectionAdapterTypedValue.BeginCollection(visitor, property, ref container, ref value, ref changeTracker)) == VisitStatus.Handled)
                {
                    VisitCollectionElements <TProperty, TContainer, TValue>(visitor, property, ref container, changeTracker);
                }

                visitCollectionAdapterTypedValue.EndCollection(visitor, property, ref container, ref value, ref changeTracker);

                if (status != VisitStatus.Unhandled)
                {
                    return(status);
                }
            }

            if (self is IVisitCollectionAdapter visitCollectionAdapter)
            {
                if ((status = visitCollectionAdapter.BeginCollection(visitor, property, ref container, ref value, ref changeTracker)) == VisitStatus.Handled)
                {
                    VisitCollectionElements <TProperty, TContainer, TValue>(visitor, property, ref container, changeTracker);
                }

                visitCollectionAdapter.EndCollection(visitor, property, ref container, ref value, ref changeTracker);

                if (status != VisitStatus.Unhandled)
                {
                    return(status);
                }
            }

            return(VisitStatus.Unhandled);
        }
 void Reset()
 {
     m_Index = 0;
     Current = default;
 }
 public Enumerator(ReadOnlyAdapterCollection collection)
 {
     m_Adapters = collection.m_Adapters;
     m_Index    = 0;
     Current    = default;
 }