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

EscapeKeywords() private static method

private static EscapeKeywords ( string identifier ) : string
identifier string
return string
        private static string EscapeKeywords(string identifier)
        {
            if (identifier == null || identifier.Length == 0) return identifier;
            string originalIdentifier = identifier;
            string[] names = identifier.Split(new char[] { '.', ',', '<', '>' });
            StringBuilder sb = new StringBuilder();
            int separator = -1;
            for (int i = 0; i < names.Length; i++)
            {
                if (separator >= 0)
                {
                    sb.Append(originalIdentifier.Substring(separator, 1));
                }
                separator++;
                separator += names[i].Length;
                string escapedName = names[i].Trim();
                EscapeKeywords(escapedName, sb);
            }
            if (sb.Length != originalIdentifier.Length)
                return sb.ToString();
            return originalIdentifier;
        }
    }

Same methods

CodeIdentifier::EscapeKeywords ( string identifier, StringBuilder sb ) : void

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