Пример #1
0
        public override string ToString()
        {
            string result = null;

            TypeNameBuilder.ToString(this.m_typeNameBuilder, JitHelpers.GetStringHandleOnStack(ref result));
            return(result);
        }
Пример #2
0
        public override string ToString()
        {
            string s = (string)null;

            TypeNameBuilder.ToString(this.m_typeNameBuilder, JitHelpers.GetStringHandleOnStack(ref s));
            return(s);
        }
        internal static string ToString(Type type, Format format)
        {
            if (((format == Format.FullName) || (format == Format.AssemblyQualifiedName)) && (!type.IsGenericTypeDefinition && type.ContainsGenericParameters))
            {
                return(null);
            }
            TypeNameBuilder builder = new TypeNameBuilder(CreateTypeNameBuilder());

            builder.Clear();
            builder.ConstructAssemblyQualifiedNameWorker(type, format);
            string str = builder.ToString();

            builder.Dispose();
            return(str);
        }
Пример #4
0
        internal static string?ToString(Type type, Format format)
        {
            if (format == Format.FullName || format == Format.AssemblyQualifiedName)
            {
                if (!type.IsGenericTypeDefinition && type.ContainsGenericParameters)
                {
                    return(null);
                }
            }

            var tnb = new TypeNameBuilder();

            tnb.AddAssemblyQualifiedName(type, format);
            return(tnb.ToString());
        }
Пример #5
0
 // TypeNameBuilder is NOT thread safe NOR reliable
 internal static string ToString(Type type, Format format)
 {
     if (format == Format.FullName || format == Format.AssemblyQualifiedName)
     {
         if (!type.IsGenericTypeDefinition && type.ContainsGenericParameters)
             return null;
     }
     
     TypeNameBuilder tnb = new TypeNameBuilder(CreateTypeNameBuilder());
     tnb.Clear();
     tnb.ConstructAssemblyQualifiedNameWorker(type, format);
     string toString = tnb.ToString();
     tnb.Dispose();
     return toString;
 }
Пример #6
0
        internal static string ToString(Type type, TypeNameBuilder.Format format)
        {
            if ((format == TypeNameBuilder.Format.FullName || format == TypeNameBuilder.Format.AssemblyQualifiedName) && !type.IsGenericTypeDefinition && type.ContainsGenericParameters)
            {
                return(null);
            }
            TypeNameBuilder typeNameBuilder = new TypeNameBuilder(TypeNameBuilder.CreateTypeNameBuilder());

            typeNameBuilder.Clear();
            typeNameBuilder.ConstructAssemblyQualifiedNameWorker(type, format);
            string result = typeNameBuilder.ToString();

            typeNameBuilder.Dispose();
            return(result);
        }
Пример #7
0
        internal static string ToString(Type type, TypeNameBuilder.Format format)
        {
            if ((format == TypeNameBuilder.Format.FullName || format == TypeNameBuilder.Format.AssemblyQualifiedName) && (!type.IsGenericTypeDefinition && type.ContainsGenericParameters))
            {
                return((string)null);
            }
            TypeNameBuilder typeNameBuilder = new TypeNameBuilder(TypeNameBuilder.CreateTypeNameBuilder());

            typeNameBuilder.Clear();
            Type type1 = type;
            int  num   = (int)format;

            typeNameBuilder.ConstructAssemblyQualifiedNameWorker(type1, (TypeNameBuilder.Format)num);
            string @string = typeNameBuilder.ToString();

            typeNameBuilder.Dispose();
            return(@string);
        }
Пример #8
0
        [System.Security.SecuritySafeCritical]  // auto-generated
        internal static string ToString(Type type, Format format)
        {
            if (format == Format.FullName || format == Format.AssemblyQualifiedName)
            {
                if (!type.IsGenericTypeDefinition && type.ContainsGenericParameters)
                {
                    return(null);
                }
            }

            TypeNameBuilder tnb = new TypeNameBuilder(CreateTypeNameBuilder());

            tnb.Clear();
            tnb.ConstructAssemblyQualifiedNameWorker(type, format);
            string toString = tnb.ToString();

            tnb.Dispose();
            return(toString);
        }
Пример #9
0
 private void OpenGenericArgument()
 {
     TypeNameBuilder.OpenGenericArgument(this.m_typeNameBuilder);
 }
Пример #10
0
 private void AddAssemblySpec(string assemblySpec)
 {
     TypeNameBuilder.AddAssemblySpec(this.m_typeNameBuilder, assemblySpec);
 }
