Search Results

Search found 7 results on 1 pages for 'paramarray'.

Page 1/1 | 1 

  • Delegates and ParamArray - Workaround Suggestions?

    - by M.A. Hanin
    Some predefined methods contain a ParamArray in their signature. Delegates, however, cannot contain a ParamArray in their signature. Main question: Assume you wish to create a delegation mechanism for a specific method which requires a ParamArray. How would you work around this constraint? "Bonus" question: Assume you wish to create a generalized delegation mechanism for all methods which require ParamArray, how would you do that?

    Read the article

  • Variable number of arguments in ParamArray ArgList()

    - by Excel VBA guy
    If I want to pass a number of values for the ParamArray arglist via an array, how do I do it? From what I've read so far, on VBA, it appears that I need to explicitly list the values that I want to pass. But what if there are potentially different numbers of values to pass, so I do not know in advance how many I'll want to pass to the function? Is there not some way of using an array (a one-dimensional array) with a variable dimension?

    Read the article

  • How to use reflection to call a method and pass parameters whose types are unknown at compile time?

    - by MandoMando
    I'd like to call methods of a class dynamically with parameter values that are "parsed" from a string input. For example: I'd like to call the following program with these commands: c:myprog.exe MethodA System.Int32 777 c:myprog.exe MethodA System.float 23.17 c:myprog.exe MethodB System.Int32& 777 c:myprog.exe MethodC System.Int32 777 System.String ThisCanBeDone static void Main(string[] args) { ClassA aa = new ClassA(); System.Type[] types = new Type[args.Length / 2]; object[] ParamArray = new object[types.Length]; for (int i=0; i < types.Length; i++) { types[i] = System.Type.GetType(args[i*2 + 1]); // LINE_X: this will obviously cause runtime error invalid type/casting ParamArray[i] = args[i*2 + 2]; MethodInfo callInfo = aa.GetType().GetMethod(args[0],types); callInfo.Invoke(aa, ParamArray); } // In a non-changeable classlib: public class ClassA { public void MethodA(int i) { Console.Write(i.ToString()); } public void MethodA(float f) { Console.Write(f.ToString()); } public void MethodB(ref int i) { Console.Write(i.ToString()); i++; } public void MethodC(int i, string s) { Console.Write(s + i.ToString()); } public void MethodA(object o) { Console.Write("Argg! Type Trapped!"); } } "LINE_X" in the above code is the sticky part. For one, I have no idea how to assign value to a int or a ref int parameter even after I create it using Activator.CreatInstance or something else. The typeConverter does come to mind, but then that requires an explicit compile type casting as well. Am I looking at CLR with JavaScript glasses or there is way to do this?

    Read the article

  • ie8 breaks with asp.net ajax

    - by Amadeo Torese
    Hello, When using asp.net ajax (scriptmanager, timer, updatepanel) with ie8, after certain time (~3h) IE breaks with null object, constructor, or paramArray (depending on the asp.net code). Even with the simplest timer (no ajax, no updatepanel) ie8 still breaks. On every other browser it works fine, and if I code the ajax myself it works. Since google and msdn forums turned up nothing I'm wondering if anybody here has had similar problems with ie8 browser.

    Read the article

  • Parallel WCF calls to multiple servers

    - by gregmac
    I have a WCF service (the same one) running on multiple servers, and I'd like to call all instances in parallel from a single client. I'm using ChannelFactory and the interface (contract) to call the service. Each service has a local <endpoint> client defined in the .config file. What I'm trying to do is build some kind of generic framework to avoid code duplication. For example a synchronous call in a single thread looks something like this: Dim remoteName As String = "endpointName1" Dim svcProxy As ChannelFactory(Of IMyService) = New ChannelFactory(Of IMyService)(remoteName) Try svcProxy.Open() Dim svc As IMyService = svcProxy.CreateChannel() nodeResult = svc.TestRemote("foo") Finally svcProxy.Close() End Try The part I'm having difficulty with is how to specify and actually invoke the actual remote method (eg "TestRemote") without having to duplicate the above code, and all the thread-related stuff that invokes that, for each method. In the end, I'd like to be able to write code along the lines of (consider this psuedo code): Dim results as Dictionary(Of Node, ExpectedReturnType) results = ParallelInvoke(IMyService.SomeMethod, parameter1, parameter2) where ParallelInvoke() will take the method as an argument, as well as the parameters (paramArray or object() .. whatever) and then go run the request on each remote node, block until they all return an answer or timeout, and then return the results into a Dictionary with the key as the node, and the value as whatever value it returned. I can then (depending on the method) pick out the single value I need, or aggregate all the values from each server together, etc. I'm pretty sure I can do this using reflection and InvokeMember(), but that requires passing the method as a string (which can lead to errors like calling a non-existing method that can't be caught at compile time), so I'd like to see if there is a cleaner way to do this. Thanks

    Read the article

  • Why do the overloads of String.Format exist?

    - by GiddyUpHorsey
    I was using Reflector to look at the implementation of String.Format and had always been under the impression that the overloads of String.Format that took 1, 2 & 3 arguments were optimized versions of the method that takes an object array. However, what I found was that internally they create an object array and then call a method that takes an object array. 1 arg public static string Format(string format, object arg0) { if (format == null) { throw new ArgumentNullException("format"); } return Format(null, format, new object[] { arg0 }); } 2 args public static string Format(string format, object arg0, object arg1) { if (format == null) { throw new ArgumentNullException("format"); } return Format(null, format, new object[] { arg0, arg1 }); } 3 args public static string Format(string format, object arg0, object arg1, object arg2) { if (format == null) { throw new ArgumentNullException("format"); } return Format(null, format, new object[] { arg0, arg1, arg2 }); } Object array public static string Format(string format, params object[] args) { if ((format == null) || (args == null)) { throw new ArgumentNullException((format == null) ? "format" : "args"); } return Format(null, format, args); } Internally they all end up using the same code and so using the 1, 2 & 3 argument versions are no faster than the object array version. So my question is - why do they exist? When you use the object array version with a comma separated list of values, the compiler automatically converts the arguments into an object array because of the params/ParamArray keyword which is essentially what the 1, 2 & 3 versions do, so they seem redundant. Why did the BCL designers add these overloads?

    Read the article

1