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

GetCSharpName() private static method

private static GetCSharpName ( Type t, Type parameters, int index, StringBuilder sb ) : int
t System.Type
parameters System.Type
index int
sb StringBuilder
return int
        private static int GetCSharpName(Type t, Type[] parameters, int index, StringBuilder sb)
        {
            if (t.DeclaringType != null && t.DeclaringType != t)
            {
                index = GetCSharpName(t.DeclaringType, parameters, index, sb);
                sb.Append(".");
            }
            string name = t.Name;
            int nameEnd = name.IndexOf('`');
            if (nameEnd < 0)
            {
                nameEnd = name.IndexOf('!');
            }
            if (nameEnd > 0)
            {
                EscapeKeywords(name.Substring(0, nameEnd), sb);
                sb.Append("<");
                int arguments = Int32.Parse(name.Substring(nameEnd + 1), CultureInfo.InvariantCulture) + index;
                for (; index < arguments; index++)
                {
                    sb.Append(GetCSharpName(parameters[index]));
                    if (index < arguments - 1)
                    {
                        sb.Append(",");
                    }
                }
                sb.Append(">");
            }
            else
            {
                EscapeKeywords(name, sb);
            }
            return index;
        }

Same methods

CodeIdentifier::GetCSharpName ( Type t ) : string
CodeIdentifier::GetCSharpName ( string name ) : string

Usage Example

 private void GenerateGetSerializer(Hashtable serializers, XmlMapping[] xmlMappings)
 {
     this.writer.Write("public override ");
     this.writer.Write(typeof(XmlSerializer).FullName);
     this.writer.Write(" GetSerializer(");
     this.writer.Write(typeof(Type).FullName);
     this.writer.WriteLine(" type) {");
     this.writer.Indent++;
     for (int i = 0; i < xmlMappings.Length; i++)
     {
         if (xmlMappings[i] is XmlTypeMapping)
         {
             Type type = xmlMappings[i].Accessor.Mapping.TypeDesc.Type;
             if (((type != null) && (type.IsPublic || type.IsNestedPublic)) && ((!DynamicAssemblies.IsTypeDynamic(type) && !type.IsGenericType) && (!type.ContainsGenericParameters || !DynamicAssemblies.IsTypeDynamic(type.GetGenericArguments()))))
             {
                 this.writer.Write("if (type == typeof(");
                 this.writer.Write(CodeIdentifier.GetCSharpName(type));
                 this.writer.Write(")) return new ");
                 this.writer.Write((string)serializers[xmlMappings[i].Key]);
                 this.writer.WriteLine("();");
             }
         }
     }
     this.writer.WriteLine("return null;");
     this.writer.Indent--;
     this.writer.WriteLine("}");
 }
All Usage Examples Of System.Xml.Serialization.CodeIdentifier::GetCSharpName