Пример #11
0
 private void AddArray(int rank)
 {
     TypeNameBuilder.AddArray(this.m_typeNameBuilder, rank);
 }
Пример #12
0
 private void AddSzArray()
 {
     TypeNameBuilder.AddSzArray(this.m_typeNameBuilder);
 }
Пример #13
0
 private void AddByRef()
 {
     TypeNameBuilder.AddByRef(this.m_typeNameBuilder);
 }
Пример #14
0
        private void EmitValue(BinaryWriter writer, Type type, object value)
        {
            if (type.IsEnum)
            {
                switch (Type.GetTypeCode(Enum.GetUnderlyingType(type)))
                {
                case TypeCode.SByte:
                    writer.Write((sbyte)value);
                    break;

                case TypeCode.Byte:
                    writer.Write((byte)value);
                    break;

                case TypeCode.Int16:
                    writer.Write((short)value);
                    break;

                case TypeCode.UInt16:
                    writer.Write((ushort)value);
                    break;

                case TypeCode.Int32:
                    writer.Write((int)value);
                    break;

                case TypeCode.UInt32:
                    writer.Write((uint)value);
                    break;

                case TypeCode.Int64:
                    writer.Write((long)value);
                    break;

                case TypeCode.UInt64:
                    writer.Write((ulong)value);
                    break;
                }
            }
            else if (type == typeof(string))
            {
                if (value == null)
                {
                    writer.Write(byte.MaxValue);
                }
                else
                {
                    this.EmitString(writer, (string)value);
                }
            }
            else if (type == typeof(Type))
            {
                if (value == null)
                {
                    writer.Write(byte.MaxValue);
                }
                else
                {
                    string @string = TypeNameBuilder.ToString((Type)value, TypeNameBuilder.Format.AssemblyQualifiedName);
                    if (@string == null)
                    {
                        throw new ArgumentException(Environment.GetResourceString("Argument_InvalidTypeForCA", (object)value.GetType()));
                    }
                    this.EmitString(writer, @string);
                }
            }
            else if (type.IsArray)
            {
                if (value == null)
                {
                    writer.Write(uint.MaxValue);
                }
                else
                {
                    Array array       = (Array)value;
                    Type  elementType = type.GetElementType();
                    writer.Write(array.Length);
                    for (int index = 0; index < array.Length; ++index)
                    {
                        this.EmitValue(writer, elementType, array.GetValue(index));
                    }
                }
            }
            else if (type.IsPrimitive)
            {
                switch (Type.GetTypeCode(type))
                {
                case TypeCode.Boolean:
                    writer.Write((bool)value ? (byte)1 : (byte)0);
                    break;

                case TypeCode.Char:
                    writer.Write(Convert.ToUInt16((char)value));
                    break;

                case TypeCode.SByte:
                    writer.Write((sbyte)value);
                    break;

                case TypeCode.Byte:
                    writer.Write((byte)value);
                    break;

                case TypeCode.Int16:
                    writer.Write((short)value);
                    break;

                case TypeCode.UInt16:
                    writer.Write((ushort)value);
                    break;

                case TypeCode.Int32:
                    writer.Write((int)value);
                    break;

                case TypeCode.UInt32:
                    writer.Write((uint)value);
                    break;

                case TypeCode.Int64:
                    writer.Write((long)value);
                    break;

                case TypeCode.UInt64:
                    writer.Write((ulong)value);
                    break;

                case TypeCode.Single:
                    writer.Write((float)value);
                    break;

                case TypeCode.Double:
                    writer.Write((double)value);
                    break;
                }
            }
            else if (type == typeof(object))
            {
                Type type1 = value == null ? typeof(string) : (value is Type ? typeof(Type) : value.GetType());
                if (type1 == typeof(object))
                {
                    throw new ArgumentException(Environment.GetResourceString("Argument_BadParameterTypeForCAB", (object)type1.ToString()));
                }
                this.EmitType(writer, type1);
                this.EmitValue(writer, type1, value);
            }
            else
            {
                string str = "null";
                if (value != null)
                {
                    str = value.GetType().ToString();
                }
                throw new ArgumentException(Environment.GetResourceString("Argument_BadParameterTypeForCAB", (object)str));
            }
        }
 internal static string ToString(Type type, Format format)
 {
     if (((format == Format.FullName) || (format == Format.AssemblyQualifiedName)) && (!type.IsGenericTypeDefinition && type.ContainsGenericParameters))
     {
         return null;
     }
     TypeNameBuilder builder = new TypeNameBuilder(CreateTypeNameBuilder());
     builder.Clear();
     builder.ConstructAssemblyQualifiedNameWorker(type, format);
     string str = builder.ToString();
     builder.Dispose();
     return str;
 }
