Пример #1
0
        public System.Collections.ICollection GetCompatibleMethods(System.ComponentModel.EventDescriptor e)
        {
            MethodInfo       mi = e.EventType.GetMethod("Invoke");
            CodeMemberMethod methodSignature = MonoDevelop.DesignerSupport.BindingService.ReflectionToCodeDomMethod(mi);

            return(proxy.GetCompatibleMethodsInCodeBehind(methodSignature));
        }
    internal DataItemEventDescriptor(
      DataItemTypeDescriptor owner,
      EventDescriptor parent,
      Type componentType,
      Type eventType,
      Action<object, object> addHandler,
      Action<object, object> removeHandler )
      : base( owner, parent )
    {
      if( componentType == null )
        throw new ArgumentNullException( "componentType" );

      if( eventType == null )
        throw new ArgumentNullException( "eventType" );

      if( addHandler == null )
        throw new ArgumentNullException( "addHandler" );

      if( removeHandler == null )
        throw new ArgumentNullException( "removeHandler" );

      m_componentType = componentType;
      m_eventType = eventType;
      m_addHandler = addHandler;
      m_removeHandler = removeHandler;
    }
    public int Add(EventDescriptor value)
    {
      Contract.Ensures(0 <= Contract.Result<int>());
      Contract.Ensures(Contract.Result<int>() <= 2147483646);

      return default(int);
    }
		protected override ICollection GetCompatibleMethods(EventDescriptor e)
		{
			ITypeDefinition definition = loader.GetPrimaryTypeDefinition();
			ArrayList compatibleMethods = new ArrayList();
			MethodInfo methodInfo = e.EventType.GetMethod("Invoke");
			var methodInfoParameters = methodInfo.GetParameters();
			
			foreach (IMethod method in definition.Methods) {
				if (method.Parameters.Count == methodInfoParameters.Length) {
					bool found = true;
					for (int i = 0; i < methodInfoParameters.Length; ++i) {
						ParameterInfo pInfo = methodInfoParameters[i];
						IParameter p = method.Parameters[i];
						if (p.Type.ReflectionName != pInfo.ParameterType.ToString()) {
							found = false;
							break;
						}
					}
					if (found) {
						compatibleMethods.Add(method.Name);
					}
				}
			}
			
			return compatibleMethods;
		}
Пример #5
0
 public System.ComponentModel.PropertyDescriptor GetEventProperty(System.ComponentModel.EventDescriptor e)
 {
     if (e == null)
     {
         throw new ArgumentNullException("e");
     }
     return(new EventPropertyDescriptor(e));
 }
		protected override bool ShowCode(IComponent component, EventDescriptor edesc, string methodName)
		{
			if (formDesigner != null) {
				formDesigner.ShowSourceCode(component, edesc, methodName);
				return true;
			}
			return false;
		}
    protected DataItemEventDescriptorBase( DataItemTypeDescriptor owner, EventDescriptor parent )
      : base( parent )
    {
      if( owner == null )
        throw new ArgumentNullException( "owner" );

      m_owner = owner;
    }
 ICollection IEventBindingService.GetCompatibleMethods(EventDescriptor e)
 {
     if (e == null)
     {
         throw new ArgumentNullException("e");
     }
     return this.GetCompatibleMethods(e);
 }
Пример #9
0
		string IEventBindingService.CreateUniqueMethodName (IComponent component, EventDescriptor eventDescriptor)
		{
			if (eventDescriptor == null)
				throw new ArgumentNullException ("eventDescriptor");
			if (component == null)
				throw new ArgumentNullException ("component");

			return this.CreateUniqueMethodName (component, eventDescriptor);
		}
Пример #10
0
		public ReflectionEventDescriptor (Type componentType, EventDescriptor oldEventDescriptor, Attribute[] attrs) : base (oldEventDescriptor, attrs)
		{
			_componentType = componentType;
			_eventType = oldEventDescriptor.EventType;

			EventInfo event_info = componentType.GetEvent (oldEventDescriptor.Name);
			add_method = event_info.GetAddMethod ();
			remove_method = event_info.GetRemoveMethod ();
		}
		EventDescriptorCollection (EventDescriptor[] events, bool readOnly) 
		{
			this.isReadOnly = readOnly;
			if (events == null)
				return;

			for (int i = 0; i < events.Length; i++)
				this.Add (events[i]);
		}
 public int Add(EventDescriptor value)
 {
     if (this.readOnly)
     {
         throw new NotSupportedException();
     }
     this.EnsureSize(this.eventCount + 1);
     this.events[this.eventCount++] = value;
     return (this.eventCount - 1);
 }
 private string GetEventDescriptorHashCode(EventDescriptor eventDesc)
 {
     StringBuilder builder = new StringBuilder(eventDesc.Name);
     builder.Append(eventDesc.EventType.GetHashCode().ToString(CultureInfo.InvariantCulture));
     foreach (Attribute attribute in eventDesc.Attributes)
     {
         builder.Append(attribute.GetHashCode().ToString(CultureInfo.InvariantCulture));
     }
     return builder.ToString();
 }
