Пример #1
0
            private StringBuilder GetTypeString(Type type, SerializationContext context)
            {
                StringBuilder sb = null;
                if (type.GetGenericArguments().Length > 0)
                {
                    // generikus típusok
                    string arrayMarks = string.Empty;
                    if (IsNestedType(type))
                    {
                        sb = new StringBuilder(GetTypeNameWithoutArrayMarks(type, false, out arrayMarks));
                    }
                    else
                    {
                        sb = new StringBuilder(string.Format("{0}.{1}", type.Namespace, GetTypeNameWithoutArrayMarks(type, false, out arrayMarks)));
                    }
                    if (!type.IsGenericTypeDefinition)
                    {
                        // nyers generikus típusok paraméterlistáját nem serializáljuk
                        sb.Append("[");
                        bool writeComma = false;
                        foreach (Type arrayType in type.GetGenericArguments())
                        {
                            if (writeComma)
                            {
                                sb.Append(";");
                            }
                            else
                            {
                                writeComma = true;
                            }
                            sb.Append(context.GetTypeInfo(arrayType).TypeId.ToString());
                        }
                        sb.Append("]");
                    }
                    sb.Append(arrayMarks);
                }
                else
                {
                    // nem generikus típusok
                    if (IsNestedType(type))
                    {
                        sb = new StringBuilder(type.Name);
                    }
                    else
                    {
                        sb = new StringBuilder(type.FullName);
                    }
                }

                if (IsNestedType(type))
                {
                    Type declaringType = GetDeclaringType(type);
                    sb.Insert(0, string.Format("({0})+", context.GetTypeInfo(declaringType).TypeId.ToString()));
                }

                if (AssemblyId != -1)
                {
                    sb.Append("{");
                    sb.Append(AssemblyId.ToString());
                    sb.Append("}");
                }

                return sb;
            }