private static void PreloadDefinitionIntoCache(SPFeatureDefinition featureDefinition, string idAttributeName)
        {
            var coll = featureDefinition.GetElementDefinitions(CultureInfo.InvariantCulture);

            foreach (SPElementDefinition element in coll)
            {
                string elementId = (element.XmlDefinition as XmlElement).GetAttribute(idAttributeName);

                string key = CreateKey(element.ElementType, elementId);
                if (_cache.Exists(key))
                    continue;

                var elementInfo = new CachedElementDefinition();
                elementInfo.ElementXml = element.XmlDefinition.Clone();
                elementInfo.FeatureId = featureDefinition.Id;

                if (element.ElementType == "ListTemplate")
                {
                    key += "_" + element.FeatureDefinition.Id.ToString("N").ToUpper();
                }

                _cache.Insert(key, elementInfo, false);
            }
        }
        private static CachedElementDefinition? GetElementInfoFromElementDefinition(SPFeatureDefinition featureDefinition, string elementType, string idAttributeName, object id)
        {
            var elementCollection = featureDefinition.GetElementDefinitions(CultureInfo.InvariantCulture);
            CachedElementDefinition? ret = null;

            foreach (SPElementDefinition e in elementCollection)
            {
                if (e.ElementType == "ContentType" ||
                    e.ElementType == "Field" ||
                    e.ElementType == "ListInstance" ||
                    e.ElementType == "ListTemplate")
                {
                    string elementId;
                    if (e.ElementType == "ContentType" || e.ElementType == "Field")
                    {
                        elementId = SPGENCommon.GetElementDefinitionAttribute(e.XmlDefinition.Attributes, "ID");
                    }
                    else if (e.ElementType == "ListInstance")
                    {
                        elementId = SPGENCommon.GetElementDefinitionAttribute(e.XmlDefinition.Attributes, "Url");
                    }
                    else
                    {
                        elementId = SPGENCommon.GetElementDefinitionAttribute(e.XmlDefinition.Attributes, "Type");
                    }

                    string key = CreateKey(e.ElementType, elementId);

                    if (_cache.Exists(key))
                        continue;

                    var elementInfo = new CachedElementDefinition();
                    elementInfo.ElementXml = e.XmlDefinition.Clone();
                    elementInfo.FeatureId = featureDefinition.Id;

                    bool equals = false;

                    if (e.ElementType == elementType)
                    {
                        if (id is Guid)
                        {
                            if ((Guid)id == new Guid(elementId))
                                equals = true;
                        }
                        else if (id is SPContentTypeId)
                        {
                            if ((SPContentTypeId)id == new SPContentTypeId(elementId))
                                equals = true;
                        }
                        else
                        {
                            if ((string)id == elementId)
                                equals = true;
                        }
                    }

                    if (!equals)
                    {
                        if (e.ElementType == "ListTemplate")
                        {
                            key += "_" + e.FeatureDefinition.Id.ToString("N").ToUpper();
                        }

                        _cache.Insert(key, elementInfo, true);
                    }
                    else
                    {
                        ret = elementInfo;
                    }
                }
            }

            return ret;
        }