public static void GetName()
        {
            var name      = "name";
            var attribute = new DefaultEventAttribute(name);

            Assert.Equal(name, attribute.Name);
        }
        public static void GetName()
        {
            var name = "name";
            var attribute = new DefaultEventAttribute(name);

            Assert.Equal(name, attribute.Name);
        }
        public void Default_Get_ReturnsExpected()
        {
            DefaultEventAttribute attribute = DefaultEventAttribute.Default;

            Assert.Same(attribute, DefaultEventAttribute.Default);
            Assert.Null(attribute.Name);
        }
        public static void Equals_SameName()
        {
            var name = "name";
            var firstAttribute = new DefaultEventAttribute(name);
            var secondAttribute = new DefaultEventAttribute(name);

            Assert.True(firstAttribute.Equals(secondAttribute));
        }
        public static void Equals_SameName()
        {
            var name            = "name";
            var firstAttribute  = new DefaultEventAttribute(name);
            var secondAttribute = new DefaultEventAttribute(name);

            Assert.True(firstAttribute.Equals(secondAttribute));
        }
Example #6
0
        public void DesignerAttributes_DefaultEventAttribute_EventExists(Type type, DefaultEventAttribute attribute)
        {
            var eventInfo = type.GetEvent(attribute.Name);

            _output.WriteLine($"{type.FullName}: {attribute.Name} --> {eventInfo?.Name}");

            Assert.NotNull(eventInfo);
        }
Example #7
0
        // Determine if two instances of this class are equal.
        public override bool Equals(Object obj)
        {
            DefaultEventAttribute other = (obj as DefaultEventAttribute);

            if (other != null)
            {
                return(name == other.name);
            }
            else
            {
                return(false);
            }
        }
Example #8
0
    // </Snippet1>
    // <Snippet2>
    public static int Main()
    {
        // Creates a new collection.
        MyCollection myNewCollection = new MyCollection();

        // Gets the attributes for the collection.
        AttributeCollection attributes = TypeDescriptor.GetAttributes(myNewCollection);

        /* Prints the name of the default event by retrieving the
         * DefaultEventAttribute from the AttributeCollection. */
        DefaultEventAttribute myAttribute =
            (DefaultEventAttribute)attributes[typeof(DefaultEventAttribute)];

        Console.WriteLine("The default event is: " + myAttribute.Name);
        return(0);
    }
Example #9
0
        EventDescriptor ICustomTypeDescriptor.GetDefaultEvent()
        {
            if (_readDefaultEvent == false)
            {
                _readDefaultEvent = true;

                DefaultEventAttribute attr =
                    _td.GetAttributes()[typeof(DefaultEventAttribute)] as DefaultEventAttribute;

                if (attr != null && !string.IsNullOrEmpty(attr.Name))
                {
                    _defaultEvent = _typeDescriptionProvider.GetEvent(attr.Name);
                }
            }

            return(_defaultEvent);
        }
 public DesignItemProperty GetDefaultEvent(DesignItem item)
 {
     object[] attributes = item.ComponentType.GetCustomAttributes(typeof(DefaultEventAttribute), true);
     if (attributes.Length == 1)
     {
         DefaultEventAttribute dae = (DefaultEventAttribute)attributes[0];
         var events    = TypeDescriptor.GetEvents(item.Component);
         var eventInfo = events[dae.Name];
         if (eventInfo != null)
         {
             DesignItemProperty property = item.Properties.GetProperty(dae.Name);
             if (property != null && property.IsEvent)
             {
                 return(property);
             }
         }
     }
     return(null);
 }
