C# Delegates & guid.newguid()
<p>I just started using C# this afternoon, so be a little gentle.</p>

<p>Currently I am working on a type of "template engine" where one of the callbacks needs to generate a globally unique ID. I am using delegates to manage the callbacks.</p>

<p>Currently the code looks like this (though I have also tried an anonymous function &amp; returning NewGuid directly w/o a variable):</p>

<pre><code>static string UID(List&lt;string&gt; p)
    {
        string s = Guid.NewGuid().ToString();
        return s;
    }
</code></pre>

<p>Which, when called directly, works fine. However if I try to call it via the delegate (added to a StringDictionary via <code>addCallback("generate UID", new CallbackWrapper(UID))</code>), the program will generate the same GUID regardless of how many times I duplicate it; even though calling the method directly both before &amp; after the event occurs results in a unique ID as expected. I'v</p>

<p>No doubt it's just something simple I've missed, inevitably stemming from me being relatively inexperienced at C#.</p>

<p>Any help would be appreciated.</p>

<p>Thanks.</p>

<p>Well, I've now tried Dictionary with the same result.</p>

<p>CallbackWrapper is just the delegate, it's defined like this:</p>

<pre><code>delegate string CallbackWrapper(List&lt;string&gt; parameters);
</code></pre>

<p>The remainder of the work is done in another class, which looks like this:</p>

<pre><code>class TemplateParser
{

    private Dictionary&lt;string, CallbackWrapper&gt; callbackMap;

    public TemplateParser(string directivePrefix, string directiveSuffix)
    {
        ...
        callbackMap = new Dictionary&lt;string,CallbackWrapper&gt;();
    }
    public TemplateParser() : this("&lt;!-- {", "} --&gt;") {}

    {
        callbackMap.Add(name, callback);
    }

    public string parse(string filename)
    {
            ...
            string replacement =
                callbackMap[directiveName](new List&lt;string&gt;(parameters.Split(new string[] { ";", " " }, StringSplitOptions.RemoveEmptyEntries)); 
            ...     
    }
}
</code></pre>

<p>I've stripped out the majority of the string handling code to save some space.</p>
