Пример #1
0
        internal void AddScalar(void *value, int size)
        {
            var pb = (byte *)value;

            if (this.bufferNesting == 0)
            {
                var scratchOld = this.scratch;
                var scratchNew = scratchOld + size;
                if (this.scratchEnd < scratchNew)
                {
                    throw new IndexOutOfRangeException(Environment.GetResourceString("EventSource_AddScalarOutOfRange"));
                }

                this.ScalarsBegin();
                this.scratch = scratchNew;

                for (int i = 0; i != size; i++)
                {
                    scratchOld[i] = pb[i];
                }
            }
            else
            {
                var oldPos = this.bufferPos;
                this.bufferPos = checked (this.bufferPos + size);
                this.EnsureBuffer();
                for (int i = 0; i != size; i++, oldPos++)
                {
                    this.buffer[oldPos] = pb[i];
                }
            }
        }
Пример #2
0
        private void PinArray(object value, int size)
        {
            var pinsTemp = this.pins;

            if (this.pinsEnd <= pinsTemp)
            {
#if PROJECTN
                throw new IndexOutOfRangeException(SR.GetResourceString("EventSource_PinArrayOutOfRange", null));
#else
                throw new IndexOutOfRangeException(Environment.GetResourceString("EventSource_PinArrayOutOfRange"));
#endif
            }

            var datasTemp = this.datas;
            if (this.datasEnd <= datasTemp)
            {
#if PROJECTN
                throw new IndexOutOfRangeException(SR.GetResourceString("EventSource_DataDescriptorsOutOfRange", null));
#else
                throw new IndexOutOfRangeException(Environment.GetResourceString("EventSource_DataDescriptorsOutOfRange"));
#endif
            }

            this.pins  = pinsTemp + 1;
            this.datas = datasTemp + 1;

            *pinsTemp = GCHandle.Alloc(value, GCHandleType.Pinned);
            datasTemp->m_Ptr  = (long)(ulong)(UIntPtr)(void *)pinsTemp->AddrOfPinnedObject();
            datasTemp->m_Size = size;
        }
Пример #3
0
        private FieldMetadata(
            string name,
            TraceLoggingDataType dataType,
            EventFieldTags tags,
            byte countFlags,
            ushort fixedCount = 0,
            byte[] custom     = null)
        {
            if (name == null)
            {
                throw new ArgumentNullException(
                          "name",
                          "This usually means that the object passed to Write is of a type that"
                          + " does not support being used as the top-level object in an event,"
                          + " e.g. a primitive or built-in type.");
            }

            Statics.CheckName(name);
            var coreType = (int)dataType & Statics.InTypeMask;

            this.name       = name;
            this.nameSize   = Encoding.UTF8.GetByteCount(this.name) + 1;
            this.inType     = (byte)(coreType | countFlags);
            this.outType    = (byte)(((int)dataType >> 8) & Statics.OutTypeMask);
            this.tags       = tags;
            this.fixedCount = fixedCount;
            this.custom     = custom;

            if (countFlags != 0)
            {
                if (coreType == (int)TraceLoggingDataType.Nil)
                {
                    throw new NotSupportedException(Environment.GetResourceString("EventSource_NotSupportedArrayOfNil"));
                }
                if (coreType == (int)TraceLoggingDataType.Binary)
                {
                    throw new NotSupportedException(Environment.GetResourceString("EventSource_NotSupportedArrayOfBinary"));
                }
#if !BROKEN_UNTIL_M3
                if (coreType == (int)TraceLoggingDataType.Utf16String ||
                    coreType == (int)TraceLoggingDataType.MbcsString)
                {
                    throw new NotSupportedException(Environment.GetResourceString("EventSource_NotSupportedArrayOfNullTerminatedString"));
                }
#endif
            }

            if (((int)this.tags & 0xfffffff) != 0)
            {
                this.outType |= Statics.OutTypeChainFlag;
            }

            if (this.outType != 0)
            {
                this.inType |= Statics.InTypeChainFlag;
            }
        }
Пример #4
0
 public void IncrementStructFieldCount()
 {
     this.inType |= Statics.InTypeChainFlag;
     this.outType++;
     if ((this.outType & Statics.OutTypeMask) == 0)
     {
         throw new NotSupportedException(Environment.GetResourceString("EventSource_TooManyFields"));
     }
 }
