private CodeDocType ConvertToModel(Type type, CodeDocMemberDetailLevel detailLevel, ICodeDocMemberDataProvider extraMemberDataProvider = null)
            {
                Contract.Requires(type != null);
                Contract.Ensures(Contract.Result<CodeDocType>() != null);
                Contract.Ensures(!String.IsNullOrEmpty(Contract.Result<CodeDocType>().ShortName));
                Contract.Ensures(!String.IsNullOrEmpty(Contract.Result<CodeDocType>().FullName));
                Contract.Ensures(!String.IsNullOrEmpty(Contract.Result<CodeDocType>().Title));
                Contract.Ensures(Contract.Result<CodeDocType>().Title == Contract.Result<CodeDocType>().ShortName);
                Contract.Ensures(!String.IsNullOrEmpty(Contract.Result<CodeDocType>().SubTitle));

                var includeExceptions = detailLevel != CodeDocMemberDetailLevel.Minimum;
                var appendXmlDoc = detailLevel.HasFlag(CodeDocMemberDetailLevel.Summary) || detailLevel.HasFlag(CodeDocMemberDetailLevel.AdditionalContents);
                var provideXmlDoc = includeExceptions || detailLevel != CodeDocMemberDetailLevel.Minimum;
                var includeMembers = detailLevel.HasFlag(CodeDocMemberDetailLevel.Members);
                var includeInheritance = detailLevel.HasFlag(CodeDocMemberDetailLevel.Inheritance);
                var includeParameters = detailLevel != CodeDocMemberDetailLevel.Minimum;

                var cRef = GetCRefIdentifier(type);
                var model = type.IsDelegateType()
                    ? new CodeDocDelegate(cRef)
                    : new CodeDocType(cRef);
                model.Uri = GetUri(type);
                var delegateModel = model as CodeDocDelegate;

                var memberDataProvider = new CodeDocMemberInfoProvider<Type>(type);

                XmlDocMember xmlDocs = null;
                if (provideXmlDoc) {
                    xmlDocs = XmlDocs.GetMember(cRef.FullCRef);
                    if (xmlDocs != null)
                        memberDataProvider.Add(new CodeDocMemberXmlDataProvider(xmlDocs));
                }

                if (extraMemberDataProvider != null)
                    memberDataProvider.Add(extraMemberDataProvider);

                if (includeInheritance && type.BaseType != null) {
                    if (ImplicitlyInheritDataProvider(type.BaseType) || (xmlDocs != null && xmlDocs.HasInheritDoc)) {
                        var baseModel = GetOrConvert(type.BaseType, detailLevel);
                        memberDataProvider.Add(new CodeDocMemberDataProvider(baseModel));
                    }
                }

                if (appendXmlDoc)
                    ApplyContentXmlDocs(model, memberDataProvider);

                model.ExternalVisibility = memberDataProvider.ExternalVisibility ?? ExternalVisibilityKind.Public;
                model.ShortName = RegularTypeDisplayNameOverlay.GetDisplayName(type);
                model.FullName = FullTypeDisplayNameOverlay.GetDisplayName(type);
                model.Title = model.ShortName;
                model.NamespaceName = type.Namespace;

                if (type.IsEnum)
                    model.SubTitle = "Enumeration";
                else if (type.IsValueType)
                    model.SubTitle = "Structure";
                else if (type.IsInterface)
                    model.SubTitle = "Interface";
                else if (type.IsDelegateType())
                    model.SubTitle = "Delegate";
                else
                    model.SubTitle = "Class";

                model.Namespace = GetOrCreateNamespaceByName(type.Namespace);
                model.Assembly = GetCodeDocAssembly(type.Assembly);
                model.IsEnum = type.IsEnum;
                model.IsFlagsEnum = type.IsEnum && type.HasAttribute(typeof(FlagsAttribute));
                model.IsSealed = type.IsSealed;
                model.IsValueType = type.IsValueType;
                model.IsStatic = memberDataProvider.IsStatic.GetValueOrDefault();
                model.IsObsolete = memberDataProvider.IsObsolete.GetValueOrDefault();

                if (type.DeclaringType != null)
                    model.DeclaringType = GetOrConvert(type.DeclaringType, CodeDocMemberDetailLevel.Minimum);

                if (delegateModel != null)
                    delegateModel.IsPure = memberDataProvider.IsPure.GetValueOrDefault();

                if (includeInheritance && !type.IsInterface) {
                    var currentBase = type.BaseType;
                    if (null != currentBase) {
                        var baseChain = new List<CodeDocType>() {
                            GetOrConvert(currentBase, detailLevel)
                        };
                        currentBase = currentBase.BaseType;
                        while (currentBase != null) {
                            baseChain.Add(GetOrConvert(currentBase, CodeDocMemberDetailLevel.Minimum));
                            currentBase = currentBase.BaseType;
                        }
                        model.BaseChain = baseChain;
                    }

                    var implementedInterfaces = type.GetInterfaces();
                    if (implementedInterfaces.Length > 0) {
                        model.Interfaces = Array.ConvertAll(
                            implementedInterfaces,
                            t => GetOrConvert(t, CodeDocMemberDetailLevel.Minimum));
                    }
                }

                if (includeParameters && type.IsGenericType) {
                    var genericDefinition = type.IsGenericTypeDefinition
                        ? type
                        : type.GetGenericTypeDefinition();
                    if (genericDefinition != null) {
                        var genericArguments = genericDefinition.GetGenericArguments();
                        if (type.IsNested && genericArguments.Length > 0) {
                            Contract.Assume(type.DeclaringType != null);
                            var parentGenericArguments = type.DeclaringType.GetGenericArguments();
                            genericArguments = genericArguments
                                .Where(a => parentGenericArguments.All(p => p.Name != a.Name))
                                .ToArray();
                        }
                        if (genericArguments.Length > 0) {
                            model.GenericParameters = CreateGenericTypeParameters(
                                genericArguments,
                                memberDataProvider);
                        }
                    }
                }

                if (delegateModel != null) {
                    if (includeParameters) {
                        delegateModel.Parameters = Array.ConvertAll(
                            type.GetDelegateTypeParameters(),
                            p => CreateArgument(p, memberDataProvider));

                        var returnParameter = type.GetDelegateReturnParameter();
                        if (returnParameter != null && returnParameter.ParameterType != typeof (void))
                            delegateModel.Return = CreateReturn(returnParameter, memberDataProvider);
                    }

                    if (includeExceptions) {
                        if (memberDataProvider.HasExceptions)
                            delegateModel.Exceptions = CreateExceptionModels(memberDataProvider.GetExceptions()).ToArray();
                        if (memberDataProvider.HasEnsures)
                            delegateModel.Ensures = memberDataProvider.GetEnsures().ToArray();
                        if (memberDataProvider.HasRequires)
                            delegateModel.Requires = memberDataProvider.GetRequires().ToArray();
                    }
                }

                if (includeMembers) {
                    var nestedTypeModels = new List<ICodeDocMember>();
                    var nestedDelegateModels = new List<ICodeDocMember>();
                    foreach (var nestedType in type.GetAllNestedTypes().Where(ReflectionRepository.MemberFilter)) {
                        var nestedTypeModel = GetOrConvert(nestedType, CodeDocMemberDetailLevel.QuickSummary);
                        if (nestedType.IsDelegateType())
                            nestedDelegateModels.Add(nestedTypeModel);
                        else
                            nestedTypeModels.Add(nestedTypeModel);
                    }
                    model.NestedTypes = nestedTypeModels;
                    model.NestedDelegates = nestedDelegateModels;

                    var methodModels = new List<ICodeDocMember>();
                    var operatorModels = new List<ICodeDocMember>();
                    foreach (var methodInfo in type.GetAllMethods().Where(ReflectionRepository.MemberFilter)) {
                        var methodModel = GetOrConvert(methodInfo, CodeDocMemberDetailLevel.QuickSummary);
                        if (methodInfo.IsOperatorOverload())
                            operatorModels.Add(methodModel);
                        else
                            methodModels.Add(methodModel);
                    }
                    model.Methods = methodModels;
                    model.Operators = operatorModels;

                    model.Constructors = type
                        .GetAllConstructors()
                        .Where(ReflectionRepository.MemberFilter)
                        .Select(methodInfo => GetOrConvert(methodInfo, CodeDocMemberDetailLevel.QuickSummary))
                        .ToArray();

                    model.Properties = type
                        .GetAllProperties()
                        .Where(ReflectionRepository.MemberFilter)
                        .Select(propertyInfo => GetOrConvert(propertyInfo, CodeDocMemberDetailLevel.QuickSummary))
                        .ToArray();

                    model.Fields = type
                        .GetAllFields()
                        .Where(ReflectionRepository.MemberFilter)
                        .Select(fieldInfo => GetOrConvert(fieldInfo, CodeDocMemberDetailLevel.QuickSummary))
                        .ToArray();

                    model.Events = type
                        .GetAllEvents()
                        .Where(ReflectionRepository.MemberFilter)
                        .Select(eventInfo => GetOrConvert(eventInfo, CodeDocMemberDetailLevel.QuickSummary))
                        .ToArray();
                }

                return model;
            }
            private CodeDocMethod ConvertToModel(MethodBase methodBase, CodeDocMemberDetailLevel detailLevel, ICodeDocMemberDataProvider extraMemberDataProvider = null)
            {
                Contract.Requires(methodBase != null);
                Contract.Ensures(Contract.Result<CodeDocMethod>() != null);
                Contract.Ensures(!String.IsNullOrEmpty(Contract.Result<CodeDocMethod>().ShortName));
                Contract.Ensures(!String.IsNullOrEmpty(Contract.Result<CodeDocMethod>().FullName));
                Contract.Ensures(!String.IsNullOrEmpty(Contract.Result<CodeDocMethod>().Title));
                Contract.Ensures(Contract.Result<CodeDocMethod>().Title == Contract.Result<CodeDocMethod>().ShortName);
                Contract.Ensures(!String.IsNullOrEmpty(Contract.Result<CodeDocMethod>().SubTitle));

                var includeExceptions = detailLevel != CodeDocMemberDetailLevel.Minimum;
                var appendXmlDoc = detailLevel.HasFlag(CodeDocMemberDetailLevel.Summary) || detailLevel.HasFlag(CodeDocMemberDetailLevel.AdditionalContents);
                var provideXmlDoc = includeExceptions || detailLevel != CodeDocMemberDetailLevel.Minimum;
                var includeInheritance = detailLevel.HasFlag(CodeDocMemberDetailLevel.Inheritance);
                var includeParameters = detailLevel != CodeDocMemberDetailLevel.Minimum;

                var methodInfo = methodBase as MethodInfo;
                var methodCRef = GetCRefIdentifier(methodBase);
                var model = new CodeDocMethod(methodCRef);
                model.Uri = GetUri(methodBase);

                var memberDataProvider = new CodeDocMemberInfoProvider<MethodBase>(methodBase);

                if (provideXmlDoc) {
                    var xmlDocs = XmlDocs.GetMember(methodCRef.FullCRef);
                    if (xmlDocs != null)
                        memberDataProvider.Add(new CodeDocMemberXmlDataProvider(xmlDocs));
                }

                if (extraMemberDataProvider != null)
                    memberDataProvider.Add(extraMemberDataProvider);

                if (includeInheritance && methodInfo != null) {
                    var baseDefinition = methodInfo.FindNextAncestor();
                    if (baseDefinition != null) {
                        var baseDefinitionModel = GetOnly(GetCRefIdentifier(baseDefinition), detailLevel);
                        if (baseDefinitionModel != null)
                            memberDataProvider.Add(new CodeDocMemberDataProvider(baseDefinitionModel));
                    }
                }

                if (appendXmlDoc)
                    ApplyContentXmlDocs(model, memberDataProvider);

                model.ExternalVisibility = memberDataProvider.ExternalVisibility ?? ExternalVisibilityKind.Public;
                model.ShortName = RegularTypeDisplayNameOverlay.GetDisplayName(methodBase);
                model.FullName = FullTypeDisplayNameOverlay.GetDisplayName(methodBase);
                model.Title = model.ShortName;
                Contract.Assume(methodBase.DeclaringType != null);
                model.NamespaceName = methodBase.DeclaringType.Namespace;

                if (includeParameters) {
                    model.Parameters = Array.ConvertAll(
                        methodBase.GetParameters(),
                        p => CreateArgument(p, memberDataProvider));

                    if (methodInfo != null && methodInfo.ReturnParameter != null &&
                        methodInfo.ReturnType != typeof (void))
                        model.Return = CreateReturn(methodInfo.ReturnParameter, memberDataProvider);
                }

                if (methodBase.IsConstructor)
                    model.SubTitle = "Constructor";
                else if (model.Parameters != null && model.Parameters.Count == 1 && model.HasReturn && CSharpOperatorNameSymbolMap.IsConversionOperatorMethodName(methodBase.Name)) {
                    model.SubTitle = "Conversion";

                    string conversionOperationName;
                    if (methodBase.Name.EndsWith("Explicit", StringComparison.OrdinalIgnoreCase))
                        conversionOperationName = "Explicit";
                    else if (methodBase.Name.EndsWith("Implicit", StringComparison.OrdinalIgnoreCase))
                        conversionOperationName = "Implicit";
                    else
                        conversionOperationName = String.Empty;

                    var conversionParameterPart = String.Concat(
                        model.Parameters[0].ParameterType.ShortName,
                        " to ",
                        model.Return.ParameterType.ShortName);

                    model.ShortName = String.IsNullOrEmpty(conversionOperationName)
                        ? conversionParameterPart
                        : String.Concat(conversionOperationName, ' ', conversionParameterPart);
                    model.Title = model.ShortName;
                }
                else if (methodBase.IsOperatorOverload())
                    model.SubTitle = "Operator";
                else
                    model.SubTitle = "Method";

                Contract.Assume(methodBase.DeclaringType != null);
                model.Namespace = GetOrCreateNamespaceByName(methodBase.DeclaringType.Namespace);
                model.Assembly = GetCodeDocAssembly(methodBase.DeclaringType.Assembly);
                model.DeclaringType = GetOrConvert(methodBase.DeclaringType, CodeDocMemberDetailLevel.Minimum);
                model.IsOperatorOverload = methodBase.IsOperatorOverload();
                model.IsExtensionMethod = methodBase.IsExtensionMethod();
                model.IsSealed = methodBase.IsSealed();
                model.IsStatic = memberDataProvider.IsStatic.GetValueOrDefault();
                model.IsObsolete = memberDataProvider.IsObsolete.GetValueOrDefault();
                model.IsPure = memberDataProvider.IsPure.GetValueOrDefault();

                if (methodBase.DeclaringType != null && !methodBase.DeclaringType.IsInterface) {
                    if (methodBase.IsAbstract)
                        model.IsAbstract = true;
                    else if (methodBase.IsVirtual && !methodBase.IsFinal && methodBase.Attributes.HasFlag(MethodAttributes.NewSlot))
                        model.IsVirtual = true;
                }

                if (includeExceptions){
                    if (memberDataProvider.HasExceptions)
                        model.Exceptions = CreateExceptionModels(memberDataProvider.GetExceptions()).ToArray();
                    if (memberDataProvider.HasEnsures)
                        model.Ensures = memberDataProvider.GetEnsures().ToArray();
                    if (memberDataProvider.HasRequires)
                        model.Requires = memberDataProvider.GetRequires().ToArray();
                }

                if (includeParameters && methodBase.IsGenericMethod) {
                    var genericDefinition = methodBase.IsGenericMethodDefinition
                        ? methodBase
                        : methodInfo == null ? null : methodInfo.GetGenericMethodDefinition();
                    if (genericDefinition != null) {
                        var genericArguments = genericDefinition.GetGenericArguments();
                        if (genericArguments.Length > 0) {
                            model.GenericParameters = CreateGenericTypeParameters(
                                genericArguments,
                                memberDataProvider);
                        }
                    }
                }

                return model;
            }
            private CodeDocField ConvertToModel(FieldInfo fieldInfo, CodeDocMemberDetailLevel detailLevel, ICodeDocMemberDataProvider extraMemberDataProvider = null)
            {
                Contract.Requires(fieldInfo != null);
                Contract.Ensures(Contract.Result<CodeDocField>() != null);
                Contract.Ensures(!String.IsNullOrEmpty(Contract.Result<CodeDocField>().ShortName));
                Contract.Ensures(!String.IsNullOrEmpty(Contract.Result<CodeDocField>().FullName));
                Contract.Ensures(!String.IsNullOrEmpty(Contract.Result<CodeDocField>().Title));
                Contract.Ensures(Contract.Result<CodeDocField>().Title == Contract.Result<CodeDocField>().ShortName);
                Contract.Ensures(!String.IsNullOrEmpty(Contract.Result<CodeDocField>().SubTitle));

                var appendXmlDoc = detailLevel.HasFlag(CodeDocMemberDetailLevel.Summary) || detailLevel.HasFlag(CodeDocMemberDetailLevel.AdditionalContents);
                var provideXmlDoc = detailLevel != CodeDocMemberDetailLevel.Minimum;

                var fieldCRef = GetCRefIdentifier(fieldInfo);
                var model = new CodeDocField(fieldCRef);
                model.Uri = GetUri(fieldInfo);

                var memberDataProvider = new CodeDocMemberInfoProvider<FieldInfo>(fieldInfo);

                if (provideXmlDoc) {
                    var xmlDocs = XmlDocs.GetMember(fieldCRef.FullCRef);
                    if (xmlDocs != null)
                        memberDataProvider.Add(new CodeDocMemberXmlDataProvider(xmlDocs));
                }

                if (extraMemberDataProvider != null)
                    memberDataProvider.Add(extraMemberDataProvider);

                if (appendXmlDoc) {
                    model.ValueDescriptionContents = memberDataProvider.GeValueDescriptionContents().ToArray();
                    ApplyContentXmlDocs(model, memberDataProvider);
                }

                model.ExternalVisibility = memberDataProvider.ExternalVisibility ?? ExternalVisibilityKind.Public;
                model.ShortName = RegularTypeDisplayNameOverlay.GetDisplayName(fieldInfo);
                model.FullName = FullTypeDisplayNameOverlay.GetDisplayName(fieldInfo);
                model.Title = model.ShortName;
                Contract.Assume(fieldInfo.DeclaringType != null);
                model.NamespaceName = fieldInfo.DeclaringType.Namespace;
                model.SubTitle = fieldInfo.IsLiteral ? "Constant" : "Field";

                model.ValueType = GetOrConvert(fieldInfo.FieldType, CodeDocMemberDetailLevel.Minimum);

                model.IsLiteral = fieldInfo.IsLiteral;
                model.IsInitOnly = fieldInfo.IsInitOnly;
                model.IsStatic = memberDataProvider.IsStatic.GetValueOrDefault();
                model.IsObsolete = memberDataProvider.IsObsolete.GetValueOrDefault();

                Contract.Assume(fieldInfo.DeclaringType != null);
                model.Namespace = GetOrCreateNamespaceByName(fieldInfo.DeclaringType.Namespace);
                model.Assembly = GetCodeDocAssembly(fieldInfo.DeclaringType.Assembly);
                model.DeclaringType = GetOrConvert(fieldInfo.DeclaringType, CodeDocMemberDetailLevel.Minimum);
                return model;
            }
            private CodeDocProperty ConvertToModel(PropertyInfo propertyInfo, CodeDocMemberDetailLevel detailLevel, ICodeDocMemberDataProvider extraMemberDataProvider = null)
            {
                Contract.Requires(propertyInfo != null);
                Contract.Ensures(Contract.Result<CodeDocProperty>() != null);
                Contract.Ensures(!String.IsNullOrEmpty(Contract.Result<CodeDocProperty>().ShortName));
                Contract.Ensures(!String.IsNullOrEmpty(Contract.Result<CodeDocProperty>().FullName));
                Contract.Ensures(!String.IsNullOrEmpty(Contract.Result<CodeDocProperty>().Title));
                Contract.Ensures(Contract.Result<CodeDocProperty>().Title == Contract.Result<CodeDocProperty>().ShortName);
                Contract.Ensures(!String.IsNullOrEmpty(Contract.Result<CodeDocProperty>().SubTitle));

                var includeExceptions = detailLevel != CodeDocMemberDetailLevel.Minimum;
                var appendXmlDoc = detailLevel.HasFlag(CodeDocMemberDetailLevel.Summary) || detailLevel.HasFlag(CodeDocMemberDetailLevel.AdditionalContents);
                var provideXmlDoc = includeExceptions || detailLevel != CodeDocMemberDetailLevel.Minimum;
                var includeInheritance = detailLevel.HasFlag(CodeDocMemberDetailLevel.Inheritance);
                var includeParameters = detailLevel != CodeDocMemberDetailLevel.Minimum;

                var propertyCRef = GetCRefIdentifier(propertyInfo);
                var model = new CodeDocProperty(propertyCRef);
                model.Uri = GetUri(propertyInfo);

                var memberDataProvider = new CodeDocMemberInfoProvider<PropertyInfo>(propertyInfo);

                XmlDocMember xmlDocs = null;
                if (provideXmlDoc) {
                    xmlDocs = XmlDocs.GetMember(propertyCRef.FullCRef);
                    if (xmlDocs != null)
                        memberDataProvider.Add(new CodeDocMemberXmlDataProvider(xmlDocs));
                }

                if (extraMemberDataProvider != null)
                    memberDataProvider.Add(extraMemberDataProvider);

                if (includeInheritance) {
                    var propertyBase = propertyInfo.FindNextAncestor();
                    if (propertyBase != null) {
                        var propertyBaseModel = GetOnly(GetCRefIdentifier(propertyBase), detailLevel);
                        if (propertyBaseModel != null)
                            memberDataProvider.Add(new CodeDocMemberDataProvider(propertyBaseModel));
                    }
                }

                if (appendXmlDoc) {
                    ApplyContentXmlDocs(model, memberDataProvider);
                    model.ValueDescriptionContents = memberDataProvider.GeValueDescriptionContents().ToArray();
                }

                model.ExternalVisibility = memberDataProvider.ExternalVisibility ?? ExternalVisibilityKind.Public;
                model.ShortName = RegularTypeDisplayNameOverlay.GetDisplayName(propertyInfo);
                model.FullName = FullTypeDisplayNameOverlay.GetDisplayName(propertyInfo);
                model.Title = model.ShortName;
                Contract.Assume(propertyInfo.DeclaringType != null);
                model.NamespaceName = propertyInfo.DeclaringType.Namespace;
                model.SubTitle = propertyInfo.IsItemIndexerProperty() ? "Indexer" : "Property";

                model.IsStatic = memberDataProvider.IsStatic.GetValueOrDefault();
                model.IsObsolete = memberDataProvider.IsObsolete.GetValueOrDefault();

                model.ValueType = GetOrConvert(propertyInfo.PropertyType, CodeDocMemberDetailLevel.Minimum);
                Contract.Assume(propertyInfo.DeclaringType != null);
                model.Namespace = GetOrCreateNamespaceByName(propertyInfo.DeclaringType.Namespace);
                model.Assembly = GetCodeDocAssembly(propertyInfo.DeclaringType.Assembly);
                model.DeclaringType = GetOrConvert(propertyInfo.DeclaringType, CodeDocMemberDetailLevel.Minimum);

                if (includeParameters) {
                    var parameters = propertyInfo.GetIndexParameters();
                    if (parameters.Length > 0)
                        model.Parameters = Array.ConvertAll(parameters, p => CreateArgument(p, memberDataProvider));
                }

                var getterMethodInfo = propertyInfo.GetGetMethod(true);
                if (getterMethodInfo != null && ReflectionRepository.MemberFilter(getterMethodInfo, true)) {
                    var accessorExtraProvider = (xmlDocs != null && xmlDocs.HasGetterElement)
                        ? new CodeDocMemberXmlDataProvider(xmlDocs.GetterElement)
                        : null;
                    model.Getter = ConvertToModel(getterMethodInfo, detailLevel, accessorExtraProvider);
                }

                var setterMethodInfo = propertyInfo.GetSetMethod(true);
                if (setterMethodInfo != null && ReflectionRepository.MemberFilter(setterMethodInfo, true)) {
                    var accessorExtraProvider = (xmlDocs != null && xmlDocs.HasSetterElement)
                        ? new CodeDocMemberXmlDataProvider(xmlDocs.SetterElement)
                        : null;
                    model.Setter = ConvertToModel(setterMethodInfo, detailLevel, accessorExtraProvider);
                }

                return model;
            }
            private CodeDocEvent ConvertToModel(EventInfo eventInfo, CodeDocMemberDetailLevel detailLevel, ICodeDocMemberDataProvider extraMemberDataProvider = null)
            {
                Contract.Requires(eventInfo != null);
                Contract.Ensures(Contract.Result<CodeDocEvent>() != null);
                Contract.Ensures(!String.IsNullOrEmpty(Contract.Result<CodeDocEvent>().ShortName));
                Contract.Ensures(!String.IsNullOrEmpty(Contract.Result<CodeDocEvent>().FullName));
                Contract.Ensures(!String.IsNullOrEmpty(Contract.Result<CodeDocEvent>().Title));
                Contract.Ensures(Contract.Result<CodeDocEvent>().Title == Contract.Result<CodeDocEvent>().ShortName);
                Contract.Ensures(!String.IsNullOrEmpty(Contract.Result<CodeDocEvent>().SubTitle));

                var includeInheritance = detailLevel.HasFlag(CodeDocMemberDetailLevel.Inheritance);
                var appendXmlDoc = detailLevel.HasFlag(CodeDocMemberDetailLevel.Summary) || detailLevel.HasFlag(CodeDocMemberDetailLevel.AdditionalContents);
                var provideXmlDoc = detailLevel != CodeDocMemberDetailLevel.Minimum;

                var eventCRef = GetCRefIdentifier(eventInfo);
                var model = new CodeDocEvent(eventCRef);
                model.Uri = GetUri(eventInfo);

                var memberDataProvider = new CodeDocMemberInfoProvider<EventInfo>(eventInfo);

                if (provideXmlDoc) {
                    var xmlDocs = XmlDocs.GetMember(eventCRef.FullCRef);
                    if (xmlDocs != null)
                        memberDataProvider.Add(new CodeDocMemberXmlDataProvider(xmlDocs));
                }

                if (extraMemberDataProvider != null)
                    memberDataProvider.Add(extraMemberDataProvider);

                if (includeInheritance) {
                    var baseEvent = eventInfo.FindNextAncestor();
                    if (baseEvent != null) {
                        var baseEventModel = GetOnly(GetCRefIdentifier(baseEvent), detailLevel);
                        if (baseEventModel != null)
                            memberDataProvider.Add(new CodeDocMemberDataProvider(baseEventModel));
                    }
                }

                if (appendXmlDoc)
                    ApplyContentXmlDocs(model, memberDataProvider);

                model.ExternalVisibility = memberDataProvider.ExternalVisibility ?? ExternalVisibilityKind.Public;
                model.ShortName = RegularTypeDisplayNameOverlay.GetDisplayName(memberDataProvider.Member);
                model.FullName = FullTypeDisplayNameOverlay.GetDisplayName(memberDataProvider.Member);
                model.Title = model.ShortName;
                Contract.Assume(memberDataProvider.Member.DeclaringType != null);
                model.NamespaceName = memberDataProvider.Member.DeclaringType.Namespace;
                model.SubTitle = "Event";

                model.DelegateType = GetOrConvert(eventInfo.EventHandlerType, CodeDocMemberDetailLevel.Minimum);
                Contract.Assume(eventInfo.DeclaringType != null);
                model.Namespace = GetOrCreateNamespaceByName(eventInfo.DeclaringType.Namespace);
                model.Assembly = GetCodeDocAssembly(eventInfo.DeclaringType.Assembly);
                model.DeclaringType = GetOrConvert(eventInfo.DeclaringType, CodeDocMemberDetailLevel.Minimum);
                model.IsStatic = memberDataProvider.IsStatic.GetValueOrDefault();
                model.IsObsolete = memberDataProvider.IsObsolete.GetValueOrDefault();

                return model;
            }