private ISet <IMethodDeclaration> findMemberCandidates(bool checkInstance) { MethodSelector selector = methodCall.getSelector(); if (selector.getParent() == null) { // if called from a member method, could be a member method called without this/self InstanceContext instance = context.getClosestInstanceContext(); if (instance != null) { IType type = instance.getInstanceType(); ConcreteCategoryDeclaration cd = context.getRegisteredDeclaration <ConcreteCategoryDeclaration>(type.GetTypeName()); if (cd != null) { MethodDeclarationMap members = cd.getMemberMethods(context, selector.getName()); if (members != null) { return(new HashSet <IMethodDeclaration>(members.Values)); } } } return(new HashSet <IMethodDeclaration>()); } else { IType parentType = selector.checkParentType(context, checkInstance); return(parentType != null?parentType.getMemberMethods(context, selector.getName()) : new HashSet <IMethodDeclaration>()); } }
private void Start() { _packetDispatcher = new MethodSelector<Packet>(this, (ref Packet source, out string key) => { key = source.PacketId.ToString(); source.SkipHeader(); }); _udp = new UDPClient(); _udp.EventRead += NetworkEvent_Receive; _udp.EventClose += NetworkEvent_Close; _udp.Connect("127.0.0.1", 10201); _counter = new IntervalCounter(1000); _counter.Start(); (new IntervalTimer(1000, () => { DateTime now = DateTime.Now; Console.WriteLine(string.Format("[{0}/{1} {2}:{3}:{4}] recv: {5}", DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second, _counter.Value)); })).Start(); { Packet reqPacket = new Packet(Protocol.Echo_Req); Send(reqPacket); } }
public void ShouldNotSelectFinalMethodsFromInterface() { var methodSelector = new MethodSelector(); var methods = methodSelector.Execute(typeof(ClassWithOneMethod), Type.EmptyTypes); Assert.False(methods.Any(m => m.IsFinal)); }
public void Execute_ClassWithPrivateMethod_DoesNotReturnPrivateMethod() { var methodSelector = new MethodSelector(); var methods = methodSelector.Execute(typeof(ClassWithPrivateMethod), Type.EmptyTypes); Assert.True(!methods.Any(m => m.IsDeclaredBy<ClassWithPrivateMethod>())); }
public void Execute_InterfaceWithMethod_ReturnsInterfaceMethodsAndMethodsInheritedFromObject() { var methodSelector = new MethodSelector(); var methods = methodSelector.Execute(typeof(IMethodWithNoParameters), Type.EmptyTypes); Assert.Equal(4, methods.Length); }
public void Execute_ClassWithPrivateMethod_DoesNotReturnPrivateMethod() { var methodSelector = new MethodSelector(); var methods = methodSelector.Execute(typeof(ClassWithPrivateMethod), Type.EmptyTypes); Assert.True(!methods.Any(m => m.IsDeclaredBy <ClassWithPrivateMethod>())); }
public void Execute_InterfaceWithEvent_DoesNotReturnAddAndRemoveMethods() { var methodSelector = new MethodSelector(); var methods = methodSelector.Execute(typeof(IClassWithEvent), Type.EmptyTypes); Assert.True(!methods.Any(m => m.IsDeclaredBy<IClassWithEvent>())); }
public void Execute_ClassWithProtectedVirtualMethod_ReturnsProtectedVirtualMethod() { var methodSelector = new MethodSelector(); var methods = methodSelector.Execute(typeof(ClassWithVirtualProtectedMethod), Type.EmptyTypes); Assert.True(methods.Any(m => m.Name == "Execute")); }
public void Execute_InterfaceWithEvent_DoesNotReturnAddAndRemoveMethods() { var methodSelector = new MethodSelector(); var methods = methodSelector.Execute(typeof(IClassWithEvent), Type.EmptyTypes); Assert.True(!methods.Any(m => m.IsDeclaredBy <IClassWithEvent>())); }
public void Execute_InterfaceWithProperty_DoesNotReturnGetAndSetMethods() { var methodSelector = new MethodSelector(); var methods = methodSelector.Execute(typeof(IClassWithProperty), Type.EmptyTypes); Assert.True(!methods.Any(m => m.IsDeclaredBy<IClassWithProperty>())); }
public void Execute_InterfaceWithProperty_DoesNotReturnGetAndSetMethods() { var methodSelector = new MethodSelector(); var methods = methodSelector.Execute(typeof(IClassWithProperty), Type.EmptyTypes); Assert.True(!methods.Any(m => m.IsDeclaredBy <IClassWithProperty>())); }
public void Execute_ClassWithVirtualMethod_ReturnsOnlyVirtualMethods() { var methodSelector = new MethodSelector(); var methods = methodSelector.Execute(typeof(ClassWithVirtualAndNonVirtualMethod), Type.EmptyTypes); Assert.True(methods.All(m => m.IsVirtual)); }
private bool IsMethodBootstrapInterceptorNeeded(IEnumerable <Type> types) { var methodInterceptorsMap = AopInterceptorContainer.FindInterceptors(AttributeTargets.Method); return(types.SelectMany(type => MethodSelector.GetAllMethods(type)) .SelectMany(m => m.GetCustomAttributes()) .Select(attr => attr.GetType()) .Any(attrType => methodInterceptorsMap.ContainsKey(attrType))); }
private OdinSelector <DelegateInfo> CreateSelector(Rect arg) { arg.xMin -= arg.width; var info = this.GetDelegateInfo(); var sel = new MethodSelector(info.Target, tempType); sel.SetSelection(info); sel.ShowInPopup(arg); return(sel); }
public virtual void Engage() { // Iterate the selected methods var selector = new MethodSelector(); foreach (var method in selector.Select(context)) { var methodInjector = new MethodInjector(context, method, ResolveArguments(method)); methodInjector.Inject(); } }
public void Execute_ClassWithNoMethods_ReturnsInterceptableMethodsInheritedFromObject() { var methodSelector = new MethodSelector(); var methods = methodSelector.Execute(typeof(ClassWithNoMethods), Type.EmptyTypes); Assert.Equal(3, methods.Length); Assert.True(methods.Any(m => m.Name == "ToString")); Assert.True(methods.Any(m => m.Name == "GetHashCode")); Assert.True(methods.Any(m => m.Name == "Equals")); }
public ArrayElementsGroup(IObjectValueRole <TValue> serializedPropertyRole, int arraySize, MethodSelector getMethodElementSelector, IValueServicesFacade <TValue> valueServices, ILogger logger) : base($"[0..{arraySize - 1}]") { mySerializedPropertyRole = serializedPropertyRole; myArraySize = arraySize; myGetMethodElementSelector = getMethodElementSelector; myValueServices = valueServices; myLogger = logger; }
private ISet <IMethodDeclaration> findGlobalCandidates(bool checkInstance) { MethodSelector selector = methodCall.getSelector(); if (selector.getParent() != null) { return(new HashSet <IMethodDeclaration>()); } MethodDeclarationMap globals = context.getRegisteredDeclaration <MethodDeclarationMap>(selector.getName()); return(globals != null ? new HashSet <IMethodDeclaration>(globals.Values) : new HashSet <IMethodDeclaration>()); }
public IBeanDefinitionCollection ParseBeanMethods(Type configType) { var defCol = new BeanDefinitionCollection(); defCol.AddRange(MethodSelector.GetAllMethodsByAttribute <BeanAttribute>(configType) .SelectMany(beanMethod => { var def = new MemberMethodBeanDefinition(beanMethod); return(new[] { def, new MemberMethodFactoryBeanDefinition(def) }); }) .ToArray()); return(defCol); }
public object PostConstruct(Type type, object bean) { var postConstructors = MethodSelector.GetAllMethodsByAttribute <PostConstructAttribute>(type); // context.Existing.GetType() foreach (var pc in postConstructors) { if (pc.GetParameters().Length > 0 || pc.ReturnType != typeof(void)) { throw new InvalidOperationException("no-arg, void"); } pc.Invoke(bean, new object[0]); } return(bean); }
protected override void DrawPropertyLayout(GUIContent label) { SirenixEditorGUI.BeginBox(); { SirenixEditorGUI.BeginToolbarBoxHeader(); { var rect = GUILayoutUtility.GetRect(0, 19); var unityObjectFieldRect = rect.Padding(2).AlignLeft(rect.width / 2); var methodSelectorRect = rect.Padding(2).AlignRight(rect.width / 2 - 5); var dInfo = this.GetDelegateInfo(); var intlabel = new GUIContent("some type"); EditorGUI.BeginChangeCheck(); var someType = SirenixEditorFields.Dropdown(intlabel, tempType, SupportedReturnTypes); /*public static bool Dropdown<T>(Rect rect, IList<int> selected, IList<T> items, bool multiSelection)*/ var newTarget = SirenixEditorFields.UnityObjectField(unityObjectFieldRect, dInfo.Target, typeof(UnityEngine.Object), true); if (EditorGUI.EndChangeCheck()) { this.tmpTarget = newTarget; this.tempType = someType; } EditorGUI.BeginChangeCheck(); var selectorText = (dInfo.Method == null || this.tmpTarget) ? "Select a method" : dInfo.Method.Name; var newMethod = MethodSelector.DrawSelectorDropdown(methodSelectorRect, selectorText, this.CreateSelector); if (EditorGUI.EndChangeCheck()) { this.CreateAndAssignNewDelegate(newMethod.FirstOrDefault()); this.tmpTarget = null; } } SirenixEditorGUI.EndToolbarBoxHeader(); // Draws the rest of the ICustomEvent, and since we've drawn the label, we simply pass along null. for (int i = 0; i < this.Property.Children.Count; i++) { var child = this.Property.Children[i]; if (child.Name == "Result") { continue; } child.Draw(); } } SirenixEditorGUI.EndBox(); }
private IMethodDeclaration getClosureDeclaration(Context context, ClosureValue closure) { IMethodDeclaration decl = closure.Method; if (decl.getMemberOf() != null) { // the closure references a member method (useful when a method reference is needed) // in which case we may simply want to return that method to avoid spilling context into method body // this is only true if the closure comes straight from the method's instance context // if the closure comes from an accessible context that is not the instance context // then it is a local variable that needs the closure context to be interpreted MethodSelector selector = methodCall.getSelector(); Context declaring = context.contextForValue(selector.getName()); if (declaring == closure.getContext()) { return(decl); } } return(new ClosureDeclaration(closure)); }
public IMethodDeclaration findCandidateReference(bool checkInstance) { MethodSelector selector = methodCall.getSelector(); if (selector.getParent() != null) { return(null); } if (checkInstance) { if (context.hasValue(selector.getName())) { IValue value = context.getValue(selector.getName()); if (value is ClosureValue) { return(getClosureDeclaration(context, (ClosureValue)value)); } else if (value is ArrowValue) { return(getArrowDeclaration((ArrowValue)value)); } } } else { INamed named = context.getInstance(selector.getName(), true); if (named == null) { return(null); } IType type = named.GetIType(context).Resolve(context); if (type is MethodType) { return(((MethodType)type).Method.AsReference()); } } return(null); }
public void GetAllMethodsByAttribute_InternalMethod() { var a = MethodSelector.GetAllMethodsByAttribute <BeanAttribute>(typeof(Config)).Where(m => m.Name == "F"); Assert.Single(a); }
public void GetAllMethodsByAttribute_ImplVirtualMethodAnnotated() { var a = MethodSelector.GetAllMethodsByAttribute <BeanAttribute>(typeof(Config)).Where(m => m.Name == "E"); Assert.Single(a); }
public MethodCall(MethodSelector method) { this.selector = method; }
public MethodCall(MethodSelector selector, ArgumentList arguments) { this.selector = selector; this.arguments = arguments; }