protected virtual void OnRead(IXmlCodeReader reader, XmlNode node) { //get local variable from method component list based on _memberId XmlNode varNode = DesignUtil.GetMethodVariableNode(node.OwnerDocument.DocumentElement, _memberId); if (varNode == null) { LocalVariable v = LocalVariable.GetUnsavedLocalVariable(_classId, _memberId); if (v == null) { //it can be a variable in an exception handler //get method id UInt32 methodId = 0; XmlNode mn = node; while (mn != null) { methodId = XmlUtil.GetAttributeUInt(mn, XmlTags.XMLATT_ScopeId); if (methodId != 0) { break; } mn = mn.ParentNode; } if (methodId != 0) { ClassPointer root = ((XmlObjectReader)reader).ObjectList.GetTypedData <ClassPointer>(); MethodClass mc = root.GetCustomMethodById(methodId); if (mc != null) { v = mc.GetLocalVariable(_memberId); } } else { DesignUtil.WriteToOutputWindowAndLog("Error reading local variable. Variable node not found [{0},{1}]", _classId, _memberId); } } if (v != null) { _name = v.Name; _type = v.ClassType; _owner = v._owner; _instance = v._instance; _nameChecker = v._nameChecker; _debug = v._debug; } } else { _name = XmlUtil.GetNameAttribute(varNode); Type t = XmlUtil.GetLibTypeAttribute(varNode); if (t != null) { if (t.Equals(typeof(ParameterClass))) { MethodClass mc = _owner as MethodClass; if (mc != null) { _type = (DataTypePointer)Activator.CreateInstance(t, mc); } } else { _type = (DataTypePointer)Activator.CreateInstance(t); } reader.ReadObjectFromXmlNode(varNode, _type, t, this); } else { UInt32 id = XmlUtil.GetAttributeUInt(node, XmlTags.XMLATT_ComponentID); if (id != 0) { //try to get it from exception handler of a method ClassPointer root = ClassPointer.CreateClassPointer(((XmlObjectReader)reader).ObjectList); LocalVariable v = root.GetLocalVariable(id); if (v != null) { _name = v.Name; _type = v.ClassType; _owner = v._owner; _instance = v._instance; _nameChecker = v._nameChecker; _debug = v._debug; } } else { #if DEBUG throw new DesignerException("Error reading local variable from class [{0}]. XPath:[{1}]", reader.ClassId, XmlUtil.GetPath(node)); #endif } } } }
public PropertyDescriptorVariableValue(string name, Attribute[] attrs, string category, LocalVariable data, Type componentType) : base(name, attrs) { _category = category; _data = data; _componentType = componentType; }
public bool LoadData(LocalVariable lv) { ConstructorInfo[] cifs; Type t = lv.BaseClassType; if (t.IsEnum) { cifs = null; } else { try { Type tCo = VPLUtil.GetCoClassType(t); if (tCo != null) { cifs = tCo.GetConstructors(); } else { cifs = t.GetConstructors(); } } catch { cifs = null; } } if (cifs != null && cifs.Length > 0) { Text = string.Format(Resources.TitleSelectConstructor, t.Name); List <TreeNodeConstructor> list = new List <TreeNodeConstructor>(); for (int i = 0; i < cifs.Length; i++) { TreeNodeConstructor tn = new TreeNodeConstructor(new ConstructorPointer(cifs[i], lv)); list.Add(tn); } if (!t.IsValueType) { treeViewConstructors.Nodes.Add(new TreeNodeConstructor(new ConstructorPointerNull(lv))); } IOrderedEnumerable <TreeNodeConstructor> sorted = list.OrderBy <TreeNodeConstructor, string>(r => r.Text); foreach (TreeNodeConstructor nc in sorted) { treeViewConstructors.Nodes.Add(nc); } if (lv.VariableCustomType != null) { List <ConstructorClass> clst = lv.VariableCustomType.GetCustomConstructors(); if (clst != null && clst.Count > 0) { foreach (ConstructorClass cc in clst) { TreeNodeCustomConstructorPointer tnc = new TreeNodeCustomConstructorPointer(new CustomConstructorPointer(cc, lv.RootPointer)); treeViewConstructors.Nodes.Add(tnc); } } } return(true); } return(false); }
public ComponentIconSubscopeVariable(ILimnorDesigner designer, LocalVariable pointer, MethodClass method) : base(designer, pointer, method) { }
/// <summary> /// returns corresponding concrete type for the given generic argument or generic parameter /// </summary> /// <param name="typeParameter"></param> /// <returns></returns> public virtual DataTypePointer GetConcreteType(Type typeParameter) { if (typeParameter != null) { IObjectPointer op; if (TypeParameters != null) { if (typeParameter.IsGenericParameter || typeParameter.IsGenericType) { MethodBase mb = MethodDef; if (mb != null) { if (mb.ContainsGenericParameters) { Type[] tcs = mb.GetGenericArguments(); if (tcs != null && tcs.Length > 0) { for (int i = 0; i < tcs.Length; i++) { if (tcs[i].Equals(typeParameter)) { if (i < TypeParameters.Length) { return(TypeParameters[i]); } } } } } } } op = this.Owner; IGenericTypePointer igp = null; while (op != null) { igp = op as IGenericTypePointer; if (igp != null) { break; } op = op.Owner; } if (igp != null) { return(igp.GetConcreteType(typeParameter)); } } LocalVariable lv = null; op = this.Owner; while (op != null) { lv = op as LocalVariable; if (lv != null) { break; } op = op.Owner; } if (lv != null) { return(lv.GetConcreteType(typeParameter)); } } return(null); }
void miDelete_Click(object sender, EventArgs e) { LocalVariable lv = this.ClassPointer as LocalVariable; List <IAction> acts = lv.RootPointer.GetRelatedActions(lv.MemberId); bool bOK = (acts.Count == 0); if (bOK) { MethodDesignerHolder mdh = MethodViewer; if (mdh != null) { BranchList bl = mdh.ActionList; if (bl != null) { Dictionary <UInt32, IAction> actions = new Dictionary <uint, IAction>(); bl.GetActionsUseLocalVariable(lv.MemberId, actions); if (actions.Count > 0) { foreach (KeyValuePair <UInt32, IAction> kv in actions) { acts.Add(kv.Value); } bOK = false; } } } } if (!bOK) { List <ObjectTextID> objs = new List <ObjectTextID>(); foreach (IAction a in acts) { objs.Add(new ObjectTextID("Action", "", a.Display)); } dlgObjectUsage dlg = new dlgObjectUsage(); dlg.LoadData("There are actions using this object. These actions must be removed before this object can be removed.", "Remove object", objs); //currently no OK will be returned bOK = (dlg.ShowDialog(this.FindForm()) == DialogResult.OK); if (bOK) { IList <MethodDiagramViewer> l = MethodViewer.GetViewer(); foreach (MethodDiagramViewer mv in l) { //remove local/constructor actions belong to it List <IComponent> avList = new List <IComponent>(); for (int i = 0; i < mv.Controls.Count; i++) { ActionViewer av = mv.Controls[i] as ActionViewer; if (av != null) { foreach (IAction a in acts) { if (av.ActionObject.ContainsActionId(a.ActionId)) { avList.Add(av); } } } } if (avList.Count > 0) { mv.DeleteComponents(avList.ToArray()); } } } } if (bOK) { MethodViewer.RemoveLocalVariable(this); RemoveLabel(); Control p = this.Parent; if (p != null) { p.Controls.Remove(this); } MethodViewer.Changed = true; } }