Link to home
Start Free TrialLog in
Avatar of Camillia
CamilliaFlag for United States of America

asked on

Meaning of this code

I downloaded a code from here to display/update/insert into RESX files.

http://blog.lavablast.com/post/2008/02/RESX-file-Web-Editor.aspx

what's the meaning of this code..I know it grabs all the resx files in the directory but what is that delegate for?

Is there an easier way to write that section...just want to grab name of the RESX files from the folder...
/// Get all the Resx in the web site and list them in a list
		/// </summary>
		protected void GetResX()
		{
			SortedList<string, string> list = ResXUnified.GetResXInDirectory(Path,
				new GenericPredicate<string, string>(delegate(string[] path)
			{
				return path[0].Replace(path[1], "").Replace("App_LocalResources", "").Replace("App_GlobalResources", "");
			}));
 
			foreach (KeyValuePair<string, string> val in list)
				lstResX.Items.Add(new ListItem(val.Key, val.Value));
		}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Dmitry G
Dmitry G
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Camillia

ASKER

thanks, let me read.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks, let me look at your code.
I dont understand it. I found more info as well but i dont get it.
http://blogs.msdn.com/jeremykuhne/archive/2005/07/23/generic-collections-ii.aspx

-- I think i need maybe a step by step in that code..what is calling what...can one of you explain?

For example, the code above...the rest of the code is like this:

public static SortedList<string, string> GetResXInDirectory(string basePath)
            {
                  return GetResXInDirectory(basePath, null);
            }

and

public static SortedList<string, string> GetResXInDirectory(string basePath, GenericPredicate<string, string> display)
            {
                                              .....
   }

and

public delegate R GenericPredicate<T, R>(params T[] obj);
ok, this explains it. Still dont understand that one line:
public delegate R GenericPredicate<T, R>(params T[] obj);

but this link is a good one

http://bytes.com/forum/thread474304.html
The line
public delegate R GenericPredicate<T, R>(params T[] obj);

OK, this is a delegate for a function that returns an object of type R and takes as an argument parameter array of type T. This notation is using generics. It's up to you what types do you pass as a parameter or return fromthe function.

Usage of "params" keyword you may see:
http://www.csharphelp.com/archives/archive18.html
http://msdn.microsoft.com/en-us/library/w5zay9db%28VS.71%29.aspx
thanks