Ejemplo n.º 1
0
		public TypedSignalDescriptor (XmlElement elem, ItemGroup group, TypedClassDescriptor klass) : base (elem, group, klass)
		{
			Load (elem);

			EventInfo eventInfo = FindEvent (klass.WrapperType, klass.WrappedType, name);
			MethodInfo handler = eventInfo.EventHandlerType.GetMethod ("Invoke");
			
			if (elem.HasAttribute ("glade-name"))
				gladeName = elem.GetAttribute ("glade-name");
			else {
				object[] att = eventInfo.GetCustomAttributes (typeof(GLib.SignalAttribute), true);
				if (att.Length > 0)
					gladeName = ((GLib.SignalAttribute)att[0]).CName;
			}
			
			handlerTypeName = eventInfo.EventHandlerType.FullName;
			handlerReturnTypeName = handler.ReturnType.FullName;
			
			ParameterInfo[] pars = handler.GetParameters ();
			handlerParameters = new ParameterDescriptor [pars.Length];
			for (int n=0; n<pars.Length; n++)
				handlerParameters [n] = new ParameterDescriptor (pars[n].Name, pars [n].ParameterType.FullName);
		}
Ejemplo n.º 2
0
		public CecilSignalDescriptor (CecilWidgetLibrary lib, XmlElement elem, Stetic.ItemGroup group, Stetic.ClassDescriptor klass, EventDefinition sinfo) : base (elem, group, klass)
		{
			if (sinfo != null) {
				string handler = sinfo.EventType.FullName;
				handlerTypeName = handler.Replace ('/','+');
				Type t = Registry.GetType (handler, false);
				if (t != null) {
					MethodInfo mi = t.GetMethod ("Invoke");
					handlerReturnTypeName = mi.ReturnType.FullName;
					ParameterInfo[] pars = mi.GetParameters ();
					handlerParameters = new ParameterDescriptor [pars.Length];
					for (int n=0; n<pars.Length; n++)
						handlerParameters [n] = new ParameterDescriptor (pars[n].Name, pars[n].ParameterType.FullName);
				} else {
					// If the type is generic, the type arguments must be ignored when looking for the type 
					string tn = handler;
					int i = handler.IndexOf ('<');
					if (i != -1) {
						tn = handler.Substring (0, i);
						// Convert the type name to a type reference
						handler = handler.Replace ('<', '[');
						handler = handler.Replace ('>', ']');
					}
					TypeDefinition td = lib.FindTypeDefinition (tn);
					if (td != null) {
						MethodDefinition mi = null;
						foreach (MethodDefinition md in td.Methods) {
							if (md.Name == "Invoke") {
								mi = md;
								break;
							}
						}
						if (mi != null) {
							handlerReturnTypeName = CecilWidgetLibrary.GetInstanceType (td, sinfo.EventType, mi.ReturnType.ReturnType);
							handlerParameters = new ParameterDescriptor [mi.Parameters.Count];
							for (int n=0; n<handlerParameters.Length; n++) {
								ParameterDefinition par = mi.Parameters [n];
								handlerParameters [n] = new ParameterDescriptor (par.Name, CecilWidgetLibrary.GetInstanceType (td, sinfo.EventType, par.ParameterType));
							}
						}
					} else {
						handlerParameters = new ParameterDescriptor [0];
					}
				}
				SaveCecilXml (elem);
			}
			else {
				handlerTypeName = elem.GetAttribute ("handlerTypeName");
				handlerReturnTypeName = elem.GetAttribute ("handlerReturnTypeName");
				
				ArrayList list = new ArrayList ();
				foreach (XmlNode npar in elem.ChildNodes) {
					XmlElement epar = npar as XmlElement;
					if (epar == null) continue;
					list.Add (new ParameterDescriptor (epar.GetAttribute ("name"), epar.GetAttribute ("type")));
				}
				
				handlerParameters = (ParameterDescriptor[]) list.ToArray (typeof(ParameterDescriptor));
			}
			
			Load (elem);
		}
        public CecilSignalDescriptor(CecilWidgetLibrary lib, XmlElement elem, Stetic.ItemGroup group, Stetic.ClassDescriptor klass, EventDefinition sinfo) : base(elem, group, klass)
        {
            if (sinfo != null)
            {
                string handler = sinfo.EventType.FullName;
                handlerTypeName = handler.Replace('/', '+');
                Type t = Registry.GetType(handler, false);
                if (t != null)
                {
                    MethodInfo mi = t.GetMethod("Invoke");
                    handlerReturnTypeName = mi.ReturnType.FullName;
                    ParameterInfo[] pars = mi.GetParameters();
                    handlerParameters = new ParameterDescriptor [pars.Length];
                    for (int n = 0; n < pars.Length; n++)
                    {
                        handlerParameters [n] = new ParameterDescriptor(pars[n].Name, pars[n].ParameterType.FullName);
                    }
                }
                else
                {
                    // If the type is generic, the type arguments must be ignored when looking for the type
                    string tn = handler;
                    int    i  = handler.IndexOf('<');
                    if (i != -1)
                    {
                        tn = handler.Substring(0, i);
                        // Convert the type name to a type reference
                        handler = handler.Replace('<', '[');
                        handler = handler.Replace('>', ']');
                    }
                    TypeDefinition td = lib.FindTypeDefinition(tn);
                    if (td != null)
                    {
                        MethodDefinition mi = null;
                        foreach (MethodDefinition md in td.Methods)
                        {
                            if (md.Name == "Invoke")
                            {
                                mi = md;
                                break;
                            }
                        }
                        if (mi != null)
                        {
                            handlerReturnTypeName = CecilWidgetLibrary.GetInstanceType(td, sinfo.EventType, mi.ReturnType.ReturnType);
                            handlerParameters     = new ParameterDescriptor [mi.Parameters.Count];
                            for (int n = 0; n < handlerParameters.Length; n++)
                            {
                                ParameterDefinition par = mi.Parameters [n];
                                handlerParameters [n] = new ParameterDescriptor(par.Name, CecilWidgetLibrary.GetInstanceType(td, sinfo.EventType, par.ParameterType));
                            }
                        }
                    }
                    else
                    {
                        handlerParameters = new ParameterDescriptor [0];
                    }
                }
                SaveCecilXml(elem);
            }
            else
            {
                handlerTypeName       = elem.GetAttribute("handlerTypeName");
                handlerReturnTypeName = elem.GetAttribute("handlerReturnTypeName");

                ArrayList list = new ArrayList();
                foreach (XmlNode npar in elem.ChildNodes)
                {
                    XmlElement epar = npar as XmlElement;
                    if (epar == null)
                    {
                        continue;
                    }
                    list.Add(new ParameterDescriptor(epar.GetAttribute("name"), epar.GetAttribute("type")));
                }

                handlerParameters = (ParameterDescriptor[])list.ToArray(typeof(ParameterDescriptor));
            }

            Load(elem);
        }