System.Xml.Serialization.CodeIdentifier.EscapeKeywords C# (CSharp) Method

EscapeKeywords() private static method

private static EscapeKeywords ( string identifier, StringBuilder sb ) : void
identifier string
sb StringBuilder
return void
        private static void EscapeKeywords(string identifier, StringBuilder sb)
        {
            if (identifier == null || identifier.Length == 0)
                return;
            int arrayCount = 0;
            while (identifier.EndsWith("[]", StringComparison.Ordinal))
            {
                arrayCount++;
                identifier = identifier.Substring(0, identifier.Length - 2);
            }
            if (identifier.Length > 0)
            {
                CheckValidIdentifier(identifier);
                identifier = CSharpHelpers.CreateEscapedIdentifier(identifier);
                sb.Append(identifier);
            }
            for (int i = 0; i < arrayCount; i++)
            {
                sb.Append("[]");
            }
        }

Same methods

CodeIdentifier::EscapeKeywords ( string identifier ) : string

Usage Example

Example #1
0
        void ExportRoot(StructMapping mapping)
        {
            if (!rootExported)
            {
                rootExported = true;
                ExportDerivedStructs(mapping);

                for (StructMapping derived = mapping.DerivedMappings; derived != null; derived = derived.NextDerivedMapping)
                {
                    if (!derived.ReferencedByElement)
                    {
                        string fullTypeName = CodeIdentifier.EscapeKeywords(derived.TypeDesc.FullName);
                        CodeAttributeArgument[] arguments = new CodeAttributeArgument[] { new CodeAttributeArgument(new CodeTypeOfExpression(fullTypeName)) };
                        AddCustomAttribute(includeMetadata, typeof(XmlIncludeAttribute), arguments);
                    }
                }
                Hashtable typesIncluded = new Hashtable();
                foreach (TypeMapping m in scope.TypeMappings)
                {
                    if (m is ArrayMapping)
                    {
                        ArrayMapping arrayMapping = (ArrayMapping)m;
                        if (ShouldInclude(arrayMapping) && !typesIncluded.Contains(arrayMapping.TypeDesc.FullName))
                        {
                            string fullTypeName = CodeIdentifier.EscapeKeywords(arrayMapping.TypeDesc.FullName);
                            CodeAttributeArgument[] arguments = new CodeAttributeArgument[] { new CodeAttributeArgument(new CodeTypeOfExpression(fullTypeName)) };
                            AddCustomAttribute(includeMetadata, typeof(XmlIncludeAttribute), arguments);
                            typesIncluded.Add(arrayMapping.TypeDesc.FullName, "");
                        }
                    }
                }
            }
        }
All Usage Examples Of System.Xml.Serialization.CodeIdentifier::EscapeKeywords