public void MethodTargets() { var methodClass1 = new MethodClass("foo1"); var methodClass2 = new MethodClass("foo2"); Func <string> delegate1 = methodClass1.M; Func <string> delegate2 = methodClass2.M; AssertEquals(delegate1(), "foo1"); AssertEquals(delegate2(), "foo2"); AssertEquals(delegate1.Target, methodClass1); AssertEquals(delegate2.Target, methodClass2); }
public Dictionary <string, MethodClass> GetCustomMethods() { Dictionary <string, MethodClass> list = _definingClass.CustomMethods; Dictionary <string, MethodClass> list0 = new Dictionary <string, MethodClass>(); foreach (KeyValuePair <string, MethodClass> kv in list) { MethodClass m0 = (MethodClass)(kv.Value.Clone()); m0.SetHolder(this); list0.Add(kv.Key, m0); } return(list0); }
public override void SetOwnerMethod(List <UInt32> used, MethodClass m) { base.SetOwnerMethod(used, m); if (!used.Contains(this.BranchId)) { used.Add(this.BranchId); if (_logicExpression != null) { _logicExpression.Project = m.Project; } } }
public void SetScopeMethod(MethodClass m) { if (_decisionTable != null) { foreach (DecisionItem di in _decisionTable) { if (di.Condition != null) { di.Condition.ScopeMethod = m; } } } }
public ComponentIconForMethod(ILimnorDesigner designer, IClass pointer, MethodClass method) : this(method) { if (designer == null) { throw new DesignerException("designer is null for ComponentIcon"); } if (pointer == null) { throw new DesignerException("pointer is null for ComponentIcon"); } Init(designer, pointer); }
public override void SetOwnerMethod(List <UInt32> used, MethodClass m) { base.SetOwnerMethod(used, m); RepeatCount.ScopeMethod = m; if (RepeatCount.MathExpression != null) { MathNodeRoot r = RepeatCount.MathExpression as MathNodeRoot; if (r != null) { r.Project = m.Project; } } }
public static void Main() { var myClass = new MethodClass(); myClass.MyFunction(0); myClass.MyFunction(0, false); myClass.MyFunction(0, false, true); myClass.MyFunction(0, d: true); myClass.MyFunction(a: 0, d: true); myClass.MyInfiniteFunction("0", 1, 2, 3, 5, 6, 8, 9); myClass.MyInfiniteFunction("0"); myClass.MyInfiniteFunction("0", null); }
public override void SetOwnerMethod(List <UInt32> used, MethodClass m) { base.SetOwnerMethod(used, m); if (_decisionTable != null) { for (int i = 0; i < _decisionTable.ConditionCount; i++) { if (_decisionTable[i].Condition != null) { _decisionTable[i].Condition.Project = m.Project; } } } }
public ViewMethod(MethodClass method) { string methodacces = ""; if (method._public) { methodacces += "public"; } if (method._static) { methodacces += " " + "static"; } methodClass = methodacces + " " + method._sign; }
private void showBreakPointInMethod(int threadId, MethodClass method, IActionGroup group, ActionBranch branch) { MethodDesignerHolder h = getViewer(threadId, method, group, branch); if (h == null) { IActionGroup g = (IActionGroup)(group.Clone()); g = g.GetThreadGroup(branch.BranchId); //create a viewer SplitContainer c = getLastContainer(splitContainer1); SplitContainer newContainer = new SplitContainer(); newContainer.Dock = DockStyle.Fill; c.Panel2.Controls.Add(newContainer); c.Panel2Collapsed = false; newContainer.Panel2Collapsed = true; h = Activator.CreateInstance(g.ViewerHolderType, this, _designer) as MethodDesignerHolder; h.ThreadId = threadId; h.SetBackgroundText(group.GroupName); h.Dock = DockStyle.Fill; newContainer.Panel1.Controls.Add(h); h.LoadActions(g); _currentThreadId = threadId; h.DesignerSelected += new EventHandler(h_DesignerSelected); newContainer.Panel1.GotFocus += new EventHandler(Panel1_GotFocus); newContainer.SplitterMoved += new SplitterEventHandler(newContainer_SplitterMoved); newContainer.Resize += new EventHandler(newContainer_Resize); } else { if (h.ActionGroup.GroupFinished) { h.ActionGroup.GroupFinished = false; ThreadDebug td = ThreadData(threadId); if (td.Status == EnumRunStatus.Finished) { FormDebugger f = this.FindForm() as FormDebugger; if (f != null) { td.Status = f.DebugCommandStatus; } else { td.Status = EnumRunStatus.Run; } } UpdateViewersBackColor(); } } h.UpdateBreakpoint(branch); }
static void Main(string[] args) { Console.WriteLine(" ------------------\n <--- Main Class ---> \n ------------------ \n"); new Variables(); new Converter(); new UserInput(); new Math(); new StringClass(); new ArrayClass(); new ArrayLinq(); MethodClass m = new MethodClass(); Console.WriteLine("Calling Class's Method : " + m.num(5)); }
public BranchList(IActionsHolder scope, List <ActionBranch> actions) { _method = scope.OwnerMethod; _actsHolder = scope; if (actions.Count > 0) { _threads = new Dictionary <uint, ActionBranch>(); _threads.Add(actions[0].BranchId, actions[0]); for (int i = 0; i < actions.Count; i++) { Add(actions[i]); } } }
public void LoadData(LimnorContextMenuCollection menus) { _menus = menus; List <MenuItemDataMethod> pms = _menus.PrimaryMethods; if (pms != null && pms.Count > 0) { foreach (MenuItemDataMethod m in pms) { lstP.Items.Add(m); } } List <MenuItemDataMethod> sms = _menus.SecondaryMethods; if (sms != null && sms.Count > 0) { foreach (MenuItemDataMethod m in sms) { lstS.Items.Add(m); } } SortedDictionary <string, IMethod> all = _menus.GetAllMethods(); SortedDictionary <string, TreeNode> customNodes = new SortedDictionary <string, TreeNode>(); foreach (KeyValuePair <string, IMethod> kv in all) { MethodInfoPointer mi = kv.Value as MethodInfoPointer; if (mi != null) { treeViewAll.Nodes.Add(new TreeNodeMethod(false, mi)); } else { MethodClass mc = kv.Value as MethodClass; if (mc != null) { //use 0 as the scope because method selection does not need scope TreeNodeCustomMethod tnc = new TreeNodeCustomMethod(treeViewAll, mc.IsStatic, mc, menus.Pointer, 0); customNodes.Add(tnc.Text, tnc); } } } int i = 0; foreach (KeyValuePair <string, TreeNode> kv in customNodes) { treeViewAll.Nodes.Insert(i++, kv.Value); } }
/// <summary> /// if currently in submethod then add goto branch to the sub method; otherwise add it to the method scope /// </summary> /// <param name="method"></param> /// <param name="custMethod"></param> /// <param name="branchId"></param> /// <param name="statements"></param> public static void AddGotoBranch(CodeMemberMethod method, MethodClass custMethod, UInt32 branchId, MethodSegment statements, UInt32 groupId) { Dictionary <UInt32, MethodSegment> branches = null; if (groupId != 0) { Dictionary <UInt32, Dictionary <UInt32, MethodSegment> > groups; if (method.UserData.Contains(GOTOBRANCHES_Group)) { groups = (Dictionary <UInt32, Dictionary <UInt32, MethodSegment> >)method.UserData[GOTOBRANCHES_Group]; if (groups == null) { groups = new Dictionary <uint, Dictionary <uint, MethodSegment> >(); method.UserData[GOTOBRANCHES_Group] = groups; } } else { groups = new Dictionary <uint, Dictionary <uint, MethodSegment> >(); method.UserData.Add(GOTOBRANCHES_Group, groups); } if (!groups.TryGetValue(groupId, out branches)) { branches = new Dictionary <uint, MethodSegment>(); groups.Add(groupId, branches); } } else { if (custMethod.SubMethod.Count > 0) { IMethod0 m0 = custMethod.SubMethod.Peek(); branches = AddSubMethod(method, m0); } else { branches = (Dictionary <UInt32, MethodSegment>)method.UserData[GOTOBRANCHES]; if (branches == null) { branches = new Dictionary <uint, MethodSegment>(); method.UserData.Add(GOTOBRANCHES, branches); } } } if (!branches.ContainsKey(branchId)) { branches.Add(branchId, statements); } }
private void buttonAdd_Click(object sender, EventArgs e) { EnumMethodWebUsage webuse = EnumMethodWebUsage.Server; if (_runatwebclient) { webuse = EnumMethodWebUsage.Client; } MethodClass mc = _root.CreateNewMethodFixParams(webuse, _paramTypes, _pnames, buttonAdd.ClientRectangle, this); if (mc != null) { SelectedMethod = new VplMethodPointer(mc.MethodID, mc.MethodName); this.DialogResult = DialogResult.OK; } }
static void Main() { ICountDownNotifier[] array = new ICountDownNotifier[] { new MethodClass(), new AnonymousClass(), new LambdaClass() }; CountDownTimer[] timers = new[] { new CountDownTimer("Чтение задания"), new CountDownTimer("Выполнение задания"), new CountDownTimer("Проверка задания") }; //Ввод длительности таймеров int[] time = new int[3]; for (int i = 0; i < 3; i++) { Console.WriteLine($"Введите продолжительность {i + 1}го таймера в секундах:"); //Ввод чисел. Отбрасывает отрицательные значения, и значения, которые приведут к overflow while (!int.TryParse(Console.ReadLine(), out time[i]) || time[i] < 0 || time[i] >= int.MaxValue / 1000) { Console.WriteLine("Неверный ввод"); } } //Запуск таймеров Console.WriteLine("Запуск:\n"); for (int i = 0; i < timers.Length; i++) { //Подписка на события array[i].Init(timers[i]); try { //Запуск таймера array[i].Run(time[i]); } catch (OverflowException) { Console.WriteLine("Timer overflow. Skipping Timer."); } } //Демонстрация подписки нескольких классов на один таймер Console.WriteLine("Демонстрация подписки нескольких классов на один таймер:"); CountDownTimer timer = new CountDownTimer("ОБЩИЙ"); ICountDownNotifier item1 = new MethodClass(); ICountDownNotifier item2 = new LambdaClass(); item1.Init(timer); item2.Init(timer); item1.Run(10); Console.ReadLine(); }
public override void FindActionsByOwnerType <T>(List <IActionMethodPointer> results, List <UInt32> usedBranches, List <UInt32> usedMethods) { if (usedBranches.Contains(this.BranchId)) { return; } usedBranches.Add(this.BranchId); if (_decisionTable != null) { for (int i = 0; i < _decisionTable.ConditionCount; i++) { if (_decisionTable[i].Condition != null) { Dictionary <UInt32, IMethodPointerNode> ms = new Dictionary <uint, IMethodPointerNode>(); _decisionTable[i].Condition.GetMethodPointers(ms); if (ms.Count > 0) { foreach (KeyValuePair <UInt32, IMethodPointerNode> mp in ms) { if (mp.Value.MethodExecuter is T) { IActionMethodPointer ia = mp.Value.MethodObject as IActionMethodPointer; if (ia != null) { results.Add(ia); } } } } } if (_decisionTable[i].Actions != null) { for (int k = 0; k < _decisionTable[i].Actions.Count; k++) { if (_decisionTable[i].Actions[k].Action == null) { _decisionTable[i].Actions[k].Action = GetActionInstance(_decisionTable[i].Actions[k].ActionId); } if (_decisionTable[i].Actions[k].Action != null) { MethodClass.CollectActionsByOwnerType <T>(_decisionTable[i].Actions[k].Action, results, usedMethods); } } } } } }
public override void OnWriteToXmlNode(IXmlCodeWriter writer, XmlNode node) { base.OnWriteToXmlNode(writer, node); if (!string.IsNullOrEmpty(Description)) { XmlNode nd = node.OwnerDocument.CreateElement(DESC); node.AppendChild(nd); nd.InnerText = Description; } MethodClass mc = _method as MethodClass; if (mc != null) { XmlUtil.SetAttribute(node.ParentNode, XmlTags.XMLATT_ownerMethodId, mc.MethodID); } }
public override void FindActionsByOwnerType <T>(List <IActionMethodPointer> results, List <UInt32> usedBranches, List <UInt32> usedMethods) { if (usedBranches.Contains(this.BranchId)) { return; } usedBranches.Add(this.BranchId); if (_actionList != null) { foreach (ActionItem ai in _actionList) { if (ai.Action != null) { MethodClass.CollectActionsByOwnerType <T>(ai.Action, results, usedMethods); } } } }
private void mi_makeCopy(object sender, EventArgs e) { EventPath ep = this.Parent as EventPath; if (ep != null) { ClassPointer root = ep.Panes.Loader.GetRootId(); MethodClass newMethod = root.MakeMethodCopy(_method, this.FindForm()); if (newMethod != null) { ComponentIconMethod cim = ep.getMethodComponentIcon(newMethod.MemberId); if (cim != null) { cim.Location = new Point(this.Location.X + 20, this.Location.Y + 20); } } } }
public override void OnReadFromXmlNode(IXmlCodeReader serializer, XmlNode node) { base.OnReadFromXmlNode(serializer, node); MethodId = XmlUtil.GetAttributeUInt(node, XmlTags.XMLATT_handlerId); XmlObjectReader reader = (XmlObjectReader)serializer; ClassPointer root = reader.ObjectList.RootPointer as ClassPointer; MethodClass mc = root.GetCustomMethodById(MethodId); if (mc == null) { MathNode.LogError(string.Format(System.Globalization.CultureInfo.InvariantCulture, "Method {0} not found in class {1}", MethodId, root.ClassId)); } else { _method = mc; } }
private void checkVariable() { if (_var == null) { MethodClass mc = _actsHolder as MethodClass; if (mc != null) { _var = mc.GetLocalVariable(_varId); } if (_var == null) { if (_class != null) { _var = _class.GetLocalVariable(_varId); } } } }
public string GetDisplayName(MethodInfo methodInfo, object[] data) { if (DisplayMethod == null) { if (string.IsNullOrEmpty(DisplayMethodName)) { return(null); } DisplayMethod = MethodClass.GetMethod(DisplayMethodName, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); if (DisplayMethodName == null) { throw new InvalidOperationException($"could not resolve test data display method:" + $" class=[{MethodClass.FullName}]" + $" method=[{DisplayMethodName}]"); } } if (TestMethod == null) { TestMethod = methodInfo; } object[] methodParams = null; var paramInfos = DisplayMethod.GetParameters(); var paramLen = paramInfos.Length; if (paramLen == 2 && paramInfos[1].ParameterType == typeof(object[])) { methodParams = new object[] { this, data }; } else if (paramLen > 1) { methodParams = new object[data.Length + 1]; methodParams[0] = this; Array.Copy(data, 0, methodParams, 1, data.Length); } else if (paramLen > 0) { methodParams = new object[] { this }; } return((string)DisplayMethod.Invoke(null, methodParams)); }
public override void GetCustomMethods(List <uint> usedBranches, List <MethodClass> list) { if (usedBranches.Contains(this.BranchId)) { return; } usedBranches.Add(this.BranchId); EventAction ea = AssignedActions; if (ea != null) { foreach (TaskID tid in ea.TaskIDList) { HandlerMethodID hmid = tid as HandlerMethodID; if (hmid != null) { if (hmid.HandlerMethod != null) { if (!containsCustMethod(list, hmid.HandlerMethod.MethodID)) { list.Add(hmid.HandlerMethod); } } } else { IAction a = tid.GetPublicAction(this.OwnerMethod.RootPointer); if (a != null) { MethodClass mc = a.ActionMethod.MethodPointed as MethodClass; if (mc != null) { if (!containsCustMethod(list, mc.MethodID)) { list.Add(mc); } } } } } } }
public override void SetOwnerMethod(List <UInt32> used, MethodClass m) { if (!used.Contains(this.BranchId)) { used.Add(this.BranchId); base.SetOwnerMethod(used, m); //if (_target != null) //{ // _target.Owner = m; //} if (_ifActions != null) { _ifActions.SetOwnerMethod(used, m); } if (_elseActions != null) { _elseActions.SetOwnerMethod(used, m); } } }
public void LoadMethod(MethodClass method, EnumParameterEditType parameterEditType) { if (holder.MainDiagramViewer.ParentEditor == null) { method.SetEditContext(); } holder.LoadMethod(method, parameterEditType); EventHandlerMethod ehm = method as EventHandlerMethod; if (ehm != null) { this.Text = string.Format(System.Globalization.CultureInfo.InvariantCulture, Resources.TitleEditEventMethod, ehm.Event.Name, method.MethodName); } else { this.Text = string.Format(System.Globalization.CultureInfo.InvariantCulture, Resources.TitleEditMethod, method.MethodName); } }
public static void Main() { var obj = new MethodClass(); Del d1 = obj.Method1; Del d2 = obj.Method2; Del d3 = DelegateMethod; //Both types of assignment are valid. Del allMethodsDelegate = d1 + d2; allMethodsDelegate += d3; allMethodsDelegate("Hello World"); //To remove a method from the invocation list //remove Method1 allMethodsDelegate -= d1; // copy AllMethodsDelegate while removing d2 Del oneMethodDelegate = allMethodsDelegate - d2; }
public void EstablishObjectOwnership(MethodClass m) { if (_componentIconList != null) { foreach (ComponentIconSubscopeVariable sv in _componentIconList) { sv.EstablishObjectOwnership(_method); } } if (_actions != null) { _actions.EstablishObjectOwnership(); } if (_acts != null) { foreach (IAction act in _acts.Values) { act.EstablishObjectOwnership(this); } } }
//Along with the static DelegateMethod shown previously, we now have three methods that can be wrapped by a Del instance. public void exampleForInstanceMethod() { MethodClass obj = new MethodClass(); Del d1 = obj.Method1; Del d2 = obj.Method2; Del d3 = DelegateMethod; //Both types of assignment are valid. Del allMethodsDelegate = d1 + d2; allMethodsDelegate += d3; //At this point allMethodsDelegate contains three methods in its invocation list—Method1, Method2, and DelegateMethod. //The original three delegates, d1, d2, and d3, remain unchanged. When allMethodsDelegate is invoked, all three methods are called in order. //If the delegate uses reference parameters, the reference is passed sequentially to each of the three methods in turn, //and any changes by one method are visible to the next method. //When any of the methods throws an exception that is not caught within the method, //that exception is passed to the caller of the delegate and no subsequent methods in the invocation list are called. //If the delegate has a return value and/or out parameters, it returns the return value and parameters of the last method invoked. //To remove a method from the invocation list, use the decrement or decrement assignment operator ('-' or '-='). For example: //remove Method1 allMethodsDelegate -= d1; // copy AllMethodsDelegate while removing d2 Del oneMethodDelegate = allMethodsDelegate - d2; //Because delegate types are derived from System.Delegate, the methods and properties defined by that class can be called on the delegate. //For example, to find the number of methods in a delegate's invocation list, you may write: int invocationCount = d1.GetInvocationList().GetLength(0); //Comparing delegates of two different types assigned at compile-time will result in a compilation error. //If the delegate instances are statically of the type System.Delegate, then the comparison is allowed, but will return false at run time. For example: // Compile-time error. //Console.WriteLine(d1 == e2); // OK at compile-time. False if the run-time type of f // is not the same as that of d. System.Console.WriteLine(d1 == d2); }
static void Main(string[] args) { Del handler = DelegateMethod; handler("DelegateMethod"); MethodWithCallback(1, 2, handler); MethodClass obj = new MethodClass(); Del d1 = obj.Method1; Del d2 = obj.Method2; Del d3 = DelegateMethod; Del allMethodDelegate = d1 + d2; allMethodDelegate += d3; allMethodDelegate -= d1; Del oneMethodDelegate = allMethodDelegate - d2; int invocationCount = d1.GetInvocationList().GetLength(0); }