public string GetNameForRelationship(
            EntityMetadata entityMetadata
            , RelationshipMetadataBase relationshipMetadata
            , EntityRole?reflexiveRole
            , ICodeGenerationServiceProvider iCodeGenerationServiceProvider
            )
        {
            string str = reflexiveRole.HasValue ? reflexiveRole.Value.ToString() : string.Empty;

            string keyRelationship = entityMetadata.MetadataId.Value.ToString() + relationshipMetadata.MetadataId.Value + str;

            if (this._knowNames.ContainsKey(keyRelationship))
            {
                return(this._knowNames[keyRelationship]);
            }

            string validName = NamingService.CreateValidName(relationshipMetadata.SchemaName + (!reflexiveRole.HasValue ? string.Empty : reflexiveRole.Value == EntityRole.Referenced ? "_Referenced" : "_Referencing"));

            Dictionary <string, string> knownNamesForEntityMetadata = this._knowNames.Where(d => d.Key.StartsWith(entityMetadata.MetadataId.Value.ToString())).ToDictionary(d => d.Key, d => d.Value);

            validName = ResolveConflictName(validName, s => this._reservedAttributeNames.Contains(s) || knownNamesForEntityMetadata.ContainsValue(s) || string.Equals(s, _typeName, StringComparison.InvariantCultureIgnoreCase));

            this._knowNames.Add(keyRelationship, validName);

            return(validName);
        }
        private string CreateValidTypeName(string name)
        {
            string validName = NamingService.CreateValidName(name);

            if (this._nameMap.ContainsKey(validName))
            {
                int num = ++this._nameMap[validName];
                return(string.Format(CultureInfo.InvariantCulture, "{0}{1}", validName, num));
            }

            this._nameMap.Add(name, 0);

            return(validName);
        }
        public string GetNameForResponseField(
            CodeGenerationSdkMessageResponse response
            , Entities.SdkMessageResponseField responseField
            , ICodeGenerationServiceProvider iCodeGenerationServiceProvider
            )
        {
            if (this._knowNames.ContainsKey(response.Id.ToString() + responseField.Position.GetValueOrDefault().ToString(CultureInfo.InvariantCulture)))
            {
                return(this._knowNames[response.Id.ToString() + responseField.Position.GetValueOrDefault().ToString(CultureInfo.InvariantCulture)]);
            }

            string validName = NamingService.CreateValidName(responseField.Name);

            this._knowNames.Add(response.Id.ToString() + responseField.Position.GetValueOrDefault().ToString(CultureInfo.InvariantCulture), validName);
            return(validName);
        }
        public string GetNameForAttribute(
            EntityMetadata entityMetadata
            , AttributeMetadata attributeMetadata
            , ICodeGenerationServiceProvider iCodeGenerationServiceProvider)
        {
            string validName = NamingService.CreateValidName(StaticNamingService.GetNameForAttribute(attributeMetadata) ?? attributeMetadata.SchemaName);

            CodeDomProvider provider = CodeDomProvider.CreateProvider("CSharp");

            if (!provider.IsValidIdentifier(validName))
            {
                validName = "@" + validName;
            }

            return(validName);
        }
        public string GetNameForOption(
            OptionSetMetadata optionSetMetadata
            , OptionMetadata optionMetadata
            , ICodeGenerationServiceProvider iCodeGenerationServiceProvider
            )
        {
            if (this._knowNames.ContainsKey(optionSetMetadata.MetadataId.Value.ToString() + optionMetadata.Value.Value.ToString(CultureInfo.InvariantCulture)))
            {
                return(this._knowNames[optionSetMetadata.MetadataId.Value.ToString() + optionMetadata.Value.Value.ToString(CultureInfo.InvariantCulture)]);
            }

            string name = string.Empty;

            StateOptionMetadata stateOptionMetadata = optionMetadata as StateOptionMetadata;

            if (stateOptionMetadata != null)
            {
                name = stateOptionMetadata.InvariantName;
            }
            else
            {
                foreach (LocalizedLabel localizedLabel in optionMetadata.Label.LocalizedLabels)
                {
                    if (localizedLabel.LanguageCode == 1033)
                    {
                        name = localizedLabel.Label;
                    }
                }
            }

            if (string.IsNullOrEmpty(name))
            {
                name = string.Format(CultureInfo.InvariantCulture, "UnknownLabel{0}", (object)optionMetadata.Value.Value);
            }

            string validName = NamingService.CreateValidName(name);

            this._knowNames.Add(optionSetMetadata.MetadataId.Value.ToString() + optionMetadata.Value.Value.ToString(CultureInfo.InvariantCulture), validName);

            return(validName);
        }