Пример #16
0
 private void Clear()
 {
     TypeNameBuilder.Clear(this.m_typeNameBuilder);
 }
Пример #17
0
 internal void Dispose()
 {
     TypeNameBuilder.ReleaseTypeNameBuilder(this.m_typeNameBuilder);
 }
Пример #18
0
 private void CloseGenericArgument()
 {
     TypeNameBuilder.CloseGenericArgument(this.m_typeNameBuilder);
 }
Пример #19
0
 private void AddName(string name)
 {
     TypeNameBuilder.AddName(this.m_typeNameBuilder, name);
 }
        private static void EmitValue(BinaryWriter writer, Type type, object?value)
        {
            if (type.IsEnum)
            {
                switch (Type.GetTypeCode(Enum.GetUnderlyingType(type)))
                {
                case TypeCode.SByte:
                    writer.Write((sbyte)value !);
                    break;

                case TypeCode.Byte:
                    writer.Write((byte)value !);
                    break;

                case TypeCode.Int16:
                    writer.Write((short)value !);
                    break;

                case TypeCode.UInt16:
                    writer.Write((ushort)value !);
                    break;

                case TypeCode.Int32:
                    writer.Write((int)value !);
                    break;

                case TypeCode.UInt32:
                    writer.Write((uint)value !);
                    break;

                case TypeCode.Int64:
                    writer.Write((long)value !);
                    break;

                case TypeCode.UInt64:
                    writer.Write((ulong)value !);
                    break;

                default:
                    Debug.Fail("Invalid enum base type");
                    break;
                }
            }
            else if (type == typeof(string))
            {
                if (value == null)
                {
                    writer.Write((byte)0xff);
                }
                else
                {
                    EmitString(writer, (string)value);
                }
            }
            else if (type == typeof(Type))
            {
                if (value == null)
                {
                    writer.Write((byte)0xff);
                }
                else
                {
                    string?typeName = TypeNameBuilder.ToString((Type)value, TypeNameBuilder.Format.AssemblyQualifiedName);
                    if (typeName == null)
                    {
                        throw new ArgumentException(SR.Format(SR.Argument_InvalidTypeForCA, value.GetType()));
                    }
                    EmitString(writer, typeName);
                }
            }
            else if (type.IsArray)
            {
                if (value == null)
                {
                    writer.Write((uint)0xffffffff);
                }
                else
                {
                    Array a  = (Array)value;
                    Type  et = type.GetElementType() !;
                    writer.Write(a.Length);
                    for (int i = 0; i < a.Length; i++)
                    {
                        EmitValue(writer, et, a.GetValue(i));
                    }
                }
            }
            else if (type.IsPrimitive)
            {
                switch (Type.GetTypeCode(type))
                {
                case TypeCode.SByte:
                    writer.Write((sbyte)value !);
                    break;

                case TypeCode.Byte:
                    writer.Write((byte)value !);
                    break;

                case TypeCode.Char:
                    writer.Write(Convert.ToUInt16((char)value !));
                    break;

                case TypeCode.Boolean:
                    writer.Write((byte)((bool)value ! ? 1 : 0));
                    break;

                case TypeCode.Int16:
                    writer.Write((short)value !);
                    break;

                case TypeCode.UInt16:
                    writer.Write((ushort)value !);
                    break;

                case TypeCode.Int32:
                    writer.Write((int)value !);
                    break;

                case TypeCode.UInt32:
                    writer.Write((uint)value !);
                    break;

                case TypeCode.Int64:
                    writer.Write((long)value !);
                    break;

                case TypeCode.UInt64:
                    writer.Write((ulong)value !);
                    break;

                case TypeCode.Single:
                    writer.Write((float)value !);
                    break;

                case TypeCode.Double:
                    writer.Write((double)value !);
                    break;

                default:
                    Debug.Fail("Invalid primitive type");
                    break;
                }
            }
            else if (type == typeof(object))
            {
                // Tagged object case. Type instances aren't actually Type, they're some subclass (such as RuntimeType or
                // TypeBuilder), so we need to canonicalize this case back to Type. If we have a null value we follow the convention
                // used by C# and emit a null typed as a string (it doesn't really matter what type we pick as long as it's a
                // reference type).
                Type ot = value == null ? typeof(string) : value is Type ? typeof(Type) : value.GetType();

                // value cannot be a "System.Object" object.
                // If we allow this we will get into an infinite recursion
                if (ot == typeof(object))
                {
                    throw new ArgumentException(SR.Format(SR.Argument_BadParameterTypeForCAB, ot));
                }

                EmitType(writer, ot);
                EmitValue(writer, ot, value);
            }
            else
            {
                string typename = "null";

                if (value != null)
                {
                    typename = value.GetType().ToString();
                }

                throw new ArgumentException(SR.Format(SR.Argument_BadParameterTypeForCAB, typename));
            }
        }
