MongoDB.Bson.Serialization.TypeNameDiscriminator.GetDiscriminator C# (CSharp) Метод

GetDiscriminator() публичный статический Метод

Gets a type name to be used as a discriminator (like AssemblyQualifiedName but shortened for common DLLs).
public static GetDiscriminator ( Type type ) : string
type System.Type The type.
Результат string
        public static string GetDiscriminator(Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            string typeName;
            if (type.IsGenericType)
            {
                var typeArgumentNames = "";
                foreach (var typeArgument in type.GetGenericArguments())
                {
                    var typeArgumentName = GetDiscriminator(typeArgument);
                    if (typeArgumentName.IndexOf(',') != -1)
                    {
                        typeArgumentName = "[" + typeArgumentName + "]";
                    }
                    if (typeArgumentNames != "")
                    {
                        typeArgumentNames += ",";
                    }
                    typeArgumentNames += typeArgumentName;
                }
                typeName = type.GetGenericTypeDefinition().FullName + "[" + typeArgumentNames + "]";
            }
            else
            {
                typeName = type.FullName;
            }

            string assemblyName = null;
            if (!__wellKnownAssemblies.Contains(type.Assembly))
            {
                assemblyName = type.Assembly.FullName;
                Match match = Regex.Match(assemblyName, "(?<dll>[^,]+), Version=[^,]+, Culture=[^,]+, PublicKeyToken=(?<token>[^,]+)");
                if (match.Success)
                {
                    var publicKeyToken = match.Groups["token"].Value;
                    if (publicKeyToken == "null")
                    {
                        var dllName = match.Groups["dll"].Value;
                        assemblyName = dllName;
                    }
                }
            }

            if (assemblyName == null)
            {
                return typeName;
            }
            else
            {
                return typeName + ", " + assemblyName;
            }
        }