Example #11
0
 /// <summary>
 /// Called by internal designer host to initialize the designer.
 /// </summary>
 /// <exception cref="ArgumentOutOfRangeException">Thrown if the default event attribute is being used, but the exposed event did not exists.</exception>
 /// <param name="component"></param>
 public override void Initialize(System.ComponentModel.IComponent component)
 {
     this.component = (IElement)component;
     object[] attr = this.component.GetType().GetCustomAttributes(typeof(DefaultEventAttribute), true);
     if (attr != null && attr.Length >= 1)
     {
         DefaultEventAttribute dea = (DefaultEventAttribute)attr[0];
         EventInfo             ei  = this.component.GetType().GetEvent(dea.Name);
         if (ei != null)
         {
             ei.AddEventHandler(component, new GuruComponents.Netrix.Events.DocumentEventHandler(component_Action));
         }
         else
         {
             throw new ArgumentOutOfRangeException("The default event defined by the element's class does not exist in that element. Event: " + dea.Name);
         }
     }
     //this.component.DblClick -= new GuruComponents.Netrix.Events.DocumentEventHandler(component_DblClick);
     //this.component.DblClick += new GuruComponents.Netrix.Events.DocumentEventHandler(component_DblClick);
 }
        private static void FixUpEventNameImpl(BehaviorEventTriggerNode eventTriggerNode, SceneNode sourceNode)
        {
            if (sourceNode == null)
            {
                return;
            }
            IEnumerable <EventInformation> eventsForType = EventInformation.GetEventsForType((ITypeResolver)eventTriggerNode.ProjectContext, sourceNode.Type, MemberType.LocalEvent);

            if (!Enumerable.Any <EventInformation>(eventsForType, (Func <EventInformation, bool>)(info => info.EventName.Equals(eventTriggerNode.EventName, StringComparison.Ordinal))))
            {
                bool flag = false;
                DefaultEventAttribute defaultEventAttribute = TypeUtilities.GetAttribute <DefaultEventAttribute>(sourceNode.TargetType);
                if (defaultEventAttribute != null && !string.IsNullOrEmpty(defaultEventAttribute.Name) && (TriggerSourceInformation)Enumerable.SingleOrDefault <EventInformation>(eventsForType, (Func <EventInformation, bool>)(eventInfo => eventInfo.EventName == defaultEventAttribute.Name)) != (TriggerSourceInformation)null)
                {
                    eventTriggerNode.SetValue(BehaviorEventTriggerNode.EventNameProperty, (object)defaultEventAttribute.Name);
                    flag = true;
                }
                if (!flag && Enumerable.Any <EventInformation>(eventsForType, (Func <EventInformation, bool>)(info => info.EventName.Equals("Loaded", StringComparison.Ordinal))))
                {
                    eventTriggerNode.SetValue(BehaviorEventTriggerNode.EventNameProperty, (object)"Loaded");
                }
                else
                {
                    eventTriggerNode.ClearValue(BehaviorEventTriggerNode.EventNameProperty);
                }
            }
            ISceneNodeCollection <SceneNode> collectionForProperty = eventTriggerNode.Parent.GetCollectionForProperty(BehaviorHelper.BehaviorTriggersProperty);
            BehaviorTriggerBaseNode          matchingTriggerNode   = BehaviorHelper.FindMatchingTriggerNode(eventTriggerNode.DocumentNode, collectionForProperty);

            if (matchingTriggerNode == null || matchingTriggerNode.Equals((object)eventTriggerNode))
            {
                return;
            }
            for (int index = eventTriggerNode.Actions.Count - 1; index >= 0; --index)
            {
                BehaviorTriggerActionNode action = (BehaviorTriggerActionNode)eventTriggerNode.Actions[index];
                BehaviorHelper.ReparentAction(collectionForProperty, (BehaviorTriggerBaseNode)eventTriggerNode, matchingTriggerNode, action);
            }
            collectionForProperty.Remove((SceneNode)eventTriggerNode);
        }
        public static IEnumerable <object[]> Equals_TestData()
        {
            var attribute = new DefaultEventAttribute("name");

            yield return(new object[] { attribute, attribute, true });

            yield return(new object[] { attribute, new DefaultEventAttribute("name"), true });

            yield return(new object[] { attribute, new DefaultEventAttribute("name2"), false });

            yield return(new object[] { attribute, new DefaultEventAttribute(null), false });

            yield return(new object[] { new DefaultEventAttribute(null), new DefaultEventAttribute(null), true });

            yield return(new object[] { new DefaultEventAttribute(null), new DefaultEventAttribute("name"), false });

            yield return(new object[] { new DefaultEventAttribute(null), null, false });

            yield return(new object[] { attribute, new object(), false });

            yield return(new object[] { attribute, null, false });
        }
Example #14
0
        internal static void ShowDefaultEvent(EditingContext context)
        {
            Selection selection = context.Items.GetValue <Selection>();

            if (selection == null)
            {
                return;
            }
            ModelItem primarySelection = selection.PrimarySelection;

            if (primarySelection == null)
            {
                return;
            }
            DefaultEventAttribute defaultEventAttribute = (DefaultEventAttribute)null;

            using (IEnumerator <object> enumerator = primarySelection.GetAttributes(typeof(DefaultEventAttribute)).GetEnumerator())
            {
                if (enumerator.MoveNext())
                {
                    defaultEventAttribute = (DefaultEventAttribute)enumerator.Current;
                }
            }
            if (defaultEventAttribute == null || defaultEventAttribute.Name == null || primarySelection.Events == null)
            {
                return;
            }
            ModelEvent modelEvent = primarySelection.Events.Find(defaultEventAttribute.Name);

            if (modelEvent == null)
            {
                return;
            }
            EventBindingService service = context.Services.GetService <EventBindingService>();

            if (service == null)
            {
                return;
            }
            string methodName = (string)null;

            while (modelEvent.Handlers.Count > 0)
            {
                using (IEnumerator <string> enumerator = modelEvent.Handlers.GetEnumerator())
                {
                    if (enumerator.MoveNext())
                    {
                        methodName = enumerator.Current;
                    }
                }
                try
                {
                    service.ValidateMethodName(modelEvent, methodName);
                    break;
                }
                catch (NotSupportedException ex)
                {
                }
                modelEvent.Handlers.Remove(methodName);
                methodName = (string)null;
            }
            bool flag = false;

            foreach (string str in service.GetMethodHandlers(modelEvent))
            {
                if (methodName == null)
                {
                    methodName = str;
                    flag       = !service.AllowClassNameForMethodName();
                    break;
                }
                if (methodName == str)
                {
                    flag = true;
                    break;
                }
            }
            if (methodName == null || !flag)
            {
                if (methodName == null)
                {
                    methodName = service.CreateUniqueMethodName(modelEvent);
                    if (methodName == null)
                    {
                        return;
                    }
                }
                else
                {
                    flag = true;
                }
                if (!service.IsExistingMethodName(modelEvent, methodName) && !service.CreateMethod(modelEvent, methodName))
                {
                    return;
                }
                if (!flag && !service.AddEventHandler(modelEvent, methodName))
                {
                    modelEvent.Handlers.Add(methodName);
                }
            }
            service.ShowMethod(modelEvent, methodName);
        }
        public override bool Equals(object obj)
        {
            DefaultEventAttribute other = obj as DefaultEventAttribute;

            return((other != null) && other.Name == Name);
        }
        public void Ctor_Name(string name)
        {
            var attribute = new DefaultEventAttribute(name);

            Assert.Equal(name, attribute.Name);
        }
 public void Equals_Other_ReturnsExpected(DefaultEventAttribute attribute, object other, bool expected)
 {
     Assert.Equal(expected, attribute.Equals(other));
 }
        public void GetHashCode_InvokeMultipleTimes_ReturnsEqual()
        {
            var attribute = new DefaultEventAttribute("name");

            Assert.Equal(attribute.GetHashCode(), attribute.GetHashCode());
        }