Пример #14
0
		public string CreateUniqueMethodName (IComponent component, EventDescriptor e)
		{
			if (component.Site == null || component.Site.Name == null)
				throw new ArgumentException ("IComponent must be sited and named");
			
			//TODO: check component.Site.Name is valid as start of method name
			string trialPrefix = component.Site.Name + "_" + e.Name;
			
			return proxy.GenerateIdentifierUniqueInCodeBehind (trialPrefix);
		}
	// Constructors.
	public EventDescriptorCollection(EventDescriptor[] events)
			{
				list = new ArrayList();
				if(events != null)
				{
					foreach(EventDescriptor descr in events)
					{
						list.Add(descr);
					}
				}
			}
Пример #16
0
 /// <devdoc>
 ///    <para>
 ///       Initializes a new instance of the <see cref='System.ComponentModel.EventDescriptorCollection'/> class.
 ///    </para>
 /// </devdoc>
 public EventDescriptorCollection(EventDescriptor[] events) {
     this.events = events;
     if (events == null) {
         this.events = new EventDescriptor[0];
         this.eventCount = 0;
     }
     else {
         this.eventCount = this.events.Length;
     }
     this.eventsOwned = true;
 }
Пример #17
0
		protected override bool ShowCode(IComponent component, EventDescriptor edesc, string methodName)
		{
			// There were reports of an ArgumentNullException caused by edesc==null.
			// Looking at the .NET code calling this method, this can happen when there are two calls to ShowCode() before the Application.Idle
			// event gets raised. In that case, ShowCode() already was called for the second set of arguments, and we can safely ignore
			// the call with edesc==null.
			if (formDesigner != null && edesc != null) {
				formDesigner.ShowSourceCode(component, edesc, methodName);
				return true;
			}
			return false;
		}
Пример #18
0
 private EventDescriptorCollection(EventDescriptor[] events, int eventCount, string[] namedSort, IComparer comparer)
 {
     _eventsOwned = false;
     if (namedSort != null)
     {
         _namedSort = (string[])namedSort.Clone();
     }
     _comparer = comparer;
     _events = events;
     _eventCount = eventCount;
     _needSort = true;
 }
Пример #19
0
        public EventPropertyDescriptor(EventDescriptor eventDesc, IServiceProvider serviceProvider)
            : base(eventDesc)
        {
            _eventDescriptor = eventDesc;
            _serviceProvider = serviceProvider;

            FieldInfo eventFieldInfo = _eventDescriptor.ComponentType.GetField(_eventDescriptor.Name + "Event");
            if (eventFieldInfo != null)
            {
                _eventProperty = eventFieldInfo.GetValue(_eventDescriptor.ComponentType) as DependencyProperty;
            }
        }
 public ReflectEventDescriptor(Type componentType, EventDescriptor oldReflectEventDescriptor, Attribute[] attributes) : base(oldReflectEventDescriptor, attributes)
 {
     this.componentClass = componentType;
     this.type = oldReflectEventDescriptor.EventType;
     ReflectEventDescriptor descriptor = oldReflectEventDescriptor as ReflectEventDescriptor;
     if (descriptor != null)
     {
         this.addMethod = descriptor.addMethod;
         this.removeMethod = descriptor.removeMethod;
         this.filledMethods = true;
     }
 }