Пример #5
0
        public EventDescriptor(
            int id,
            byte version,
            byte channel,
            byte level,
            byte opcode,
            int task,
            long keywords
            )
        {
            if (id < 0)
            {
#if PROJECTN
                throw new ArgumentOutOfRangeException("id", SR.GetResourceString("ArgumentOutOfRange_NeedNonNegNum", "ArgumentOutOfRange_NeedNonNegNum"));
#else
                throw new ArgumentOutOfRangeException("id", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
#endif
            }

            if (id > ushort.MaxValue)
            {
#if PROJECTN
                throw new ArgumentOutOfRangeException("id", SR.Format("ArgumentOutOfRange_NeedValidId", 1, ushort.MaxValue));
#else
                throw new ArgumentOutOfRangeException("id", Environment.GetResourceString("ArgumentOutOfRange_NeedValidId", 1, ushort.MaxValue));
#endif
            }

            m_traceloggingId = 0;
            m_id             = (ushort)id;
            m_version        = version;
            m_channel        = channel;
            m_level          = level;
            m_opcode         = opcode;
            m_keywords       = keywords;

            if (task < 0)
            {
#if PROJECTN
                throw new ArgumentOutOfRangeException("task", SR.GetResourceString("ArgumentOutOfRange_NeedNonNegNum", "ArgumentOutOfRange_NeedNonNegNum"));
#else
                throw new ArgumentOutOfRangeException("task", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
#endif
            }

            if (task > ushort.MaxValue)
            {
#if PROJECTN
                throw new ArgumentOutOfRangeException("task", SR.Format(SR.GetResourceString("ArgumentOutOfRange_NeedValidId", "ArgumentOutOfRange_NeedValidId"), 1, ushort.MaxValue));
#else
                throw new ArgumentOutOfRangeException("task", Environment.GetResourceString("ArgumentOutOfRange_NeedValidId", 1, ushort.MaxValue));
#endif
            }

            m_task = (ushort)task;
        }
Пример #6
0
        public void BeginBufferedArray()
        {
            if (this.bufferedArrayFieldCount >= 0)
            {
                throw new NotSupportedException(Environment.GetResourceString("EventSource_NotSupportedNestedArraysEnums"));
            }

            this.bufferedArrayFieldCount = 0;
            this.impl.BeginBuffered();
        }
Пример #7
0
        public void EndBufferedArray()
        {
            if (this.bufferedArrayFieldCount != 1)
            {
                throw new InvalidOperationException(Environment.GetResourceString("EventSource_IncorrentlyAuthoredTypeInfo"));
            }

            this.bufferedArrayFieldCount = int.MinValue;
            this.impl.EndBuffered();
        }
Пример #8
0
        private static int AddValueToMetaData(List <byte> metaData, string value)
        {
            if (value.Length == 0)
            {
                return(0);
            }

            int  startPos  = metaData.Count;
            char firstChar = value[0];

            if (firstChar == '@')
            {
                metaData.AddRange(Encoding.UTF8.GetBytes(value.Substring(1)));
            }
            else if (firstChar == '{')
            {
                metaData.AddRange(new Guid(value).ToByteArray());
            }
            else if (firstChar == '#')
            {
                for (int i = 1; i < value.Length; i++)
                {
                    if (value[i] != ' ')        // Skp spaces between bytes.
                    {
                        if (!(i + 1 < value.Length))
                        {
#if PROJECTN
                            throw new ArgumentException(SR.GetResourceString("EvenHexDigits", null), "traits");
#else
                            throw new ArgumentException(Environment.GetResourceString("EvenHexDigits"), "traits");
#endif
                        }
                        metaData.Add((byte)(HexDigit(value[i]) * 16 + HexDigit(value[i + 1])));
                        i++;
                    }
                }
            }
            else if (' ' <= firstChar)      // Is it alphabetic (excludes digits and most punctuation.
            {
                metaData.AddRange(Encoding.UTF8.GetBytes(value));
            }
            else
            {
#if PROJECTN
                throw new ArgumentException(SR.GetResourceString("IllegalValue", value), "traits");
#else
                throw new ArgumentException(Environment.GetResourceString("IllegalValue", value), "traits");
#endif
            }

            return(metaData.Count - startPos);
        }
Пример #9
0
        private void ScalarsBegin()
        {
            if (!this.writingScalars)
            {
                var datasTemp = this.datas;
                if (this.datasEnd <= datasTemp)
                {
                    throw new IndexOutOfRangeException(Environment.GetResourceString("EventSource_DataDescriptorsOutOfRange"));
                }

                datasTemp->DataPointer = (IntPtr)this.scratch;
                this.writingScalars    = true;
            }
        }
Пример #10
0
        public void BeginBufferedArray()
        {
            if (this.bufferedArrayFieldCount >= 0)
            {
#if PROJECTN
                throw new NotSupportedException(SR.GetResourceString("EventSource_NotSupportedNestedArraysEnums", null));
#else
                throw new NotSupportedException(Environment.GetResourceString("EventSource_NotSupportedNestedArraysEnums"));
#endif
            }

            this.bufferedArrayFieldCount = 0;
            this.impl.BeginBuffered();
        }
Пример #11
0
        /// <summary>
        /// Adds a custom-serialized field to an event.
        /// </summary>
        /// <param name="name">
        /// The name to use for the added field. This value must not be null.
        /// </param>
        /// <param name="type">The encoding type for the field.</param>
        /// <param name="metadata">Additional information needed to decode the field, if any.</param>
        public void AddCustom(string name, TraceLoggingDataType type, byte[] metadata)
        {
            if (this.BeginningBufferedArray)
            {
                throw new NotSupportedException(Environment.GetResourceString("EventSource_NotSupportedCustomSerializedData"));
            }

            this.impl.AddScalar(2);
            this.impl.AddNonscalar();
            this.AddField(new FieldMetadata(
                              name,
                              type,
                              this.Tags,
                              metadata));
        }
Пример #12
0
        private void InitializeProviderMetadata()
        {
            if (m_traits != null)
            {
                List <byte> traitMetaData = new List <byte>(100);
                for (int i = 0; i < m_traits.Length - 1; i += 2)
                {
                    if (m_traits[i].StartsWith("ETW_"))
                    {
                        string etwTrait = m_traits[i].Substring(4);
                        byte   traitNum;
                        if (!byte.TryParse(etwTrait, out traitNum))
                        {
                            if (etwTrait == "GROUP")
                            {
                                traitNum = 1;
                            }
                            else
                            {
#if PROJECTN
                                throw new ArgumentException(SR.GetResourceString("UnknownEtwTrait", etwTrait), "traits");
#else
                                throw new ArgumentException(Environment.GetResourceString("UnknownEtwTrait", etwTrait), "traits");
#endif
                            }
                        }
                        string value  = m_traits[i + 1];
                        int    lenPos = traitMetaData.Count;
                        traitMetaData.Add(0);                                           // Emit size (to be filled in later)
                        traitMetaData.Add(0);
                        traitMetaData.Add(traitNum);                                    // Emit Trait number
                        var valueLen = AddValueToMetaData(traitMetaData, value) + 3;    // Emit the value bytes +3 accounts for 3 bytes we emited above.
                        traitMetaData[lenPos]     = unchecked ((byte)valueLen);         // Fill in size
                        traitMetaData[lenPos + 1] = unchecked ((byte)(valueLen >> 8));
                    }
                }
                providerMetadata = Statics.MetadataForString(this.Name, 0, traitMetaData.Count, 0);
                int startPos = providerMetadata.Length - traitMetaData.Count;
                foreach (var b in traitMetaData)
                {
                    providerMetadata[startPos++] = b;
                }
            }
            else
            {
                providerMetadata = Statics.MetadataForString(this.Name, 0, 0, 0);
            }
        }
Пример #13
0
 /// <summary>
 /// Returns a value 0-15 if 'c' is a hexadecimal digit.   If  it throws an argument exception.
 /// </summary>
 private static int HexDigit(char c)
 {
     if ('0' <= c && c <= '9')
     {
         return(c - '0');
     }
     if ('a' <= c)
     {
         c = unchecked ((char)(c - ('a' - 'A')));        // Convert to lower case
     }
     if ('A' <= c && c <= 'F')
     {
         return(c - 'A' + 10);
     }
     throw new ArgumentException(Environment.GetResourceString("BadHexDigit", c), "traits");
 }
Пример #14
0
        private void ScalarsBegin()
        {
            if (!this.writingScalars)
            {
                var datasTemp = this.datas;
                if (this.datasEnd <= datasTemp)
                {
#if PROJECTN
                    throw new IndexOutOfRangeException(SR.GetResourceString("EventSource_DataDescriptorsOutOfRange", null));
#else
                    throw new IndexOutOfRangeException(Environment.GetResourceString("EventSource_DataDescriptorsOutOfRange"));
#endif
                }

                datasTemp->m_Ptr    = (long)(ulong)(UIntPtr)this.scratch;
                this.writingScalars = true;
            }
        }
Пример #15
0
        /// <summary>
        /// Adds an array field to an event.
        /// </summary>
        /// <param name="name">
        /// The name to use for the added field. This value must not be null.
        /// </param>
        /// <param name="type">
        /// The type code for the added field. This must be a fixed-size type
        /// or a string type. In the case of a string type, this adds an array
        /// of characters, not an array of strings.
        /// </param>
        public void AddArray(string name, TraceLoggingDataType type)
        {
            switch ((TraceLoggingDataType)((int)type & Statics.InTypeMask))
            {
            case TraceLoggingDataType.Utf16String:
            case TraceLoggingDataType.MbcsString:
            case TraceLoggingDataType.Int8:
            case TraceLoggingDataType.UInt8:
            case TraceLoggingDataType.Int16:
            case TraceLoggingDataType.UInt16:
            case TraceLoggingDataType.Int32:
            case TraceLoggingDataType.UInt32:
            case TraceLoggingDataType.Int64:
            case TraceLoggingDataType.UInt64:
            case TraceLoggingDataType.Float:
            case TraceLoggingDataType.Double:
            case TraceLoggingDataType.Boolean32:
            case TraceLoggingDataType.Guid:
            case TraceLoggingDataType.FileTime:
            case TraceLoggingDataType.HexInt32:
            case TraceLoggingDataType.HexInt64:
            case TraceLoggingDataType.Char16:
            case TraceLoggingDataType.Char8:
                break;

            default:
                throw new ArgumentOutOfRangeException("type");
            }

            if (this.BeginningBufferedArray)
            {
#if PROJECTN
                throw new NotSupportedException(SR.GetResourceString("EventSource_NotSupportedNestedArraysEnums", null));
#else
                throw new NotSupportedException(Environment.GetResourceString("EventSource_NotSupportedNestedArraysEnums"));
#endif
            }

            this.impl.AddScalar(2);
            this.impl.AddNonscalar();
            this.AddField(new FieldMetadata(name, type, this.Tags, true));
        }
Пример #16
0
        private void PinArray(object value, int size)
        {
            var pinsTemp = this.pins;

            if (this.pinsEnd <= pinsTemp)
            {
                throw new IndexOutOfRangeException(Environment.GetResourceString("EventSource_PinArrayOutOfRange"));
            }

            var datasTemp = this.datas;

            if (this.datasEnd <= datasTemp)
            {
                throw new IndexOutOfRangeException(Environment.GetResourceString("EventSource_DataDescriptorsOutOfRange"));
            }

            this.pins  = pinsTemp + 1;
            this.datas = datasTemp + 1;

            *pinsTemp = GCHandle.Alloc(value, GCHandleType.Pinned);
            datasTemp->DataPointer = pinsTemp->AddrOfPinnedObject();
            datasTemp->m_Size      = size;
        }
Пример #17
0
        public static TraceLoggingTypeInfo <DataType> CreateDefaultTypeInfo <DataType>(
            List <Type> recursionCheck)
        {
            TraceLoggingTypeInfo result;
            var dataType = typeof(DataType);

            if (recursionCheck.Contains(dataType))
            {
                throw new NotSupportedException(Environment.GetResourceString("EventSource_RecursiveTypeDefinition"));
            }

            recursionCheck.Add(dataType);

            var eventAttrib = Statics.GetCustomAttribute <EventDataAttribute>(dataType);

            if (eventAttrib != null ||
                Statics.GetCustomAttribute <CompilerGeneratedAttribute>(dataType) != null)
            {
                var analysis = new TypeAnalysis(dataType, eventAttrib, recursionCheck);
                result = new InvokeTypeInfo <DataType>(analysis);
            }
            else if (dataType.IsArray)
            {
                var elementType = dataType.GetElementType();
                if (elementType == typeof(Boolean))
                {
                    result = new BooleanArrayTypeInfo();
                }
                else if (elementType == typeof(Byte))
                {
                    result = new ByteArrayTypeInfo();
                }
                else if (elementType == typeof(SByte))
                {
                    result = new SByteArrayTypeInfo();
                }
                else if (elementType == typeof(Int16))
                {
                    result = new Int16ArrayTypeInfo();
                }
                else if (elementType == typeof(UInt16))
                {
                    result = new UInt16ArrayTypeInfo();
                }
                else if (elementType == typeof(Int32))
                {
                    result = new Int32ArrayTypeInfo();
                }
                else if (elementType == typeof(UInt32))
                {
                    result = new UInt32ArrayTypeInfo();
                }
                else if (elementType == typeof(Int64))
                {
                    result = new Int64ArrayTypeInfo();
                }
                else if (elementType == typeof(UInt64))
                {
                    result = new UInt64ArrayTypeInfo();
                }
                else if (elementType == typeof(Char))
                {
                    result = new CharArrayTypeInfo();
                }
                else if (elementType == typeof(Double))
                {
                    result = new DoubleArrayTypeInfo();
                }
                else if (elementType == typeof(Single))
                {
                    result = new SingleArrayTypeInfo();
                }
                else if (elementType == typeof(IntPtr))
                {
                    result = new IntPtrArrayTypeInfo();
                }
                else if (elementType == typeof(UIntPtr))
                {
                    result = new UIntPtrArrayTypeInfo();
                }
                else if (elementType == typeof(Guid))
                {
                    result = new GuidArrayTypeInfo();
                }
                else
                {
                    result = (TraceLoggingTypeInfo <DataType>)CreateInstance(
                        typeof(ArrayTypeInfo <>).MakeGenericType(elementType),
                        GetTypeInfoInstance(elementType, recursionCheck));
                }
            }
            else if (Statics.IsEnum(dataType))
            {
                var underlyingType = Enum.GetUnderlyingType(dataType);
                if (underlyingType == typeof(Int32))
                {
                    result = new EnumInt32TypeInfo <DataType>();
                }
                else if (underlyingType == typeof(UInt32))
                {
                    result = new EnumUInt32TypeInfo <DataType>();
                }
                else if (underlyingType == typeof(Byte))
                {
                    result = new EnumByteTypeInfo <DataType>();
                }
                else if (underlyingType == typeof(SByte))
                {
                    result = new EnumSByteTypeInfo <DataType>();
                }
                else if (underlyingType == typeof(Int16))
                {
                    result = new EnumInt16TypeInfo <DataType>();
                }
                else if (underlyingType == typeof(UInt16))
                {
                    result = new EnumUInt16TypeInfo <DataType>();
                }
                else if (underlyingType == typeof(Int64))
                {
                    result = new EnumInt64TypeInfo <DataType>();
                }
                else if (underlyingType == typeof(UInt64))
                {
                    result = new EnumUInt64TypeInfo <DataType>();
                }
                else
                {
                    // Unexpected
                    throw new NotSupportedException(Environment.GetResourceString("EventSource_NotSupportedEnumType", dataType.Name, underlyingType.Name));
                }
            }
            else if (dataType == typeof(String))
            {
                result = new StringTypeInfo();
            }
            else if (dataType == typeof(Boolean))
            {
                result = new BooleanTypeInfo();
            }
            else if (dataType == typeof(Byte))
            {
                result = new ByteTypeInfo();
            }
            else if (dataType == typeof(SByte))
            {
                result = new SByteTypeInfo();
            }
            else if (dataType == typeof(Int16))
            {
                result = new Int16TypeInfo();
            }
            else if (dataType == typeof(UInt16))
            {
                result = new UInt16TypeInfo();
            }
            else if (dataType == typeof(Int32))
            {
                result = new Int32TypeInfo();
            }
            else if (dataType == typeof(UInt32))
            {
                result = new UInt32TypeInfo();
            }
            else if (dataType == typeof(Int64))
            {
                result = new Int64TypeInfo();
            }
            else if (dataType == typeof(UInt64))
            {
                result = new UInt64TypeInfo();
            }
            else if (dataType == typeof(Char))
            {
                result = new CharTypeInfo();
            }
            else if (dataType == typeof(Double))
            {
                result = new DoubleTypeInfo();
            }
            else if (dataType == typeof(Single))
            {
                result = new SingleTypeInfo();
            }
            else if (dataType == typeof(DateTime))
            {
                result = new DateTimeTypeInfo();
            }
            else if (dataType == typeof(Decimal))
            {
                result = new DecimalTypeInfo();
            }
            else if (dataType == typeof(IntPtr))
            {
                result = new IntPtrTypeInfo();
            }
            else if (dataType == typeof(UIntPtr))
            {
                result = new UIntPtrTypeInfo();
            }
            else if (dataType == typeof(Guid))
            {
                result = new GuidTypeInfo();
            }
            else if (dataType == typeof(TimeSpan))
            {
                result = new TimeSpanTypeInfo();
            }
            else if (dataType == typeof(DateTimeOffset))
            {
                result = new DateTimeOffsetTypeInfo();
            }
            else if (dataType == typeof(EmptyStruct))
            {
                result = new NullTypeInfo <EmptyStruct>();
            }
            else if (IsGenericMatch(dataType, typeof(KeyValuePair <,>)))
            {
                var args = GetGenericArguments(dataType);
                result = (TraceLoggingTypeInfo <DataType>)CreateInstance(
                    typeof(KeyValuePairTypeInfo <,>).MakeGenericType(args[0], args[1]),
                    recursionCheck);
            }
            else if (IsGenericMatch(dataType, typeof(Nullable <>)))
            {
                var args = GetGenericArguments(dataType);
                result = (TraceLoggingTypeInfo <DataType>)CreateInstance(
                    typeof(NullableTypeInfo <>).MakeGenericType(args[0]),
                    recursionCheck);
            }
            else
            {
                var elementType = FindEnumerableElementType(dataType);
                if (elementType != null)
                {
                    result = (TraceLoggingTypeInfo <DataType>)CreateInstance(
                        typeof(EnumerableTypeInfo <,>).MakeGenericType(dataType, elementType),
                        GetTypeInfoInstance(elementType, recursionCheck));
                }
                else
                {
                    throw new ArgumentException(Environment.GetResourceString("EventSource_NonCompliantTypeError", dataType.Name));
                }
            }

            return((TraceLoggingTypeInfo <DataType>)result);
        }
Пример #18
0
        public static TraceLoggingTypeInfo CreateDefaultTypeInfo(
            Type dataType,
            List <Type> recursionCheck)
        {
            TraceLoggingTypeInfo result;

            if (recursionCheck.Contains(dataType))
            {
#if PROJECTN
                throw new NotSupportedException(SR.GetResourceString("EventSource_RecursiveTypeDefinition", null));
#else
                throw new NotSupportedException(Environment.GetResourceString("EventSource_RecursiveTypeDefinition"));
#endif
            }

            recursionCheck.Add(dataType);

            var eventAttrib = Statics.GetCustomAttribute <EventDataAttribute>(dataType);
            if (eventAttrib != null ||
                Statics.GetCustomAttribute <CompilerGeneratedAttribute>(dataType) != null ||
                IsGenericMatch(dataType, typeof(KeyValuePair <,>)))
            {
                var analysis = new TypeAnalysis(dataType, eventAttrib, recursionCheck);
                result = new InvokeTypeInfo(dataType, analysis);
            }
            else if (dataType.IsArray)
            {
                var elementType = dataType.GetElementType();
                if (elementType == typeof(Boolean))
                {
                    result = ScalarArrayTypeInfo.Boolean();
                }
                else if (elementType == typeof(Byte))
                {
                    result = ScalarArrayTypeInfo.Byte();
                }
                else if (elementType == typeof(SByte))
                {
                    result = ScalarArrayTypeInfo.SByte();
                }
                else if (elementType == typeof(Int16))
                {
                    result = ScalarArrayTypeInfo.Int16();
                }
                else if (elementType == typeof(UInt16))
                {
                    result = ScalarArrayTypeInfo.UInt16();
                }
                else if (elementType == typeof(Int32))
                {
                    result = ScalarArrayTypeInfo.Int32();
                }
                else if (elementType == typeof(UInt32))
                {
                    result = ScalarArrayTypeInfo.UInt32();
                }
                else if (elementType == typeof(Int64))
                {
                    result = ScalarArrayTypeInfo.Int64();
                }
                else if (elementType == typeof(UInt64))
                {
                    result = ScalarArrayTypeInfo.UInt64();
                }
                else if (elementType == typeof(Char))
                {
                    result = ScalarArrayTypeInfo.Char();
                }
                else if (elementType == typeof(Double))
                {
                    result = ScalarArrayTypeInfo.Double();
                }
                else if (elementType == typeof(Single))
                {
                    result = ScalarArrayTypeInfo.Single();
                }
                else if (elementType == typeof(IntPtr))
                {
                    result = ScalarArrayTypeInfo.IntPtr();
                }
                else if (elementType == typeof(UIntPtr))
                {
                    result = ScalarArrayTypeInfo.UIntPtr();
                }
                else if (elementType == typeof(Guid))
                {
                    result = ScalarArrayTypeInfo.Guid();
                }
                else
                {
                    result = new ArrayTypeInfo(dataType, TraceLoggingTypeInfo.GetInstance(elementType, recursionCheck));
                }
            }
            else
            {
                if (Statics.IsEnum(dataType))
                {
                    dataType = Enum.GetUnderlyingType(dataType);
                }

                if (dataType == typeof(String))
                {
                    result = new StringTypeInfo();
                }
                else if (dataType == typeof(Boolean))
                {
                    result = ScalarTypeInfo.Boolean();
                }
                else if (dataType == typeof(Byte))
                {
                    result = ScalarTypeInfo.Byte();
                }
                else if (dataType == typeof(SByte))
                {
                    result = ScalarTypeInfo.SByte();
                }
                else if (dataType == typeof(Int16))
                {
                    result = ScalarTypeInfo.Int16();
                }
                else if (dataType == typeof(UInt16))
                {
                    result = ScalarTypeInfo.UInt16();
                }
                else if (dataType == typeof(Int32))
                {
                    result = ScalarTypeInfo.Int32();
                }
                else if (dataType == typeof(UInt32))
                {
                    result = ScalarTypeInfo.UInt32();
                }
                else if (dataType == typeof(Int64))
                {
                    result = ScalarTypeInfo.Int64();
                }
                else if (dataType == typeof(UInt64))
                {
                    result = ScalarTypeInfo.UInt64();
                }
                else if (dataType == typeof(Char))
                {
                    result = ScalarTypeInfo.Char();
                }
                else if (dataType == typeof(Double))
                {
                    result = ScalarTypeInfo.Double();
                }
                else if (dataType == typeof(Single))
                {
                    result = ScalarTypeInfo.Single();
                }
                else if (dataType == typeof(DateTime))
                {
                    result = new DateTimeTypeInfo();
                }
                else if (dataType == typeof(Decimal))
                {
                    result = new DecimalTypeInfo();
                }
                else if (dataType == typeof(IntPtr))
                {
                    result = ScalarTypeInfo.IntPtr();
                }
                else if (dataType == typeof(UIntPtr))
                {
                    result = ScalarTypeInfo.UIntPtr();
                }
                else if (dataType == typeof(Guid))
                {
                    result = ScalarTypeInfo.Guid();
                }
                else if (dataType == typeof(TimeSpan))
                {
                    result = new TimeSpanTypeInfo();
                }
                else if (dataType == typeof(DateTimeOffset))
                {
                    result = new DateTimeOffsetTypeInfo();
                }
                else if (dataType == typeof(EmptyStruct))
                {
                    result = new NullTypeInfo();
                }
                else if (IsGenericMatch(dataType, typeof(Nullable <>)))
                {
                    result = new NullableTypeInfo(dataType, recursionCheck);
                }
                else
                {
                    var elementType = FindEnumerableElementType(dataType);
                    if (elementType != null)
                    {
                        result = new EnumerableTypeInfo(dataType, TraceLoggingTypeInfo.GetInstance(elementType, recursionCheck));
                    }
                    else
                    {
#if PROJECTN
                        throw new ArgumentException(SR.Format("EventSource_NonCompliantTypeError", dataType.Name));
#else
                        throw new ArgumentException(Environment.GetResourceString("EventSource_NonCompliantTypeError", dataType.Name));
#endif
                    }
                }
            }

            return(result);
        }
Пример #19
0
 /// <summary>
 /// Initializes a new instance of the EventSourceException class.
 /// </summary>
 public EventSourceException() : base(Environment.GetResourceString("EventSource_ListenerWriteFailure"))
 {
 }
Пример #20
0
 internal EventSourceException(Exception innerException) : base(Environment.GetResourceString("EventSource_ListenerWriteFailure"), innerException)
 {
 }