|
Note: I know the code is incorrect, wrong type of parameters, etc. but you get the main Idea. I hope.
|
|
|
|
|
This is how it is done:
using System;
namespace ConsoleApplication1
{
public class Program
{
public delegate int OuterDelegate(object[] o);
public delegate int InnerDelegate(object[] o);
public int MyMethod(object[] o)
{
int t = 0;
foreach (object io in o)
{
t += (int)io;
}
return t;
}
static void Main(string[] args)
{
Program p = new Program();
InnerDelegate oInnerDelegate = new InnerDelegate(p.MyMethod);
OuterDelegate oOuterDelegate = new OuterDelegate(oInnerDelegate);
int i = oOuterDelegate(new object[] { 1, 2, 3, 4 });
Console.WriteLine(i.ToString());
Console.WriteLine("done");
Console.Read();
}
}
}
Now, the question I still have is how could I change the OuterDelegate to execute some code on what was returned from the InnerDelegate?
Thanks,
Steve
modified on Thursday, February 26, 2009 2:34 PM
|
|
|
|
|
Hi,
Steve Holdorf wrote: Now, the question I still have is how could I change the OuterDelegate to execute some code on what was returned from the InnerDelegate?
You could restructure slightly and write a method that invokes two delegates sequentially. I can't see any way out of passing all the arguments required for the first delegate as arguments to the invoker.
Also the invoker would need code to format or translate the first delegate's output into something the second can accept.
delegate int D1(params int[] list);
delegate void D2(int p);
class DeliDelegate {
internal void Run(){
InvokeBoth(ShowInt, Sum, 1, 2, 3, 4, 5);
InvokeBothAndSome(ShowInt, Sum, 1, 2, 3, 4, 5);
}
void InvokeBoth(D2 outer, D1 inner, params int[] p) {
outer(inner(p));
}
void InvokeBothAndSome(D2 outer, D1 inner, params int[] p) {
int res = inner(p);
res = res * 6;
outer(res);
}
int Sum(params int[] i) {
int result = 0;
foreach (int j in i) {
result += j;
}
return result;
}
void ShowInt(int i) {
Console.WriteLine("Value is {0}", i);
}
}
|
|
|
|
|
Thanks Man! You made my day a lot better.
Steve
|
|
|
|
|
 Finished code:
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
TestManager tManager = new TestManager();
Console.WriteLine("ProcessRequest1");
tManager.Run1();
Console.WriteLine("ProcessRequest2, returned value is: " + tManager.Run2());
Console.ReadLine();
}
}
}
namespace ConsoleApplication1
{
delegate object OuterDelegate (int p);
delegate object InnerDelegate (params string[] list);
class TestManager
{
public int ProcessRequest1(OuterDelegate DoSomethingWithResults, InnerDelegate GetData, params string[] sParams)
{
int iRet = Convert.ToInt32(GetData(sParams));
iRet += 1;
return Convert.ToInt32(DoSomethingWithResults(iRet));
}
public string DoSomethingWithResults(int i)
{
i += 4;
return i.ToString();
}
public string DoNothingWithResults(int i)
{
return i.ToString();
}
public object GetData(params string[] list)
{
int iReturn;
iReturn = (Convert.ToInt32(list.GetValue(0))) + (Convert.ToInt32(list.GetValue(1)));
return iReturn;
}
public int ProcessRequest2(OuterDelegate DoNothingWithResults, InnerDelegate GetData, params string[] sParams)
{
int iRet = Convert.ToInt32(GetData(sParams));
return iRet;
}
internal void Run1()
{
string [] sArray = { "1", "2" };
Console.WriteLine("Not returning anything, results: " + ProcessRequest1(DoSomethingWithResults, GetData, sArray));
}
internal string Run2()
{
string[] sArray = { "4", "5" };
return Convert.ToString(ProcessRequest2(DoNothingWithResults, GetData, sArray));
}
}
}
|
|
|
|
|
Delegates are not used to pass parameters. You are trying to pass parameters to the delegate, ie the result of the method, and the delegate at the same time which would not be correct.
I don't think you are dumb but I think your approach is flawed.
|
|
|
|
|
|
Hi,
the params keyword tells the compiler it should collect the remaining arguments and turn them into an object array; yes, you can use params with a delegate; here is an example:
delegate void TestDelegate(params object[] list);
event TestDelegate aha;
public override void Test(int arg) {
aha+=new TestDelegate(showArgCount);
aha.Invoke(1);
aha.Invoke(1, 2, 3, 4);
}
public void showArgCount(object[] args) {
log("showArgCount: "+args.Length);
}
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Sunday, June 12, 2011 8:41 AM
|
|
|
|
|
Thank you for your help and I will try to have it more together on my next question. Please understand that my boss is asking me to do something very difficult and pushing me to get it done. I am under a lot of pressure and I did spend a lot of time doing research without luck. It has been a tough morning. The bottom line is that I am sorry for the question.
Steve
|
|
|
|
|
You're welcome.
And I saw nothing wrong with your question.(if I did, I would have told you!)
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
hi friends am using usercontrol as drawing area to draw graphics...so now i want to apply zoom factor to usercontrol(not to image)...plzzzzzz help me..
txs in advance...
|
|
|
|
|
usercontrol zoom? Basically this will increase/decrease the size of the control?
why do you want to do that? what controls is your usercontrol containing?
you cannot apply zoom transformations on controls, at least in standard windows applications.
You may use a workaround, to apply a zoom factor to the size/location of each children controls.
Calin
modified on Thursday, February 26, 2009 11:31 AM
|
|
|
|
|
iam drawing shapes using graphics..so i want to apply zoomfactor to dt usercontrol...
|
|
|
|
|
Hi
1. How can I show and edit, Crystal report in wideness
(in C# code)
2. Is it posible to put water stamp Logo that will be in page size ?
thank's
|
|
|
|
|
E_Gold wrote: 1. How can I show and edit, Crystal report in wideness
in wideness? Really, that's the best you could do?
Maybe you should look into this[^]
|
|
|
|
|
I've never used Crystal Reports, but the terms you were looking for are:
1. Landscape
2. Watermark
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
i'll ask again
I am looking for a way to include a watermark in a report.
Does anyone have any ideas?
|
|
|
|
|
E_Gold wrote: Does anyone have any ideas?
Actually, I do have an idea[^]
I know, I'm absolutely brilliant! For my next feat I am thinking of performing brain surgery while disarming a nuclear weapon both during a skydiving free fall.
|
|
|
|
|
I need to dynamically add a flash object to a C# desktop application. Could someone give me some overview on how to do this. I have been able to add it statically but when I go to try to create it dynamically I come up with unhandled win32 exceptions. Also I need the background to be transparent and having troubles with this too.
Thanks for any help
|
|
|
|
|
Zap-Man wrote: Also I need the background to be transparent and having troubles with this too.
Your previous posting of this question already received an answer to that question.
Zap-Man wrote: I come up with unhandled win32 exceptions.
Perhaps posting the exception message along with the relevant code that creates the exception might help people have some idea what the problem is. AFAIK, the members of this site are just normal humans, without any clairvoyant powers.
|
|
|
|
|
yep your right but the response did not answer my question. and if you were to read what I posted you could see that I did post with relevant code. I'm unsure of what creates the exception. its a generic error and leads to nothing to help be debug the problem.
I was hoping that maybe someone else has done somthing like this or knows of any links that my help!
|
|
|
|
|
Zap-Man wrote: and if you were to read what I posted you could see that I did post with relevant code
Maybe in your other post (I haven't checked) but not in this one. I don't know what the hell you did or how you went about doing it. I'd listen to the other reply and heed his/her advice.
|
|
|
|
|
|
Zap-Man wrote: but the response did not answer my question.
Really?
Christian Graus wrote: A flash control is not going to draw itself transparently, ever.
That's not an answer? Whatever. Good luck.
|
|
|
|
|
how to create user and set sql authentication for an existing data base programatically using c#
|
|
|
|