示例#1
0
 public bool Equals(EventTypePropertyPair obj)
 {
     if (ReferenceEquals(null, obj))
     {
         return(false);
     }
     if (ReferenceEquals(this, obj))
     {
         return(true);
     }
     return(Equals(obj.propertyName, propertyName) && Equals(obj.eventType, eventType));
 }
示例#2
0
        /// <summary>
        /// Ctor.
        /// </summary>
        /// <param name="eventType">to render</param>
        /// <param name="stack">the stack of properties to avoid looping</param>
        /// <param name="options">rendering options</param>
        public RendererMeta(EventType eventType, Stack <EventTypePropertyPair> stack, RendererMetaOptions options)
        {
            var gettersSimple  = new List <GetterPair>();
            var gettersIndexed = new List <GetterPair>();
            var gettersMapped  = new List <GetterPair>();
            var gettersNested  = new List <NestedGetterPair>();

            var descriptors = eventType.PropertyDescriptors;

            foreach (EventPropertyDescriptor desc in descriptors)
            {
                String propertyName = desc.PropertyName;

                if ((!desc.IsIndexed) && (!desc.IsMapped) && (!desc.IsFragment))
                {
                    var getter = eventType.GetGetter(propertyName);
                    if (getter == null)
                    {
                        log.Warn("No getter returned for event type '" + eventType.Name + "' and property '" +
                                 propertyName + "'");
                        continue;
                    }
                    gettersSimple.Add(new GetterPair(getter, propertyName,
                                                     OutputValueRendererFactory.GetOutputValueRenderer(
                                                         desc.PropertyType, options)));
                }

                if (desc.IsIndexed && !desc.RequiresIndex && (!desc.IsFragment))
                {
                    var getter = eventType.GetGetter(propertyName);
                    if (getter == null)
                    {
                        log.Warn("No getter returned for event type '" + eventType.Name + "' and property '" +
                                 propertyName + "'");
                        continue;
                    }
                    gettersIndexed.Add(new GetterPair(getter, propertyName,
                                                      OutputValueRendererFactory.GetOutputValueRenderer(
                                                          desc.PropertyType, options)));
                }

                if (desc.IsMapped && !desc.RequiresMapKey && (!desc.IsFragment))
                {
                    var getter = eventType.GetGetter(propertyName);
                    if (getter == null)
                    {
                        log.Warn("No getter returned for event type '" + eventType.Name + "' and property '" +
                                 propertyName + "'");
                        continue;
                    }
                    gettersMapped.Add(new GetterPair(getter, propertyName,
                                                     OutputValueRendererFactory.GetOutputValueRenderer(
                                                         desc.PropertyType, options)));
                }

                if (desc.IsFragment)
                {
                    var getter       = eventType.GetGetter(propertyName);
                    var fragmentType = eventType.GetFragmentType(propertyName);
                    if (getter == null)
                    {
                        log.Warn("No getter returned for event type '" + eventType.Name + "' and property '" +
                                 propertyName + "'");
                        continue;
                    }
                    if (fragmentType == null)
                    {
                        log.Warn("No fragment type returned for event type '" + eventType.Name + "' and property '" +
                                 propertyName + "'");
                        continue;
                    }

                    var pair = new EventTypePropertyPair(fragmentType.FragmentType, propertyName);
                    if ((options.PreventLooping && stack.Contains(pair)))
                    {
                        continue; // prevent looping behavior on self-references
                    }

                    stack.Push(pair);
                    var fragmentMetaData = new RendererMeta(fragmentType.FragmentType, stack, options);
                    stack.Pop();

                    gettersNested.Add(new NestedGetterPair(getter, propertyName, fragmentMetaData,
                                                           fragmentType.IsIndexed));
                }
            }

            gettersSimple.Sort((gp1, gp2) => gp1.Name.CompareTo(gp2.Name));
            gettersIndexed.Sort((gp1, gp2) => gp1.Name.CompareTo(gp2.Name));
            gettersMapped.Sort((gp1, gp2) => gp1.Name.CompareTo(gp2.Name));
            gettersNested.Sort((gp1, gp2) => gp1.Name.CompareTo(gp2.Name));

            simpleProperties = gettersSimple.ToArray();
            indexProperties  = gettersIndexed.ToArray();
            mappedProperties = gettersMapped.ToArray();
            nestedProperties = gettersNested.ToArray();
        }