Пример #21
0
 /// <summary>
 ///    <para>
 ///       Initializes a new instance of the <see cref='System.ComponentModel.EventDescriptorCollection'/> class.
 ///    </para>
 /// </summary>
 public EventDescriptorCollection(EventDescriptor[] events)
 {
     if (events == null)
     {
         _events = Array.Empty<EventDescriptor>();
     }
     else
     {
         _events = events;
         Count = events.Length;
     }
     _eventsOwned = true;
 }
        public override EventDescriptorCollection GetEvents()
        {
            var coll = base.GetEvents();
            var list = new EventDescriptor[coll.Count];

            for (int i = 0; i < coll.Count; i++)
                if (coll[i].Name == "TextChanged")//instead of TextChanged slip BindingTextChanged for binding
                    list[i] = new FooTextChangedDescriptor(coll[i]);
                else
                    list[i] = coll[i];

            return new EventDescriptorCollection(list);
        }
Пример #23
0
        private List<Attribute> CopyAttributes(EventDescriptor descriptor, params Type[] exclusions)
        {
            List<Attribute> ret = new List<Attribute>();
            List<Type> exclusionList = new List<Type>(exclusions);

            foreach (Attribute att in descriptor.Attributes)
            {
                if (!exclusionList.Contains(att.GetType()))
                {
                    ret.Add(att);
                }
            }
            return ret;
        }
Пример #24
0
        public System.Collections.ICollection GetCompatibleMethods(System.ComponentModel.EventDescriptor e)
        {
            ParameterInfo[] pi = GetEventParameters(e);

            ArrayList arr = new ArrayList();

            foreach (DictionaryEntry de in eventHandlers)
            {
                if ((ParameterInfo[])de.Value == pi)
                {
                    arr.Add(de.Key);
                }
            }

            return(arr.ToArray(typeof(string)));
        }
    internal ValueChangeDataItemPropertyDescriptor(
      DataItemTypeDescriptor owner,
      PropertyDescriptor parent,
      Type componentType,
      Type propertyType,
      Func<object, object> getter,
      Action<object, object> setter,
      Action<object> resetter,
      EventDescriptor eventDescriptor )
      : base( owner, parent, componentType, propertyType, getter, setter, resetter )
    {
      if( eventDescriptor == null )
        throw new ArgumentNullException( "eventDescriptor" );

      m_eventDescriptor = eventDescriptor;
      m_eventProxy = new EventProxy( this, eventDescriptor );
    }
Пример #26
0
		public Delegate CreateActionDelegate(Type genericEventHandlerType, EventDescriptor eventDescriptor,
		                                     BindingContext context)
		{
			Type eventArgsType = EventUtil.GetEventArgsType(eventDescriptor);
			EventHandlerInfo eventHandlerInfo =
				GetEventHandlerInfo(genericEventHandlerType, eventArgsType);

			if (eventHandlerInfo != null)
			{
				object eventHandler = Activator.CreateInstance(
					eventHandlerInfo.EventHandlerType, new object[] {context});

				return Delegate.CreateDelegate(eventDescriptor.EventType, eventHandler,
				                               eventHandlerInfo.EventMethod);
			}

			return null;
		}
Пример #27
0
        public string CreateUniqueMethodName(IComponent component, EventDescriptor e)
        {
            if (component.Site == null || component.Site.Name == null)
                throw new ArgumentException ("IComponent must be sited and named");

            //TODO: check component.Site.Name is valid as start of method name
            string trialPrefix = component.Site.Name + "_" + e.Name;
            string trialValue = trialPrefix;

            for (int suffix = 1; suffix <= int.MaxValue; suffix++)
            {
                if (!eventHandlers.ContainsKey (trialValue))
                    return trialValue;

                trialValue = trialPrefix + suffix.ToString ();
            }

            throw new Exception ("Tried method names up to " + trialValue + " and all already existed");
        }
