WvDbi split into multiple classes, and now parses URL-style database names.
[versaplex.git] / wvdotnet / wvmoniker.cs
blob107c03dc11b3df5cb2ad4d1811ed6ab8c6e48d6b
1 using System;
2 using System.Collections.Generic;
3 using Wv;
4 using Wv.Extensions;
6 namespace Wv
8 public class WvMoniker<T>
10 static List<WvMoniker<T>> registry = new List<WvMoniker<T>>();
11 string prefix;
12 Func<string,object,T> func;
14 public static WvMoniker<T>
15 register(string prefix, Func<string,object,T> func)
17 return new WvMoniker<T>(prefix, func);
20 public WvMoniker(string prefix, Func<string,object,T> func)
22 this.prefix = prefix;
23 this.func = func;
24 registry.Add(this);
27 // probably nobody will ever call this
28 public void unregister()
30 registry.Remove(this);
33 public static WvMoniker<T> find(string prefix)
35 foreach (WvMoniker<T> m in registry)
36 if (m.prefix == prefix)
37 return m;
38 return null;
41 public static T create(string moniker, object o)
43 int pos = moniker.IndexOf(':');
44 string prefix, suffix;
45 if (pos >= 0)
47 prefix = moniker.Substring(0, pos);
48 suffix = moniker.Substring(pos+1);
50 else
52 prefix = moniker;
53 suffix = "";
56 WvMoniker<T> m = find(prefix);
57 if (m == null)
58 return default(T);
59 else
60 return m.func(suffix, o);
63 public static T create(string moniker)
65 return create(moniker, null);