Thinktecture.Tools.Web.Services.CodeGeneration.MessageContractConverter.OnTypeNameChanged C# (CSharp) Method

OnTypeNameChanged() protected method

protected OnTypeNameChanged ( CodeTypeExtension typeExtension, string oldName, string newName ) : void
typeExtension CodeTypeExtension
oldName string
newName string
return void
        protected override void OnTypeNameChanged(CodeTypeExtension typeExtension, string oldName, string newName)
        {
            // Prepare the MessageContractAttribute attribute to specify the type name on the wire.
            CodeAttributeDeclaration messageContractAttribute = typeExtension.FindAttribute("System.ServiceModel.MessageContractAttribute");
            if (messageContractAttribute != null)
            {
                CodeAttributeArgument wrapperNameArgument = messageContractAttribute.Arguments
                    .OfType<CodeAttributeArgument>()
                    .FirstOrDefault(arg => arg.Name.Equals("WrapperName", StringComparison.OrdinalIgnoreCase));

                if (wrapperNameArgument == null)
                    return;

                CodePrimitiveExpression wrapperNameValue = wrapperNameArgument.Value as CodePrimitiveExpression;
                if (wrapperNameValue != null && !string.IsNullOrEmpty((string)wrapperNameValue.Value))
                {
                    string newWrapperNameValue = PascalCaseConverterHelper.GetPascalCaseName((string)wrapperNameValue.Value);
                    wrapperNameArgument.Value = new CodePrimitiveExpression(newWrapperNameValue);
                }
            }
            else
            {
                CodeAttributeDeclaration xmlType =
                    new CodeAttributeDeclaration("System.ServiceModel.MessageContractAttribute",
                    new CodeAttributeArgumentExtended("WrapperName",
                    new CodePrimitiveExpression(oldName), true));

                // Add the XmlTypeAttribute attribute to ctd.
                typeExtension.AddAttribute(xmlType);
            }
        }