Пример #28
0
        public bool ShowCode(System.ComponentModel.IComponent component, System.ComponentModel.EventDescriptor e)
        {
            PropertyDescriptor pd   = GetEventProperty(e);
            string             name = (string)pd.GetValue(component);

            if (name == null)
            {
                name = CreateUniqueMethodName(component, e);
                pd.SetValue(component, name);
            }

            MethodInfo       mi = e.EventType.GetMethod("Invoke");
            CodeMemberMethod methodSignature = MonoDevelop.DesignerSupport.BindingService.ReflectionToCodeDomMethod(mi);

            methodSignature.Name       = name;
            methodSignature.Attributes = MemberAttributes.Family;

            return(proxy.ShowMethod(methodSignature));
        }
        public ICollection GetCompatibleMethods(EventDescriptor e)
        {
            List<String> compatibleMethods = new List<string>();

            IDesignerHost designerHost = _serviceProvider.GetService(typeof(IDesignerHost)) as IDesignerHost;
            if (designerHost == null || designerHost.RootComponent == null)
            {
                return compatibleMethods;
            }

            EventInfo eventInfo = e.ComponentType.GetEvent(e.Name);
            ParameterInfo[] eventParameters = null;
            if (eventInfo != null)
            {
                MethodInfo invokeMethod = eventInfo.EventHandlerType.GetMethod("Invoke");
                if (invokeMethod != null)
                {
                    eventParameters = invokeMethod.GetParameters();
                }
            }

            if (eventParameters != null)
            {
                Type rootType = designerHost.RootComponent.GetType();
                MethodInfo[] methods = rootType.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly);

                foreach (MethodInfo method in methods)
                {
                    ParameterInfo[] parameters = method.GetParameters();
                    if (parameters.Length == eventParameters.Length)
                    {
                        if (IsCandidateMethod(eventParameters, parameters))
                        {
                            compatibleMethods.Add(method.Name);
                        }
                    }
                }

                compatibleMethods.Add("[Clear]");
            }

            return compatibleMethods;
        }
		protected override string CreateUniqueMethodName (IComponent component, EventDescriptor eventDescriptor)
		{
			string name = component.Site.Name + eventDescriptor.Name;
			ICollection compatibleMethodNames = this.GetCompatibleMethods (eventDescriptor);
			bool interrupt = false;
			int i = 0;
			while (!interrupt) {
				string tmpName = name;
				foreach (string existingName in compatibleMethodNames) {
					if (existingName == tmpName)
						tmpName += i.ToString ();
					else {
						name = tmpName;
						interrupt = true;
					}
				}
				i++;
			}
			return null;
		}
Пример #31
0
		internal void SetDataSource (object new_data_source)
		{
			if (changed_event != null)
				changed_event.RemoveEventHandler (data_source, property_value_changed_handler);

			data_source = new_data_source;

			if (property_name != null) {
				prop_desc = TypeDescriptor.GetProperties (data_source).Find (property_name, true);

				if (prop_desc == null)
					return;

				changed_event = TypeDescriptor.GetEvents (data_source).Find (property_name + "Changed", false);
				if (changed_event != null) {
					property_value_changed_handler = new EventHandler (PropertyValueChanged);
					changed_event.AddEventHandler (data_source, property_value_changed_handler);
				}
			}
		}
Пример #32
0
 string IEventBindingService.CreateUniqueMethodName(IComponent component, EventDescriptor e)
 {
     TextBuffer buffer;
     ICodeBehindDocumentLanguage codeDocumentLanguage = this.GetCodeDocumentLanguage() as ICodeBehindDocumentLanguage;
     if (codeDocumentLanguage == null)
     {
         return string.Empty;
     }
     IMultiViewDocumentWindow documentWindow = this.GetDocumentWindow();
     CodeView codeView = this.GetCodeView(documentWindow);
     if (codeView.Text.Length != 0)
     {
         buffer = codeView.Buffer;
     }
     else
     {
         IDocumentWithCode code = base.Component as IDocumentWithCode;
         buffer = new TextBuffer(code.Code.Text);
     }
     return codeDocumentLanguage.GenerateEventHandlerName(buffer, component, e);
 }
Пример #33
0
 ICollection IEventBindingService.GetCompatibleMethods(EventDescriptor e)
 {
     TextBuffer buffer;
     ICodeBehindDocumentLanguage codeDocumentLanguage = this.GetCodeDocumentLanguage() as ICodeBehindDocumentLanguage;
     if (codeDocumentLanguage == null)
     {
         return new string[0];
     }
     IMultiViewDocumentWindow documentWindow = this.GetDocumentWindow();
     CodeView codeView = this.GetCodeView(documentWindow);
     if (codeView.Text.Length != 0)
     {
         buffer = codeView.Buffer;
     }
     else
     {
         IDocumentWithCode component = base.Component as IDocumentWithCode;
         buffer = new TextBuffer(component.Code.Text);
     }
     return codeDocumentLanguage.GetEventHandlers(buffer, e);
 }
