internal static T CreateChain <T> (ChainedExtension next) where T : ChainedExtension, new() { var first = new T(); first.nextInChain = ChainedExtension.FindNextImplementation <T> (next); return(first); }
public T GetExtension <T> () where T : ChainedExtension, new() { ChainedExtension e; if (!chains.TryGetValue(typeof(T), out e)) { e = new T(); e.InitChain(this, ChainedExtension.FindNextImplementation <T> (extensions[0])); chains [typeof(T)] = e; } return((T)e); }
public void Update(ExtensionChain chain, Type type, int firstChainChangeIndex) { // We only want to update an extension if we insert somewhere before the extension we found. if (extensionIndex < firstChainChangeIndex) { return; } // Maybe it would be useful to skip extensions until min(indices), as they've already been scanned // in a previous check var impl = ChainedExtension.FindNextImplementation(type, chain.extensions[0], out extensionIndex); Extension.InitChain(chain, impl); }
void Rechain() { // Re-chain every extension for (int n = extensions.Length - 2; n >= 0; n--) { extensions [n].InitChain(this, extensions [n + 1]); } // The first extension object in type-specific chains is a placeholder extension used only to hold // a reference to the real first extension. foreach (var fex in chains) { fex.Value.InitChain(this, ChainedExtension.FindNextImplementation(fex.Key, extensions[0])); } }