Пример #21
0
 private void AddPointer()
 {
     TypeNameBuilder.AddPointer(this.m_typeNameBuilder);
 }
Пример #22
0
 public override String ToString()
 {
     return(TypeNameBuilder.ToString(this, TypeNameBuilder.Format.ToString));
 }
Пример #23
0
        private void EmitValue(BinaryWriter writer, Type type, object value)
        {
            if (type.IsEnum)
            {
                switch (Type.GetTypeCode(Enum.GetUnderlyingType(type)))
                {
                case TypeCode.SByte:
                    writer.Write((sbyte)value);
                    return;

                case TypeCode.Byte:
                    writer.Write((byte)value);
                    return;

                case TypeCode.Int16:
                    writer.Write((short)value);
                    return;

                case TypeCode.UInt16:
                    writer.Write((ushort)value);
                    return;

                case TypeCode.Int32:
                    writer.Write((int)value);
                    return;

                case TypeCode.UInt32:
                    writer.Write((uint)value);
                    return;

                case TypeCode.Int64:
                    writer.Write((long)value);
                    return;

                case TypeCode.UInt64:
                    writer.Write((ulong)value);
                    return;
                }
            }
            else if (type == typeof(string))
            {
                if (value == null)
                {
                    writer.Write((byte)0xff);
                }
                else
                {
                    this.EmitString(writer, (string)value);
                }
            }
            else if (type == typeof(Type))
            {
                if (value == null)
                {
                    writer.Write((byte)0xff);
                }
                else
                {
                    string str = TypeNameBuilder.ToString((Type)value, TypeNameBuilder.Format.AssemblyQualifiedName);
                    if (str == null)
                    {
                        throw new ArgumentException(Environment.GetResourceString("Argument_InvalidTypeForCA", new object[] { value.GetType() }));
                    }
                    this.EmitString(writer, str);
                }
            }
            else if (type.IsArray)
            {
                if (value == null)
                {
                    writer.Write(uint.MaxValue);
                }
                else
                {
                    Array array       = (Array)value;
                    Type  elementType = type.GetElementType();
                    writer.Write(array.Length);
                    for (int i = 0; i < array.Length; i++)
                    {
                        this.EmitValue(writer, elementType, array.GetValue(i));
                    }
                }
            }
            else if (type.IsPrimitive)
            {
                switch (Type.GetTypeCode(type))
                {
                case TypeCode.Boolean:
                    writer.Write(((bool)value) ? ((byte)1) : ((byte)0));
                    return;

                case TypeCode.Char:
                    writer.Write(Convert.ToUInt16((char)value));
                    return;

                case TypeCode.SByte:
                    writer.Write((sbyte)value);
                    return;

                case TypeCode.Byte:
                    writer.Write((byte)value);
                    return;

                case TypeCode.Int16:
                    writer.Write((short)value);
                    return;

                case TypeCode.UInt16:
                    writer.Write((ushort)value);
                    return;

                case TypeCode.Int32:
                    writer.Write((int)value);
                    return;

                case TypeCode.UInt32:
                    writer.Write((uint)value);
                    return;

                case TypeCode.Int64:
                    writer.Write((long)value);
                    return;

                case TypeCode.UInt64:
                    writer.Write((ulong)value);
                    return;

                case TypeCode.Single:
                    writer.Write((float)value);
                    return;

                case TypeCode.Double:
                    writer.Write((double)value);
                    return;
                }
            }
            else if (type == typeof(object))
            {
                Type type3 = (value == null) ? typeof(string) : ((value is Type) ? typeof(Type) : value.GetType());
                if (type3 == typeof(object))
                {
                    throw new ArgumentException(Environment.GetResourceString("Argument_BadParameterTypeForCAB", new object[] { type3.ToString() }));
                }
                this.EmitType(writer, type3);
                this.EmitValue(writer, type3, value);
            }
            else
            {
                string str2 = "null";
                if (value != null)
                {
                    str2 = value.GetType().ToString();
                }
                throw new ArgumentException(Environment.GetResourceString("Argument_BadParameterTypeForCAB", new object[] { str2 }));
            }
        }