Пример #34
0
 string ICodeBehindDocumentLanguage.GenerateEventHandlerName(TextBuffer buffer, IComponent component, EventDescriptor eventDescriptor)
 {
     bool flag = false;
     if (buffer == null)
     {
         throw new ArgumentNullException("buffer");
     }
     if (component == null)
     {
         throw new ArgumentNullException("component");
     }
     if (component.Site == null)
     {
         throw new ArgumentException("Invalid component", "component");
     }
     if (eventDescriptor == null)
     {
         throw new ArgumentNullException("eventDescriptor");
     }
     string str = component.Site.Name + "_" + eventDescriptor.Name;
     ArrayList eventHandlers = (ArrayList) ((ICodeBehindDocumentLanguage) this).GetEventHandlers(buffer, eventDescriptor);
     if (eventHandlers.Count == 0)
     {
         return str;
     }
     string item = str;
     int num = 0;
     do
     {
         if (eventHandlers.Contains(item))
         {
             num++;
             item = str + "_" + num;
         }
     }
     while (!flag);
     return item;
 }
Пример #35
0
        //TODO: actually show code and return true if exists
        public bool ShowCode(System.ComponentModel.IComponent component, System.ComponentModel.EventDescriptor e)
        {
            PropertyDescriptor pd   = GetEventProperty(e);
            string             name = (string)pd.GetValue(component);

            if (name == null)
            {
                name = CreateUniqueMethodName(component, e);
                pd.SetValue(component, name);
            }

            if (eventHandlers.ContainsKey(name))
            {
                ShowMessage("In an IDE this would show the existing CodeBehind method \"" + name + "\".");
            }
            else
            {
                eventHandlers.Add(name, GetEventParameters(e));
                ShowMessage("In an IDE this would create and show the CodeBehind method \"" + name + "\".");
            }

            return(true);
        }
Пример #36
0
 public void Remove(EventDescriptor value)
 {
     throw new NotImplementedException();
 }
Пример #37
0
 // Insert a descriptor into this collection.
 public void Insert(int index, EventDescriptor value)
 {
     list.Insert(index, value);
 }
Пример #38
0
 // Remove a descriptor from this collection.
 public void Remove(EventDescriptor value)
 {
     list.Remove(value);
 }
Пример #39
0
 // Add an descriptor to this collection.
 public int Add(EventDescriptor value)
 {
     return(list.Add(value));
 }
 public int IndexOf(EventDescriptor value) => Array.IndexOf(_events, value, 0, Count);
 public bool Contains(EventDescriptor value)
 {
     return(default(bool));
 }
 public bool Contains(EventDescriptor value) => IndexOf(value) >= 0;
Пример #43
0
 // Get the index of a specific descriptor within the collection.
 public int IndexOf(EventDescriptor value)
 {
     return(list.IndexOf(value));
 }
Пример #44
0
 /// <include file='doc\EventDescriptorCollection.uex' path='docs/doc[@for="EventDescriptorCollection.IndexOf"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public int IndexOf(EventDescriptor value)
 {
     return(Array.IndexOf(events, value, 0, eventCount));
 }
Пример #45
0
        public System.Collections.ICollection GetCompatibleMethods(System.ComponentModel.EventDescriptor e)
        {
            MethodInfo mi = e.EventType.GetMethod("Invoke");

            return(proxy.GetCompatibleMethodsInCodeBehind(mi));
        }
 public int IndexOf(EventDescriptor value)
 {
     return(Array.IndexOf <EventDescriptor>(this.events, value, 0, this.eventCount));
 }
Пример #47
0
 public void Insert(int index, EventDescriptor value)
 {
     throw new NotImplementedException();
 }
 public int IndexOf(EventDescriptor value)
 {
     return(default(int));
 }
 public bool Contains(EventDescriptor value)
 {
     return(this.IndexOf(value) >= 0);
 }
Пример #50
0
 public int IndexOf(EventDescriptor value)
 {
     throw new NotImplementedException();
 }
 public void Remove(EventDescriptor value)
 {
 }
Пример #52
0
 public bool Contains(EventDescriptor value)
 {
     throw new NotImplementedException();
 }
 public void Insert(int index, EventDescriptor value)
 {
     Contract.Requires(0 <= index);
 }
Пример #54
0
 public bool InsertComponentEvent(IComponent component, System.ComponentModel.EventDescriptor edesc, string eventMethodName, string body, out string file, out int position)
 {
     throw new NotImplementedException();
 }
Пример #55
0
 // Determine if this collection contains a particular descriptor.
 public bool Contains(EventDescriptor value)
 {
     return(list.Contains(value));
 }