public CecilPropertyDescriptor (CecilWidgetLibrary lib, XmlElement elem, Stetic.ItemGroup group, Stetic.ClassDescriptor klass, PropertyDefinition pinfo): base (elem, group, klass) { string tname; if (pinfo != null) { name = pinfo.Name; tname = pinfo.PropertyType.FullName; canWrite = pinfo.SetMethod != null; } else { name = elem.GetAttribute ("name"); tname = elem.GetAttribute ("type"); canWrite = elem.Attributes ["canWrite"] == null; } Load (elem); type = Stetic.Registry.GetType (tname, false); if (type == null) { Console.WriteLine ("Could not find type: " + tname); type = typeof(string); } if (type.IsValueType) initialValue = Activator.CreateInstance (type); // Consider all properties runtime-properties, since they have been created // from class properties. isRuntimeProperty = true; if (pinfo != null) SaveCecilXml (elem); }
public ComponentType[] GetComponentTypes(string fileName) { if (IsWidgetLibrary(fileName)) { return(CecilWidgetLibrary.GetComponentTypes(this, fileName).ToArray()); } else { return(new ComponentType [0]); } }
public CecilClassDescriptor (CecilWidgetLibrary lib, XmlElement element, ClassDescriptor typeClassDescriptor, XmlElement steticDefinition, TypeDefinition cls) { this.cecilLib = lib; this.steticDefinition = steticDefinition; this.typeClassDescriptor = typeClassDescriptor; wrappedTypeName = element.GetAttribute ("type"); type = cls; Load (element); type = null; canGenerateCode = true; string baseType = element.GetAttribute ("base-type"); if (baseType.Length > 0) { wrapperClassDescriptor = Registry.LookupClassByName (baseType); if (wrapperClassDescriptor == null) throw new InvalidOperationException ("Unknown base type: " + baseType); } else { wrapperClassDescriptor = typeClassDescriptor; } if (steticDefinition == null && !AllowChildren && NeedsBlackBox (typeClassDescriptor.Name)) { // It is not possible to create instances of that widget, instead we'll have // to create the typical custom widget black box. if (!CanCreateWidgetInstance (wrapperClassDescriptor.Name)) throw new InvalidOperationException ("Can't load widget type '" + Name + "'. Instances of that type can't be created because the type can't be loaded into the process."); useCustomWidgetBox = true; } widgetId = Name.ToLower (); int i = widgetId.LastIndexOf ('.'); if (i != -1) { if (i != widgetId.Length - 1) widgetId = widgetId.Substring (i+1); else widgetId = widgetId.Replace (".", ""); } string iconName = element.GetAttribute ("icon"); icon = lib.GetEmbeddedIcon (iconName); // If the class is a custom widget created using stetic, it means that it has // simple property and there is no custom logic, so it is safe to generate code // for this class. if (steticDefinition != null) canGenerateCode = true; // If it has a custom wrapper, then it definitely has custom logic, so it can't generate code if (element.HasAttribute ("wrapper")) canGenerateCode = false; }
public CecilPropertyDescriptor(CecilWidgetLibrary lib, XmlElement elem, Stetic.ItemGroup group, Stetic.ClassDescriptor klass, PropertyDefinition pinfo) : base(elem, group, klass) { string tname; if (pinfo != null) { name = pinfo.Name; tname = pinfo.PropertyType.FullName; canWrite = pinfo.SetMethod != null; } else { name = elem.GetAttribute("name"); tname = elem.GetAttribute("type"); canWrite = elem.Attributes ["canWrite"] == null; } Load(elem); type = Stetic.Registry.GetType(tname, false); if (type == null) { Console.WriteLine("Could not find type: " + tname); type = typeof(string); } if (type.IsValueType) { initialValue = Activator.CreateInstance(type); } // Consider all properties runtime-properties, since they have been created // from class properties. isRuntimeProperty = true; if (pinfo != null) { SaveCecilXml(elem); } }
internal static bool InternalIsWidgetLibrary(AssemblyResolver resolver, string assemblyRef) { string path; if (assemblyRef.EndsWith(".dll") || assemblyRef.EndsWith(".exe")) { if (!File.Exists(assemblyRef)) { return(false); } path = assemblyRef; } else { path = resolver.Resolve(assemblyRef, null); if (path == null) { return(false); } } return(CecilWidgetLibrary.IsWidgetLibrary(path)); }
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 CecilClassDescriptor(CecilWidgetLibrary lib, XmlElement element, ClassDescriptor typeClassDescriptor, XmlElement steticDefinition, TypeDefinition cls) { this.cecilLib = lib; this.steticDefinition = steticDefinition; this.typeClassDescriptor = typeClassDescriptor; wrappedTypeName = element.GetAttribute("type"); type = cls; Load(element); type = null; canGenerateCode = true; string baseType = element.GetAttribute("base-type"); if (baseType.Length > 0) { wrapperClassDescriptor = Registry.LookupClassByName(baseType); if (wrapperClassDescriptor == null) { throw new InvalidOperationException("Unknown base type: " + baseType); } } else { wrapperClassDescriptor = typeClassDescriptor; } if (steticDefinition == null && !AllowChildren && NeedsBlackBox(typeClassDescriptor.Name)) { // It is not possible to create instances of that widget, instead we'll have // to create the typical custom widget black box. if (!CanCreateWidgetInstance(wrapperClassDescriptor.Name)) { throw new InvalidOperationException("Can't load widget type '" + Name + "'. Instances of that type can't be created because the type can't be loaded into the process."); } useCustomWidgetBox = true; } widgetId = Name.ToLower(); int i = widgetId.LastIndexOf('.'); if (i != -1) { if (i != widgetId.Length - 1) { widgetId = widgetId.Substring(i + 1); } else { widgetId = widgetId.Replace(".", ""); } } string iconName = element.GetAttribute("icon"); icon = lib.GetEmbeddedIcon(iconName); // If the class is a custom widget created using stetic, it means that it has // simple property and there is no custom logic, so it is safe to generate code // for this class. if (steticDefinition != null) { canGenerateCode = true; } // If it has a custom wrapper, then it definitely has custom logic, so it can't generate code if (element.HasAttribute("wrapper")) { canGenerateCode = false; } }
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); }