private void SpecializeOneFunction(string name, CallDelegate callable, bool mergeOriginalAnalysis) { int lastIndex; VariableDef def; if (Scope.TryGetVariable(name, out def)) { SpecializeVariableDef(def, callable, mergeOriginalAnalysis); } else if ((lastIndex = name.LastIndexOf('.')) != -1 && Scope.TryGetVariable(name.Substring(0, lastIndex), out def)) { var methodName = name.Substring(lastIndex + 1, name.Length - (lastIndex + 1)); foreach (var v in def.TypesNoCopy) { ClassInfo ci = v as ClassInfo; if (ci != null) { VariableDef methodDef; if (ci.Scope.TryGetVariable(methodName, out methodDef)) { SpecializeVariableDef(methodDef, callable, mergeOriginalAnalysis); } } } } }
private void ExcecuteMethod <T>(CallDelegate <RequestParams, OutputModel <T>, bool> method, RequestParams @params, out OutputModel <T> outputModel) { outputModel = null; for (int i = 0; i < 2; i++) { if (method(@params, out outputModel)) { break; } else { if (outputModel.Response.Status == Status.InvalidSession) { // Login and retrieve session token if (!Login(out var response)) { throw new Exception($"Invalid session and couldn't refresh. {response.Message}"); } } else { throw new Exception("Unknown error."); } } } }
void IModule.SpecializeFunction(string name, CallDelegate callable, bool mergeOriginalAnalysis) { foreach (var member in _members.OfType <IModule>()) { member.SpecializeFunction(name, callable, mergeOriginalAnalysis); } }
/// <summary> /// Replaces a built-in function (specified by module name and function /// name) with a customized delegate which provides specific behavior /// for handling when that function is called. /// /// Currently this just provides a hook when the function is called - it /// could be expanded to providing the interpretation of when the /// function is called as well. /// </summary> private void SpecializeFunction(string moduleName, string name, CallDelegate callable, bool mergeOriginalAnalysis, bool save) { ModuleReference module; int lastDot; string realModName = null; if (Modules.TryGetImportedModule(moduleName, out module)) { IModule mod = module.Module as IModule; if (mod != null) { mod.SpecializeFunction(name, callable, mergeOriginalAnalysis); return; } } else if ((lastDot = moduleName.LastIndexOf('.')) != -1 && Modules.TryGetImportedModule(realModName = moduleName.Substring(0, lastDot), out module)) { IModule mod = module.Module as IModule; if (mod != null) { mod.SpecializeFunction(moduleName.Substring(lastDot + 1, moduleName.Length - (lastDot + 1)) + "." + name, callable, mergeOriginalAnalysis); return; } } if (save) { SaveDelayedSpecialization(moduleName, name, callable, realModName, mergeOriginalAnalysis); } }
public SpecializationInfo(string moduleName, string name, CallDelegate callable, bool mergeOriginalAnalysis) { ModuleName = moduleName; Name = name; Callable = callable; SuppressOriginalAnalysis = mergeOriginalAnalysis; }
public void SpecializeFunction(string name, CallDelegate callable, bool mergeOriginalAnalysis) { int lastIndex; IAnalysisSet def; if (TryGetMember(name, out def)) { foreach (var v in def) { if (!(v is SpecializedNamespace)) { this[name] = new SpecializedCallable(v, callable, mergeOriginalAnalysis).SelfSet; break; } } } else if ((lastIndex = name.LastIndexOf('.')) != -1 && TryGetMember(name.Substring(0, lastIndex), out def)) { var methodName = name.Substring(lastIndex + 1, name.Length - (lastIndex + 1)); foreach (var v in def) { BuiltinClassInfo ci = v as BuiltinClassInfo; if (ci != null) { IAnalysisSet classValue; if (ci.TryGetMember(methodName, out classValue)) { ci[methodName] = new SpecializedCallable(classValue.FirstOrDefault(), callable, mergeOriginalAnalysis).SelfSet; } else { ci[methodName] = new SpecializedCallable(null, callable, mergeOriginalAnalysis).SelfSet; } IAnalysisSet instValue; if (ci.Instance.TryGetMember(methodName, out instValue)) { ci.Instance[methodName] = new SpecializedCallable( instValue.FirstOrDefault(), ci.Instance, callable, mergeOriginalAnalysis).SelfSet; } else { ci.Instance[methodName] = new SpecializedCallable( null, ci.Instance, callable, mergeOriginalAnalysis).SelfSet; } } } } else { this[name] = new SpecializedCallable(null, callable, false); } }
/// <summary> /// Replaces a built-in function (specified by module name and function /// name) with a customized delegate which provides specific behavior /// for handling when that function is called. /// /// Currently this just provides a hook when the function is called - it /// could be expanded to providing the interpretation of when the /// function is called as well. /// </summary> private void SpecializeFunction(string moduleName, string name, CallDelegate callable, bool mergeOriginalAnalysis, bool save) { ModuleReference module; int lastDot; string realModName = null; if (Modules.TryGetImportedModule(moduleName, out module)) { IModule mod = module.Module as IModule; if (mod != null) { mod.SpecializeFunction(name, callable, mergeOriginalAnalysis); return; } } else if ((lastDot = moduleName.LastIndexOf('.')) != -1 && Modules.TryGetImportedModule(realModName = moduleName.Substring(0, lastDot), out module)) { IModule mod = module.Module as IModule; if (mod != null) { mod.SpecializeFunction(moduleName.Substring(lastDot + 1, moduleName.Length - (lastDot + 1)) + "." + name, callable, mergeOriginalAnalysis); return; } } if (save) { SaveDelayedSpecialization(moduleName, name, callable, realModName, mergeOriginalAnalysis); } }
public void SpecializeFunction(string name, CallDelegate callable, bool mergeOriginalAnalysis) { lock (this) { if (_specialized == null) { _specialized = new Dictionary<string, Tuple<CallDelegate, bool>>(); } _specialized[name] = Tuple.Create(callable, mergeOriginalAnalysis); } }
private static CallResult Call <T>(CallDelegate <T> callDelegate, T parameter) { var errCode = 0; var message = new byte[CONST_MessageSize]; var res = callDelegate(parameter, ref errCode, message, CONST_MessageSize); return(new CallResult(new ReturnValue(res), errCode, TypeConverter.ByteToString(message))); }
protected CallDelegate varCallBackBarcode; // это тот самый член-делегат :)) public bool StartScan(CallDelegate parCallBackBarcode) { if (parCallBackBarcode == null) { return(false); } varCallBackBarcode = parCallBackBarcode; return(init()); }
public CallDelegate Build() { CallDelegate callDelegate = _last; foreach (var m in middlewareList.Reverse()) { callDelegate = m(callDelegate); } return(CallProxy = callDelegate); }
private void SaveDelayedSpecialization(string moduleName, string name, CallDelegate callable, string realModName, bool mergeOriginalAnalysis) { lock (_specializationInfo) { if (!_specializationInfo.TryGetValue(realModName ?? moduleName, out var specList)) { _specializationInfo[realModName ?? moduleName] = specList = new List <SpecializationInfo>(); } specList.Add(new SpecializationInfo(moduleName, name, callable, mergeOriginalAnalysis)); } }
///<summary>Calls a function for each element in selection.</summary> ///<param name="dataFunc">A function that is called for each element. It is given the element, the bound datum, and the element's order within it's group.</param> public Selection <TElementType, TDataType, TParentDataType> Call(CallDelegate dlgt) { foreach (var groupWithData in _groups) { var id = 0; foreach (var visualElement in groupWithData.Elements) { dlgt(visualElement, (TDataType)visualElement.GetBoundData(), id++); } } return(this); }
private static void SpecializeVariableDef(VariableDef def, CallDelegate callable, bool mergeOriginalAnalysis) { List<AnalysisValue> items = new List<AnalysisValue>(); foreach (var v in def.TypesNoCopy) { if (!(v is SpecializedNamespace) && v.DeclaringModule != null) { items.Add(v); } } def._dependencies = default(SingleDict<IVersioned, ReferenceableDependencyInfo>); foreach (var item in items) { def.AddTypes(item.DeclaringModule, new SpecializedCallable(item, callable, mergeOriginalAnalysis).SelfSet); } }
static void Main(string[] args) { //实例化委托 CallDelegate<int, float> delegateBig = new CallDelegate<int, float>(new ImplementingClass().WhichIsBig); //调用委托方法,执行ImplementingClass WhichIsBig float big = delegateBig(10, 20.5f); // 输出最大值20.5 Console.WriteLine(big); // 输入任意键退出 Console.ReadKey(); }
public MapWhenMiddleware(CallDelegate next, MapWhenOptions options) { if (next == null) { throw new ArgumentNullException(nameof(next)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } this._next = next; this._options = options; }
static void Main(string[] args) { //实例化委托 CallDelegate <int, float> delegateBig = new CallDelegate <int, float>(new ImplementingClass().WhichIsBig); //调用委托方法,执行ImplementingClass WhichIsBig float big = delegateBig(10, 20.5f); // 输出最大值20.5 Console.WriteLine(big); // 输入任意键退出 Console.ReadKey(); }
private void SafeRaiseEvent(CallDelegate del, Call call) { if (del == null) { return; } var invocationList = del.GetInvocationList(); foreach (var current in invocationList) { ((CallDelegate)current).BeginInvoke(call, _raiseCallEventCallback, current); } }
private void Call(CallDelegate callDelegate) { foreach (IMod mod in mods) { try { if (!ModManager.IsModDisabled(mod)) { callDelegate(mod); } } catch (Exception ex) { GeneralManager.Instance.LogToFileOrConsole("[PromDate] " + mod.Name + " threw " + ex); } } }
public void Register <T>(string method, CallDelegate <T> handler) { ProtoCall call; if (!this.protos.TryGetValue(method, out call)) { this.protos.Add(method, new ProtoCall() { Type = typeof(T), Handler = handler, }); } else { call.Handler = handler; } }
static void Main(string[] args) { // 3. 在程序中创建委托实例与步骤2创建的方法相关联 CallDelegate delegateBig = new CallDelegate(new ImplementingClass().WhichIsBig); // 4. 用委托调用相关联的方法,执行ImplementingClass WhichIsBig int big = delegateBig(10, 20); // 另一种使用委托的方式, 执行ImplementingClass WhichIsSmall int small = Process(10, 20, new CallDelegate(new ImplementingClass().WhichIsSmall)); // 输出 Console.WriteLine(big); // 输出最大值20 Console.WriteLine(small); // 输出最小值10 // 输入任意键退出 Console.ReadKey(); }
static void Main(string[] args) { // 3. 在程序中创建委托实例与步骤2创建的方法相关联 CallDelegate delegateBig = new CallDelegate(new ImplementingClass().WhichIsBig); // 4. 用委托调用相关联的方法,执行ImplementingClass WhichIsBig int big = delegateBig(10, 20); // 另一种使用委托的方式, 执行ImplementingClass WhichIsSmall int small = Process(10, 20, new CallDelegate(new ImplementingClass().WhichIsSmall)); // 输出 Console.WriteLine(big); // 输出最大值20 Console.WriteLine(small); // 输出最小值10 // 输入任意键退出 Console.ReadKey(); }
/// <summary> /// 独立信令 呼叫接口 /// 用于用户新开一个频道并邀请对方加入频道,如果返回码不是200、10201、10202时,sdk会主动关闭频道,标记接口调用失败 /// 该接口为组合接口,等同于用户先创建频道,成功后加入频道并邀请对方 /// </summary> /// <param name="param">呼叫的传入参数</param> /// <param name="cb">结果回调见NimSignalingDef.cs</param> public static void Call(NIMSignalingCallParam param, CallDelegate cb) { int nSizeOfParam = Marshal.SizeOf(param); IntPtr param_ptr = Marshal.AllocHGlobal(nSizeOfParam); try { Marshal.StructureToPtr(param, param_ptr, false); var user_ptr = NimUtility.DelegateConverter.ConvertToIntPtr(cb); SignalingNativeMethods.nim_signaling_call(param_ptr, NimSignalingCallCb, user_ptr); } catch (Exception ex) { } finally { Marshal.FreeHGlobal(param_ptr); } }
private IAnalysisSet GetFunction(Node node, AnalysisUnit unit, string name, CallDelegate callable) { lock (_callables) { if (_callables.TryGetValue(name, out var res)) { return(res); } } if (unit.ForEval) { return(null); } var inner = _inner.GetMember(node, unit, name).OfType <BuiltinFunctionInfo>().FirstOrDefault(); lock (_callables) { return(_callables[name] = new SpecializedCallable(inner, callable, false)); } }
protected async Task <TResult> Call <TResult>(CallDelegate <TResult> call) { var callId = NewGuid(); CallRecorded callRecorded; if (TryPop(out callRecorded)) { if (callRecorded.ExceptionMessage == null) { return(_serializer.Deserialize <TResult>(callRecorded.Payload)); } throw new TaskFailedException(callRecorded.ExceptionMessage, callRecorded.ExceptionStackTrace); } // flush before calling external system await FlushEvents().ConfigureAwait(false); var result = default(TResult); TaskFailedException exceptionToThrow = null; try { result = await call(callId).ConfigureAwait(false); } catch (Exception ex) { exceptionToThrow = new TaskFailedException(ex.Message, ex.StackTrace); } if (exceptionToThrow == null) { var payload = _serializer.Serialize(result); Append(new CallRecorded(payload)); // don't flush after call, it's assumed that it's idempotent return(result); } Append(new CallRecorded(exceptionToThrow.Message, exceptionToThrow.StackTrace)); throw exceptionToThrow; }
public InfoView(CallDelegate callDelegate, EmailDelegate emailDelegate) { _infoLabel = ViewFactory.CreateUILabel(); _infoImage = new UIImageView(); _infoPhoneButton = UIButton.FromType(UIButtonType.Custom); _infoEmailButton = UIButton.FromType(UIButtonType.Custom); AddSubview(_infoImage); AddSubview(_infoLabel); AddSubview(_infoPhoneButton); AddSubview(_infoEmailButton); BackgroundColor = UIColor.White; _callDelegate = callDelegate; _emailDelegate = emailDelegate; _infoPhoneButton.TouchUpInside += InfoPhoneButton_TouchUpInside; _infoEmailButton.TouchUpInside += InfoEmailButton_TouchUpInside; }
void WriteLog(string message) { CallDelegate callDelegate = delegate { if (richTextBox1.Lines.Length > 500) { richTextBox1.Clear(); } if (!message.EndsWith("\r\n")) { this.richTextBox1.AppendText("\r\n"); } this.richTextBox1.AppendText(message); richTextBox1.Focus(); this.richTextBox1.Select(this.richTextBox1.TextLength, 0); this.richTextBox1.ScrollToCaret(); }; if (this.richTextBox1.InvokeRequired) { this.richTextBox1.Invoke(callDelegate); } else { if (richTextBox1.Lines.Length > 500) { richTextBox1.Clear(); } if (!message.EndsWith("\r\n")) { this.richTextBox1.AppendText("\r\n"); } this.richTextBox1.AppendText(message); this.richTextBox1.SelectionStart = richTextBox1.Text.Length; richTextBox1.Focus(); } }
void IModule.SpecializeFunction(string name, CallDelegate callable, bool mergeOriginalAnalysis) { foreach (var member in _members.OfType<IModule>()) { member.SpecializeFunction(name, callable, mergeOriginalAnalysis); } }
public SpecializationInfo(string moduleName, string name, CallDelegate callable, bool mergeOriginalAnalysis) { ModuleName = moduleName; Name = name; Callable = callable; SuppressOriginalAnalysis = mergeOriginalAnalysis; }
private void SpecializeOneFunction(string name, CallDelegate callable, bool mergeOriginalAnalysis) { int lastIndex; VariableDef def; if (Scope.TryGetVariable(name, out def)) { SpecializeVariableDef(def, callable, mergeOriginalAnalysis); } else if ((lastIndex = name.LastIndexOf('.')) != -1 && Scope.TryGetVariable(name.Substring(0, lastIndex), out def)) { var methodName = name.Substring(lastIndex + 1, name.Length - (lastIndex + 1)); foreach (var v in def.TypesNoCopy) { ClassInfo ci = v as ClassInfo; if (ci != null) { VariableDef methodDef; if (ci.Scope.TryGetVariable(methodName, out methodDef)) { SpecializeVariableDef(methodDef, callable, mergeOriginalAnalysis); } } } } }
private static void SpecializeVariableDef(VariableDef def, CallDelegate callable, bool mergeOriginalAnalysis) { List<AnalysisValue> items = new List<AnalysisValue>(); foreach (var v in def.TypesNoCopy) { if (!(v is SpecializedNamespace) && v.DeclaringModule != null) { items.Add(v); } } def._dependencies = default(SingleDict<IVersioned, ReferenceableDependencyInfo>); foreach (var item in items) { def.AddTypes(item.DeclaringModule, new SpecializedCallable(item, callable, mergeOriginalAnalysis).SelfSet); } }
public SpecializedCallable(AnalysisValue original, AnalysisValue inst, CallDelegate callable, bool mergeNormalAnalysis) : base(original, inst) { _callable = callable; _mergeOriginalAnalysis = mergeNormalAnalysis; }
public void SpecializeFunction(string name, CallDelegate callable, bool mergeOriginalAnalysis) { lock (this) { if (_specialized == null) { _specialized = new Dictionary<string, Tuple<CallDelegate, bool>>(); } _specialized[name] = Tuple.Create(callable, mergeOriginalAnalysis); } }
public SpecializedFunctionValue(ProjectEntry projectEntry, string name, CallDelegate func, string documentation = null, ExpandoValue prototype = null, params ParameterResult[] signature) : base(projectEntry, name, documentation, prototype, signature) { _func = func; }
public CallableFunctionSpecializer(CallDelegate callDelegate) { _delegate = callDelegate; }
public PatternSpecialization(CallDelegate specialization, bool callBase, params ExpectedChild[] children) : base(specialization, callBase) { Body = new ExpectedNode( typeof(Block), children ); }
public CloneSpecialization(CallDelegate specialization) : base(specialization, false) { }
public PatternSpecialization(CallDelegate specialization, params ExpectedChild[] children) : this(specialization, true, children) { }
public BaseSpecialization(CallDelegate specialization, bool callBase) { Specialization = specialization; CallBase = callBase; }
public BaseSpecialization(CallDelegate specialization) { Specialization = specialization; CallBase = true; }
private void SaveDelayedSpecialization(string moduleName, string name, CallDelegate callable, string realModName, bool mergeOriginalAnalysis) { lock (_specializationInfo) { List<SpecializationInfo> specList; if (!_specializationInfo.TryGetValue(realModName ?? moduleName, out specList)) { _specializationInfo[realModName ?? moduleName] = specList = new List<SpecializationInfo>(); } specList.Add(new SpecializationInfo(moduleName, name, callable, mergeOriginalAnalysis)); } }
/// <summary> /// Replaces a built-in function (specified by module name and function /// name) with a customized delegate which provides specific behavior /// for handling when that function is called. /// </summary> /// <remarks>New in 2.0</remarks> public void SpecializeFunction(string moduleName, string name, CallDelegate callable, bool mergeOriginalAnalysis = false) { SpecializeFunction(moduleName, name, callable, mergeOriginalAnalysis, true); }
public void SpecializeFunction(string name, CallDelegate callable, bool mergeOriginalAnalysis) { }
public SpecializedFunctionValue(ProjectEntry projectEntry, string name, CallDelegate func, OverloadResult[] overloads, string documentation = null, ExpandoValue prototype = null) : base(projectEntry, name, overloads, documentation, prototype) { _func = func; }
// 在函数内使用委托 public static int Process(int a, int b, CallDelegate call) { return call(a, b); }
public POS(int parPort = -1, bool parIsLog = false, CallDelegate pardelCallAudit = null) { this.varPort = parPort; delCallAudit = pardelCallAudit; }
private BuiltinFunctionValue SpecializedFunction(string name, CallDelegate value, string documentation = null, params ParameterResult[] parameters) { return new SpecializedFunctionValue(_analyzer._builtinEntry, name, value, documentation, null, parameters); }
/// <summary> /// Replaces a built-in function (specified by module name and function /// name) with a customized delegate which provides specific behavior /// for handling when that function is called. /// </summary> /// <remarks>New in 2.0</remarks> public void SpecializeFunction(string moduleName, string name, CallDelegate callable, bool mergeOriginalAnalysis = false) { SpecializeFunction(moduleName, name, callable, mergeOriginalAnalysis, true); }
public CallableFunctionSpecializer(CallDelegate callDelegate) { _delegate = callDelegate; }
public SpecializedUserFunctionValue(CallDelegate call, FunctionObject node, AnalysisUnit declUnit, EnvironmentRecord declScope, bool callBase) : base(node, declUnit, declScope) { _call = call; _callBase = callBase; }
public SpecializedCallable(AnalysisValue original, AnalysisValue inst, CallDelegate callable, bool mergeNormalAnalysis) : base(original, inst) { _callable = callable; _mergeOriginalAnalysis = mergeNormalAnalysis; }
public SpecializedUserFunctionValue(CallDelegate call, FunctionObject node, AnalysisUnit declUnit, EnvironmentRecord declScope, bool callBase) : base(node, declUnit, declScope) { _call = call; _callBase = callBase; }