//public string TypeName //{ // get { return TypeUtils.ToDisplayString(Parameter.ParameterType, true); } //} public static ParameterDom[] BuildParameters(ParameterInfo[] piAr, XElement parentDoc) { if(piAr==null || piAr.Length==0) return new ParameterDom[0]; if(parentDoc==null) return piAr.Select(_ => new ParameterDom(_)).ToArray(); var pd = new ParameterDictionary(parentDoc, "param"); return piAr .Select( _ => new ParameterDom(_){DocInfo = pd[_.Name]}) .ToArray(); }
private void AddMethod(MethodInfo info, CodeTypeDeclaration target) { var method = new CodeMemberMethod { Attributes = MemberAttributes.Public, Name = info.Name, ReturnType = new CodeTypeReference(info.ReturnType), }; var allParameters = info.GetParameters().ToArray(); var parameters = new ParameterInfo[0]; if (allParameters.Length > 1) parameters = allParameters.Skip(1).ToArray(); method.Parameters.AddRange( parameters.Select(p => new CodeParameterDeclarationExpression(p.ParameterType, p.Name)).ToArray()); //Invoke var statement = new CodeMethodReturnStatement(); string parms = GetInvokeParametersString(parameters); statement.Expression = new CodeSnippetExpression(string.Format("Invoke(d => d.{0}({1}))", info.Name, parms)); method.Statements.Add(statement); target.Members.Add(method); }
internal static object[] CreateConstructorParamtersInstances(this IoC ioc, ParameterInfo[] src) { return src .Select(pi => pi.IocParameterIsArray() ? ioc.GetParameterAsArray(pi.GetIocRealType()) : ioc.GetObject(pi.ParameterType)).ToArray(); }
private bool ConstructorHasAllMethodArgs(ParameterInfo[] methodArgs, ParameterInfo[] constructorParams) { var consArgTypes = constructorParams.Select(a => a.ParameterType).ToList(); var methodArgTypes = methodArgs.Select(a => a.ParameterType).ToList(); return !consArgTypes.Except(methodArgTypes).Any() && !methodArgTypes.Except(consArgTypes).Any(); }
private void ValidateParameters(ParameterInfo[] parameters, object[] parameterValues) { if (parameters.Length == parameterValues.Length && ParameterTypesMatch(parameters, parameterValues)) return; var expectedShape = CreateShape(parameters.Select(x => x.ParameterType)); var actualShape = CreateShape(parameterValues.Select((x, index) => x == null ? parameters[index].ParameterType : x.GetType())); throw new InvalidParadigmExemplarException(string.Format("Invalid paradigm exemplar: expected it to have a shape of {0}, but it had a shape of {1}", expectedShape, actualShape)); }
private static object[] GetParameterValues(TestContext context, ParameterInfo[] parameters) { Func<ParameterInfo, int, object> selectFunc = (parameter, index) => { context.WriteLine("{0} = {1}", parameter.Name, context.DataRow[index]); return context.DataRow[index]; }; return parameters.Select(selectFunc).ToArray(); }
private static Expression[] CreateParameterExpressions(ParameterInfo[] methodParams, ParameterExpression argsParameter) { return methodParams.Select( (parameter, index) => Expression.Convert( Expression.ArrayIndex(argsParameter, Expression.Constant(index)), parameter.ParameterType ) ).ToArray(); }
private static string CreateTypeName(string delegateName, ParameterInfo[] parameters) { var builder = new StringBuilder(); builder.Append(delegateName); builder.Append("<"); builder.Append(String.Join(",", parameters.Select(c => c.Name).ToArray())); builder.Append(">"); return builder.ToString(); }
private static Delegate GetCallMethodAsyncFuncInternal(Type serviceType, Type argumentType, ParameterInfo[] arguments, MethodInfo method, bool hasReturn) { if (arguments.Length > 0 && argumentType == null) throw new ArgumentException("parameterType can not be null when paras.Length > 0"); var serviceArgument = Expression.Parameter(typeof(object), "service"); var actionArgument = Expression.Parameter(typeof(object), "argument"); var asyncCallbackArgument = Expression.Parameter(typeof(AsyncCallback), "callback"); var stateArgument = Expression.Parameter(typeof(object), "state"); var convertService = Expression.Convert(serviceArgument, serviceType); var convertArgument = argumentType == null ? null : Expression.Convert(actionArgument, argumentType); MethodCallExpression call; if (arguments.Length > 1) { if (convertArgument == null) throw new ArgumentException("argumentType can't be null when arguments.Length > 1"); var callArgs = arguments .Select(it => (Expression)Expression.Property(convertArgument, it.Name)) .ToList(); callArgs.Add(asyncCallbackArgument); callArgs.Add(stateArgument); call = Expression.Call(convertService, method, callArgs); } else if (arguments.Length == 1) { call = Expression.Call(convertService, method, new Expression[] { convertArgument, asyncCallbackArgument, stateArgument }); } else { call = Expression.Call(convertService, method, new Expression[] { asyncCallbackArgument, stateArgument }); } var methodArgs = new[] { serviceArgument, actionArgument, asyncCallbackArgument, stateArgument }; LambdaExpression methodLam; if (hasReturn) { var convertCall = Expression.Convert(call, typeof(IAsyncResult)); methodLam = Expression.Lambda(convertCall, methodArgs); } else { methodLam = Expression.Lambda(call, methodArgs); } var methodFunc = methodLam.Compile(); return methodFunc; }
/// <summary> /// Compares the signature of the method with the given parameter types and returns true if /// all method parameters have the same order and type. Parameter names are not considered. /// </summary> /// <returns>True if the supplied parameter type array matches the method parameters array, false otherwise.</returns> public static bool HasParameterSignature(this MethodBase method, ParameterInfo[] parameters) { return method.GetParameters().Select(p => p.ParameterType).SequenceEqual(parameters.Select(p => p.ParameterType)); }
private object[] GetParameterData(ParameterInfo[] parameters, Fixture fixture) { return parameters .Select(p => new SpecimenContext(fixture).Resolve(p)) .ToArray(); }
private static string FormatParameters(ParameterInfo[] parameters) { return string.Join(",", parameters.Select(x => x.ParameterType.Name)); }
private void SetSignature(Type returnType, ParameterInfo returnParameter, Type[] parameters, ParameterInfo[] baseMethodParameters) { builder.SetSignature( returnType, #if FEATURE_EMIT_CUSTOMMODIFIERS returnParameter.GetRequiredCustomModifiers(), returnParameter.GetOptionalCustomModifiers(), #else null, null, #endif parameters, #if FEATURE_EMIT_CUSTOMMODIFIERS baseMethodParameters.Select(x => x.GetRequiredCustomModifiers()).ToArray(), baseMethodParameters.Select(x => x.GetOptionalCustomModifiers()).ToArray() #else null, null #endif ); }
public IdentifierImpl(string className, string methodName, ParameterInfo[] parameters) : this(className, methodName, parameters.Select(p => p.Name).ToArray(), ToParameterStringArray(parameters.Select(p => p.ParameterType).ToArray()), false) {}
private List<Parameter> BuildParameterList(ParameterInfo[] parameters, bool checkForExtensionMethods) { if (parameters == null || parameters.Length == 0) return null; return parameters.Select(a => new Parameter { Name = a.Name, TypeName = GetReadableTypeName(a.ParameterType), ParameterFlags = GetParameterFlags(a, checkForExtensionMethods) }).ToList(); }
private static IAstRefOrValue CreateCallMethod(MethodInfo mi, ParameterInfo[] parameters) { return AstBuildHelper.CallMethod( mi, mi.IsStatic ? null : new AstCastclassRef( AstBuildHelper.ReadFieldRV( new AstReadThis() { thisType = typeof(MethodInvokerBase) }, typeof(MethodInvokerBase).GetField("targetObject", BindingFlags.NonPublic | BindingFlags.Instance) ), mi.DeclaringType ), parameters.Select((p, idx) => (IAstStackItem)AstBuildHelper.ReadArgumentRV(idx + 1, typeof(object))).ToList() ); }
private static string BuildParameterPath(ParameterInfo[] parameters) { if(!parameters.Any()) return String.Empty; var parameterPath = Path.Combine(parameters.Select(p => $"{{{p.Name}}}").ToArray()); return $"/{parameterPath}"; }
private IEnumerable<object> get_parameters(ParameterInfo[] param_types) { return param_types.Select(x => Container.Current.get_a(x.ParameterType)); }
private string TypeNames(ParameterInfo[] parameters) { return String.Join(",", parameters.Select(p => p.ParameterType.FullName).ToArray()); }
internal XmlComment GetMethodDocumentation(Type type, string methodName, ParameterInfo[] parameters) { string paramString = string.Join(",", parameters.Select(p => p.ParameterType.FullName)); string attributeValue = type.FullName + "." + methodName + "(" + paramString + ")"; return GetXmlComment("//member[@name=\"M:" + attributeValue + "\"]"); }
private static Delegate GetCallMethodFuncInternal(Type serviceType, Type argumentType, ParameterInfo[] arguments, MethodInfo method, bool hasReturn) { #if NETCORE if (method.ReturnType.GetTypeInfo().IsGenericType && method.ReturnType.GetTypeInfo().BaseType == typeof(Task)) #else if (method.ReturnType.IsGenericType && method.ReturnType.BaseType == typeof(Task)) #endif return GetCallTaskMethodFuncInternal(serviceType, argumentType, arguments, method, hasReturn); if (arguments.Length > 0 && argumentType == null) throw new ArgumentException("parameterType can not be null when paras.Length > 0"); var serviceArgument = Expression.Parameter(typeof(object), "service"); var actionArgument = Expression.Parameter(typeof(object), "argument"); var convertService = Expression.Convert(serviceArgument, serviceType); var convertArgument = argumentType == null ? null : Expression.Convert(actionArgument, argumentType); MethodCallExpression call; if (arguments.Length > 1) { if (convertArgument == null) throw new ArgumentException("argumentType can't be null when arguments.Length > 1"); var callArgs = arguments .Select(it => Expression.Property(convertArgument, it.Name)) .ToList(); call = method.IsStatic ? Expression.Call(method, callArgs) : Expression.Call(convertService, method, callArgs); } else if (arguments.Length == 1) { call = method.IsStatic ? Expression.Call(method, new Expression[] { convertArgument }) : Expression.Call(convertService, method, new Expression[] { convertArgument }); } else { call = method.IsStatic ? Expression.Call(method) : Expression.Call(convertService, method); } var methodArgs = new[] { serviceArgument, actionArgument }; LambdaExpression methodLam; if (hasReturn) { var convertCall = Expression.Convert(call, typeof(object)); methodLam = Expression.Lambda(convertCall, methodArgs); } else { methodLam = Expression.Lambda(call, methodArgs); } var methodFunc = methodLam.Compile(); return methodFunc; }
private string GetPropertyRefId(PropertyInfo pinfo, ParameterInfo[] parameters) { StringBuilder sb = new StringBuilder(); sb.Append(pinfo.Name); if (parameters != null && parameters.Length > 0) { sb.Append("("); sb.Append(string.Join(",", parameters.Select(a => a.ParameterType.IsGenericParameter ? (a.ParameterType.DeclaringMethod != null ? "``" : "`") + a.ParameterType.GenericParameterPosition : GetReadableTypeName(a.ParameterType)).ToArray())); sb.Append(")"); } return sb.ToString().Replace('<', '{').Replace('>', '}').Replace(" ", ""); }
private string GetMethodRefId(MethodBase method, ParameterInfo[] parameters) { StringBuilder sb = new StringBuilder(); sb.Append(method.Name.Replace(".ctor", "#ctor")); if (method.IsGenericMethod) { var gp = method.GetGenericArguments(); if (gp.Length > 0) sb.Append("``").Append(gp.Length); } sb.Append("("); sb.Append(string.Join(",", parameters.Select(a => a.ParameterType.IsGenericParameter ? (a.ParameterType.DeclaringMethod != null ? "``" : "`") + a.ParameterType.GenericParameterPosition : GetReadableTypeName(a.ParameterType)).ToArray())); sb.Append(")"); return sb.ToString().Replace('<', '{').Replace('>', '}').Replace(" ", ""); }
private ParadigmParameter[] CreateParameters(ParameterInfo[] parameters, object[] parameterValues) { ValidateParameters(parameters, parameterValues); return parameters.Select((param, index) => new ParadigmParameter(param, parameterValues[index])).ToArray(); }
internal static string SummarizeTypes(ParameterInfo[] parameters) { var types = parameters.Select(p => p.ParameterType).ToArray(); return SummarizeTypes(types); }
public static List<string> GetParameterNames(ParameterInfo[] parameters) { return parameters .Select(parameter => parameter.Name) .ToList(); }
private static void EmitInvokeCore( ServiceInvokerEmitter emitter, MethodInfo targetOperation, ParameterInfo[] parameters, Type returnType, bool isWrapperNeeded ) { var methodReturnType = targetOperation.ReturnType == typeof( void ) ? typeof( Missing ) : targetOperation.ReturnType; var asyncInvokerIsDebugModeProperty = typeof( AsyncServiceInvoker<> ).MakeGenericType( methodReturnType ).GetProperty( "IsDebugMode", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic ); var il = emitter.GetInvokeCoreMethodILGenerator(); try { var endOfMethod = il.DefineLabel(); var unpackedArguments = parameters.Select( item => il.DeclareLocal( item.ParameterType, item.Name ) ).ToArray(); var serializers = unpackedArguments.Select( item => emitter.RegisterSerializer( item.LocalType ) ).ToArray(); var result = il.DeclareLocal( typeof( AsyncInvocationResult ), "result" ); /* * using( var argumentsItemUnpacker = arguments.ReadSubTree() ) * { * argumentsItemUnpacker. * ... * } */ var argumentsItemUnpacker = il.DeclareLocal( typeof( Unpacker ), "argumentsItemUnpacker" ); il.EmitAnyLdarg( 1 ); il.EmitAnyCall( _unpackerReadSubtreeMethod ); il.EmitAnyStloc( argumentsItemUnpacker ); il.BeginExceptionBlock(); for ( int i = 0; i < parameters.Length; i++ ) { /* * if ( !argumentsItemUnpacker.Read() ) * { * throw new SerializationException( String.Format( CultureInfo.CurrentCuture, "Stream unexpectedly ends at argument {0}.", N ) ); * } * * T argN; * try * { * argN = this._serializerN.UnpackFrom( argumentsItemUnpacker ); * } * catch( Exception ex ) * { * return new AsyncInvocatonResult( InvocationHelper.HandleArgumentDeserializationException( ex, "argN" ) ); * return; * } */ il.EmitAnyLdloc( argumentsItemUnpacker ); il.EmitAnyCall( _unpackerReadMethod ); var endIf = il.DefineLabel(); il.EmitBrtrue_S( endIf ); var args = il.DeclareLocal( typeof( object[] ), "args" ); il.EmitNewarr( typeof( object ), 1 ); il.EmitAnyStloc( args ); il.EmitGetProperty( _cultureInfoCurrentCultureProperty ); il.EmitLdstr( "Stream unexpectedly ends at arguments array {0}." ); il.EmitAnyLdloc( args ); il.EmitAnyLdc_I4( 0 ); il.EmitAnyLdc_I4( i ); il.EmitBox( typeof( int ) ); il.EmitStelem( typeof( object ) ); il.EmitAnyLdloc( args ); il.EmitAnyCall( _stringFormatMethod ); il.EmitNewobj( _serializationExceptionCtorStringConstructor ); il.EmitThrow(); il.MarkLabel( endIf ); il.BeginExceptionBlock(); il.EmitAnyLdarg( 0 ); il.EmitLdfld( serializers[ i ] ); il.EmitAnyLdloc( argumentsItemUnpacker ); il.EmitAnyCall( serializers[ i ].FieldType.GetMethod( "UnpackFrom", BindingFlags.Public | BindingFlags.Instance ) ); il.EmitAnyStloc( unpackedArguments[ i ] ); EmitExceptionHandling( il, returnType, endOfMethod, ( il0, exception ) => { il0.EmitAnyLdloc( exception ); il0.EmitLdstr( parameters[ i ].Name ); il0.EmitAnyLdarg( 0 ); il0.EmitGetProperty( asyncInvokerIsDebugModeProperty ); il0.EmitCall( InvocationHelper.HandleArgumentDeserializationExceptionMethod ); il0.EmitNewobj( _asyncInvocationResultErrorConstructor ); il0.EmitAnyStloc( result ); } ); } il.BeginFinallyBlock(); il.EmitAnyLdloc( argumentsItemUnpacker ); il.EmitAnyCall( _idisposableDisposeMethod ); il.EndExceptionBlock(); /* * TService service = this._serviceDescription.Initializer() */ var service = il.DeclareLocal( targetOperation.DeclaringType, "service" ); il.EmitAnyLdarg( 0 ); il.EmitGetProperty( typeof( AsyncServiceInvoker<> ).MakeGenericType( methodReturnType ).GetProperty( "ServiceDescription" ) ); il.EmitGetProperty( ServiceDescription.InitializerProperty ); il.EmitAnyCall( _func_1_Invoke ); il.EmitCastclass( service.LocalType ); il.EmitAnyStloc( service ); /* * #if IS_TASK * return new AsyncInvocationResult( service.Target( arg1, ..., argN ) ); * #else * return new AsyncInvocationResult( this.PrivateInvokeCore( state as Tuple<...> ), new Tuple<...>(...) ) ); * #endif */ if ( !isWrapperNeeded ) { il.EmitAnyLdloc( service ); foreach ( var arg in unpackedArguments ) { il.EmitAnyLdloc( arg ); } il.EmitAnyCall( targetOperation ); } else { EmitWrapperInvocation( emitter, il, service, targetOperation, unpackedArguments ); } il.EmitNewobj( _asyncInvocationResultTaskConstructor ); il.EmitAnyStloc( result ); il.MarkLabel( endOfMethod ); il.EmitAnyLdloc( result ); il.EmitRet(); } finally { il.FlushTrace(); } }
private static IAstRefOrValue CreateCallDelegate(Delegate del, ParameterInfo[] parameters) { return AstBuildHelper.CallMethod( del.GetType().GetMethod("Invoke"), new AstCastclassRef( AstBuildHelper.ReadFieldRV( new AstReadThis() { thisType = typeof(DelegateInvokerBase) }, typeof(DelegateInvokerBase).GetField("_del", BindingFlags.NonPublic | BindingFlags.Instance) ), del.GetType() ), parameters.Select((p, idx) => (IAstStackItem)AstBuildHelper.ReadArgumentRV(idx + 1, typeof(object))).ToList() ); }
private void SetSignature(Type returnType, ParameterInfo returnParameter, Type[] parameters, ParameterInfo[] baseMethodParameters) { builder.SetSignature( returnType, #if SILVERLIGHT null, null, #else returnParameter.GetRequiredCustomModifiers(), returnParameter.GetOptionalCustomModifiers(), #endif parameters, #if SILVERLIGHT null, null #else baseMethodParameters.Select(x => x.GetRequiredCustomModifiers()).ToArray(), baseMethodParameters.Select(x => x.GetOptionalCustomModifiers()).ToArray() #endif ); }
private static dynamic[] ExtractParameExtractParamtersFromPath(dynamic x, ParameterInfo[] parameters) { var nancyParameters = (DynamicDictionary) x; var reqParams = parameters.Select(pi => { var parameter = nancyParameters[pi.Name]; return Convert.ChangeType(parameter, pi.ParameterType); }).ToArray(); return reqParams; }