GetUniqueIdentifier() private method

Given an identifier, makes it unique within the scope by adding a suffix (1, 2, 3, ...), and returns the adjusted identifier.
private GetUniqueIdentifier ( string identifier ) : string
identifier string Identifier. Must not be null or empty.
return string
        // This is to solve duplicate names between property and type
        internal void SetPropertyIdentifierMappingsIfNameConflicts(string typeName, IEdmStructuredType structuredType)
        {
            if (Context.EnableNamingAlias)
            {
                typeName = Customization.CustomizeNaming(typeName);
            }

            // PropertyName in VB is case-insensitive.
            var isLanguageCaseSensitive = true;

            // In VB, it is allowed that a type has a property whose name is same with the type's name
            var allowPropertyNameSameWithTypeName = false;

            Func<string, string> customizePropertyName = name => { return Context.EnableNamingAlias ? Customization.CustomizeNaming(name) : name; };

            var propertyGroups = structuredType.Properties()
                .GroupBy(p => isLanguageCaseSensitive ? customizePropertyName(p.Name) : customizePropertyName(p.Name).ToUpperInvariant());

            // If the group contains more than one property, or the property in the group has the same name with the type (only for C#), we need to rename the property
            var propertyToBeRenamedGroups = propertyGroups.Where(g => g.Count() > 1 || !allowPropertyNameSameWithTypeName && g.Key == typeName);

            var knownIdentifiers = propertyGroups.Select(g => customizePropertyName(g.First().Name)).ToList();
            if (!allowPropertyNameSameWithTypeName && !knownIdentifiers.Contains(typeName))
            {
                knownIdentifiers.Add(typeName);
            }
            var uniqueIdentifierService =
                new UniqueIdentifierService(knownIdentifiers, isLanguageCaseSensitive);

            IdentifierMappings.Clear();
            foreach (var g in propertyToBeRenamedGroups)
            {
                var hasPropertyNameSameWithCustomizedPropertyName = false;
                var itemCount = g.Count();
                for (var i = 0; i < itemCount; i++)
                {
                    var property = g.ElementAt(i);
                    var customizedPropertyName = customizePropertyName(property.Name);

                    if (Context.EnableNamingAlias && customizedPropertyName == property.Name)
                    {
                        hasPropertyNameSameWithCustomizedPropertyName = true;
                    }

                    if (isLanguageCaseSensitive)
                    {
                        // If a property name is same as its customized property name, then we don't rename it.
                        // Or we don't rename the last property in the group
                        if (customizedPropertyName != typeName
                            && (customizedPropertyName == property.Name
                                || (!hasPropertyNameSameWithCustomizedPropertyName && i == itemCount - 1)))
                        {
                            continue;
                        }
                    }
                    else
                    {
                        // When EnableNamingAlias = true, If a property name is same as its customized property name, then we don't rename it.
                        // Or we don't rename the last property in the group.
                        if ((Context.EnableNamingAlias && customizedPropertyName == property.Name)
                            || (!hasPropertyNameSameWithCustomizedPropertyName && i == itemCount - 1))
                        {
                            continue;
                        }
                    }
                    var renamedPropertyName = uniqueIdentifierService.GetUniqueIdentifier(customizedPropertyName);
                    IdentifierMappings.Add(property.Name, renamedPropertyName);
                }
            }
        }
        internal void WritePropertiesForStructuredType(IEnumerable<IEdmProperty> properties)
        {
            var useDataServiceCollection = Context.UseDataServiceCollection;

            var propertyInfos = properties.Select(property =>
            {
                var propertyName = IdentifierMappings.ContainsKey(property.Name) ?
                    IdentifierMappings[property.Name] : (Context.EnableNamingAlias ? Customization.CustomizeNaming(property.Name) : property.Name);

                return new
                {
                    PropertyType = Utils.GetClrTypeName(property.Type, useDataServiceCollection, this, Context),
                    PropertyVanillaName = property.Name,
                    PropertyName = propertyName,
                    FixedPropertyName = GetFixedName(propertyName),
                    PrivatePropertyName = "_" + propertyName,
                    PropertyInitializationValue = Utils.GetPropertyInitializationValue(property, useDataServiceCollection, this, Context)
                };
            }).ToList();

            // Private name should not confict with field name
            var uniqueIdentifierService = new UniqueIdentifierService(propertyInfos.Select(_ => _.FixedPropertyName), true);

            foreach (var propertyInfo in propertyInfos)
            {
                var privatePropertyName = uniqueIdentifierService.GetUniqueIdentifier("_" + propertyInfo.PropertyName);

                WritePropertyForStructuredType(
                    propertyInfo.PropertyType,
                    propertyInfo.PropertyVanillaName,
                    propertyInfo.PropertyName,
                    propertyInfo.FixedPropertyName,
                    privatePropertyName,
                    propertyInfo.PropertyInitializationValue,
                    useDataServiceCollection);
            }
        }