public void Must_return_a_collection_of_class_method_accessors(Type classType) { // Arrange var expected = classType.Method("InvariantMethod").AsMany(); var source = classType.Instantiate(); // Act var actual = sut.GetMethods(source); // Assert actual.Should().BeEquivalentByName(expected); }
public override void Enumerate(IMemberCompletionAcceptor acceptor) { if (acceptor == null) { throw ExceptionBuilder.ArgumentNull("acceptor"); } // Report all columns accessible by the table ref. TableRefBinding tableRefBinding = new TableRefBinding(null, _tableBinding, _correlationName); foreach (ColumnBinding columnBinding in _tableBinding.Columns) { ColumnRefBinding columnRefBinding = new ColumnRefBinding(tableRefBinding, columnBinding); acceptor.AcceptColumnRef(columnRefBinding); } // Now contribute any methods accessible by the row type. IMethodProvider methodProvider = _scope.DataContext.MetadataContext.MethodProviders[_tableBinding.RowType]; if (methodProvider != null) { MethodBinding[] methods = methodProvider.GetMethods(_tableBinding.RowType); foreach (MethodBinding methodBinding in methods) { acceptor.AcceptMethod(methodBinding); } } }
public override void Enumerate(IMemberCompletionAcceptor acceptor) { if (acceptor == null) { throw ExceptionBuilder.ArgumentNull("acceptor"); } NamedConstantExpression namedConstantExpression = _expressionBeforeDot as NamedConstantExpression; ParameterExpression parameterExpression = _expressionBeforeDot as ParameterExpression; IList <PropertyBinding> properties = null; if (namedConstantExpression == null && parameterExpression == null) { // The properties must be provided by a regular property provider. IPropertyProvider propertyProvider = _scope.DataContext.MetadataContext.PropertyProviders[_expressionBeforeDot.ExpressionType]; if (propertyProvider != null) { properties = propertyProvider.GetProperties(_expressionBeforeDot.ExpressionType); } } else { // The expression before the dot is named constant or a parameter. In both cases, the properties // could be contributed as custom properties. if (namedConstantExpression != null) { properties = namedConstantExpression.Constant.CustomProperties; } else { properties = parameterExpression.Parameter.CustomProperties; } } if (properties != null) { foreach (PropertyBinding propertyBinding in properties) { acceptor.AcceptProperty(propertyBinding); } } // Now contribute any methods IMethodProvider methodProvider = _scope.DataContext.MetadataContext.MethodProviders[_expressionBeforeDot.ExpressionType]; if (methodProvider != null) { MethodBinding[] methods = methodProvider.GetMethods(_expressionBeforeDot.ExpressionType); foreach (MethodBinding methodBinding in methods) { acceptor.AcceptMethod(methodBinding); } } }
private IEnumerable <ValidationResult> ValidateInvariants(object source) { foreach (var method in methodProvider.GetMethods(source)) { foreach (var result in methodValidator.Validate(source, method)) { yield return(result); } } }
/// <summary> /// Returns all methods matching the identifier. /// </summary> /// <param name="type">The type to search the methods in.</param> /// <param name="identifier">The identifier to match the methods.</param> public MethodBinding[] FindMethod(Type type, Identifier identifier) { if (type == null) { throw ExceptionBuilder.ArgumentNull("type"); } if (identifier == null) { throw ExceptionBuilder.ArgumentNull("identifier"); } // Get method provider responsible for the given type. IMethodProvider methodProvider = _methodProviders[type]; if (methodProvider == null) { return(new MethodBinding[0]); } // Get properties from the provider. MethodBinding[] methods; try { methods = methodProvider.GetMethods(type); } catch (NQueryException) { throw; } catch (Exception ex) { throw ExceptionBuilder.IMethodProviderGetMethodsFailed(ex); } // Return all methods that match the given name. List <MethodBinding> result = new List <MethodBinding>(); foreach (MethodBinding methodBinding in methods) { if (identifier.Matches(methodBinding.Name)) { result.Add(methodBinding); } } return(result.ToArray()); }
private void CompileMethods() { foreach (MethodBase method in _methodProvider.GetMethods()) { try { var asyncAttribute = (AsyncStateMachineAttribute)method.GetCustomAttribute(typeof(AsyncStateMachineAttribute)); if (asyncAttribute == null) { CompileSyncMethod(method); } else { CompileAsyncMethod(method, asyncAttribute); } } catch (Exception ex) { Console.WriteLine(method.DeclaringType.Name + "." + method.Name + ":" + ex.Message); } } }