Ejemplo n.º 1
0
        private static unsafe void GenerateMetadataForProperty(PropertyAnalysis property, byte *pMetadataBlob, ref uint offset, uint blobSize)
        {
            Debug.Assert(property != null);
            Debug.Assert(pMetadataBlob != null);

            // Check if this property is a nested struct.
            InvokeTypeInfo invokeTypeInfo = property.typeInfo as InvokeTypeInfo;

            if (invokeTypeInfo != null)
            {
                // Each nested struct is serialized as:
                //     TypeCode.Object              : 4 bytes
                //     Number of properties         : 4 bytes
                //     Property description 0...N
                //     Nested struct property name  : NULL-terminated string.
                EventPipeMetadataGenerator.WriteToBuffer(pMetadataBlob, blobSize, ref offset, (uint)TypeCode.Object);

                // Get the set of properties to be serialized.
                PropertyAnalysis[] properties = invokeTypeInfo.properties;
                if (properties != null)
                {
                    // Write the count of serializable properties.
                    EventPipeMetadataGenerator.WriteToBuffer(pMetadataBlob, blobSize, ref offset, (uint)properties.Length);

                    foreach (PropertyAnalysis prop in properties)
                    {
                        GenerateMetadataForProperty(prop, pMetadataBlob, ref offset, blobSize);
                    }
                }
                else
                {
                    // This struct has zero serializable properties so we just write the property count.
                    EventPipeMetadataGenerator.WriteToBuffer(pMetadataBlob, blobSize, ref offset, (uint)0);
                }

                // Write the property name.
                fixed(char *pPropertyName = property.name)
                {
                    EventPipeMetadataGenerator.WriteToBuffer(pMetadataBlob, blobSize, ref offset, (byte *)pPropertyName, ((uint)property.name.Length + 1) * 2);
                }
            }
            else
            {
                // Each primitive type is serialized as:
                //     TypeCode : 4 bytes
                //     PropertyName : NULL-terminated string
                TypeCode typeCode = GetTypeCodeExtended(property.typeInfo.DataType);
                Debug.Assert(typeCode != TypeCode.Object);

                // Write the type code.
                EventPipeMetadataGenerator.WriteToBuffer(pMetadataBlob, blobSize, ref offset, (uint)typeCode);

                // Write the property name.
                fixed(char *pPropertyName = property.name)
                {
                    EventPipeMetadataGenerator.WriteToBuffer(pMetadataBlob, blobSize, ref offset, (byte *)pPropertyName, ((uint)property.name.Length + 1) * 2);
                }
            }
        }
Ejemplo n.º 2
0
        internal unsafe void GenerateMetadata(byte *pMetadataBlob, ref uint offset, uint blobSize)
        {
            TypeCode typeCode = GetTypeCodeExtended(ParameterType);

            if (typeCode == TypeCode.Object)
            {
                // Each nested struct is serialized as:
                //     TypeCode.Object              : 4 bytes
                //     Number of properties         : 4 bytes
                //     Property description 0...N
                //     Nested struct property name  : NULL-terminated string.
                EventPipeMetadataGenerator.WriteToBuffer(pMetadataBlob, blobSize, ref offset, (uint)TypeCode.Object);

                InvokeTypeInfo invokeTypeInfo = TypeInfo as InvokeTypeInfo;
                if (invokeTypeInfo == null)
                {
                    throw new NotSupportedException();
                }

                // Get the set of properties to be serialized.
                PropertyAnalysis[] properties = invokeTypeInfo.properties;
                if (properties != null)
                {
                    // Write the count of serializable properties.
                    EventPipeMetadataGenerator.WriteToBuffer(pMetadataBlob, blobSize, ref offset, (uint)properties.Length);

                    foreach (PropertyAnalysis prop in properties)
                    {
                        GenerateMetadataForProperty(prop, pMetadataBlob, ref offset, blobSize);
                    }
                }
                else
                {
                    // This struct has zero serializable properties so we just write the property count.
                    EventPipeMetadataGenerator.WriteToBuffer(pMetadataBlob, blobSize, ref offset, (uint)0);
                }

                // Top-level structs don't have a property name, but for simplicity we write a NULL-char to represent the name.
                EventPipeMetadataGenerator.WriteToBuffer(pMetadataBlob, blobSize, ref offset, '\0');
            }
            else
            {
                // Write parameter type.
                EventPipeMetadataGenerator.WriteToBuffer(pMetadataBlob, blobSize, ref offset, (uint)typeCode);

                // Write parameter name.
                fixed(char *pParameterName = ParameterName)
                {
                    EventPipeMetadataGenerator.WriteToBuffer(pMetadataBlob, blobSize, ref offset, (byte *)pParameterName, ((uint)ParameterName.Length + 1) * 2);
                }
            }
        }
Ejemplo n.º 3
0
        internal unsafe uint GetMetadataLength()
        {
            uint ret = 0;

            TypeCode typeCode = GetTypeCodeExtended(ParameterType);

            if (typeCode == TypeCode.Object)
            {
                InvokeTypeInfo typeInfo = TypeInfo as InvokeTypeInfo;
                if (typeInfo == null)
                {
                    throw new NotSupportedException();
                }

                // Each nested struct is serialized as:
                //     TypeCode.Object      : 4 bytes
                //     Number of properties : 4 bytes
                //     Property description 0...N
                //     Nested struct property name  : NULL-terminated string.
                ret += sizeof(uint)    // TypeCode
                       + sizeof(uint); // Property count

                // Get the set of properties to be serialized.
                PropertyAnalysis[] properties = typeInfo.properties;
                if (properties != null)
                {
                    foreach (PropertyAnalysis prop in properties)
                    {
                        ret += GetMetadataLengthForProperty(prop);
                    }
                }

                // For simplicity when writing a reader, we write a NULL char
                // after the metadata for a top-level struct (for its name) so that
                // readers don't have do special case the outer-most struct.
                ret += sizeof(char);
            }
            else
            {
                ret += (uint)(sizeof(uint) + ((ParameterName.Length + 1) * 2));
            }

            return(ret);
        }
Ejemplo n.º 4
0
        private static uint GetMetadataLengthForProperty(PropertyAnalysis property)
        {
            Debug.Assert(property != null);

            uint ret = 0;

            // Check if this property is a nested struct.
            InvokeTypeInfo invokeTypeInfo = property.typeInfo as InvokeTypeInfo;

            if (invokeTypeInfo != null)
            {
                // Each nested struct is serialized as:
                //     TypeCode.Object      : 4 bytes
                //     Number of properties : 4 bytes
                //     Property description 0...N
                //     Nested struct property name  : NULL-terminated string.
                ret += sizeof(uint)    // TypeCode
                       + sizeof(uint); // Property count

                // Get the set of properties to be serialized.
                PropertyAnalysis[] properties = invokeTypeInfo.properties;
                if (properties != null)
                {
                    foreach (PropertyAnalysis prop in properties)
                    {
                        ret += GetMetadataLengthForProperty(prop);
                    }
                }

                // Add the size of the property name.
                ret += (uint)((property.name.Length + 1) * 2);
            }
            else
            {
                ret += (uint)(sizeof(uint) + ((property.name.Length + 1) * 2));
            }

            return(ret);
        }
Ejemplo n.º 5
0
        // Token: 0x060035F1 RID: 13809 RVA: 0x000CF5C0 File Offset: 0x000CD7C0
        public static TraceLoggingTypeInfo <DataType> CreateDefaultTypeInfo <DataType>(List <Type> recursionCheck)
        {
            Type typeFromHandle = typeof(DataType);

            if (recursionCheck.Contains(typeFromHandle))
            {
                throw new NotSupportedException(Environment.GetResourceString("EventSource_RecursiveTypeDefinition"));
            }
            recursionCheck.Add(typeFromHandle);
            EventDataAttribute   customAttribute = Statics.GetCustomAttribute <EventDataAttribute>(typeFromHandle);
            TraceLoggingTypeInfo traceLoggingTypeInfo;

            if (customAttribute != null || Statics.GetCustomAttribute <CompilerGeneratedAttribute>(typeFromHandle) != null)
            {
                TypeAnalysis typeAnalysis = new TypeAnalysis(typeFromHandle, customAttribute, recursionCheck);
                traceLoggingTypeInfo = new InvokeTypeInfo <DataType>(typeAnalysis);
            }
            else if (typeFromHandle.IsArray)
            {
                Type elementType = typeFromHandle.GetElementType();
                if (elementType == typeof(bool))
                {
                    traceLoggingTypeInfo = new BooleanArrayTypeInfo();
                }
                else if (elementType == typeof(byte))
                {
                    traceLoggingTypeInfo = new ByteArrayTypeInfo();
                }
                else if (elementType == typeof(sbyte))
                {
                    traceLoggingTypeInfo = new SByteArrayTypeInfo();
                }
                else if (elementType == typeof(short))
                {
                    traceLoggingTypeInfo = new Int16ArrayTypeInfo();
                }
                else if (elementType == typeof(ushort))
                {
                    traceLoggingTypeInfo = new UInt16ArrayTypeInfo();
                }
                else if (elementType == typeof(int))
                {
                    traceLoggingTypeInfo = new Int32ArrayTypeInfo();
                }
                else if (elementType == typeof(uint))
                {
                    traceLoggingTypeInfo = new UInt32ArrayTypeInfo();
                }
                else if (elementType == typeof(long))
                {
                    traceLoggingTypeInfo = new Int64ArrayTypeInfo();
                }
                else if (elementType == typeof(ulong))
                {
                    traceLoggingTypeInfo = new UInt64ArrayTypeInfo();
                }
                else if (elementType == typeof(char))
                {
                    traceLoggingTypeInfo = new CharArrayTypeInfo();
                }
                else if (elementType == typeof(double))
                {
                    traceLoggingTypeInfo = new DoubleArrayTypeInfo();
                }
                else if (elementType == typeof(float))
                {
                    traceLoggingTypeInfo = new SingleArrayTypeInfo();
                }
                else if (elementType == typeof(IntPtr))
                {
                    traceLoggingTypeInfo = new IntPtrArrayTypeInfo();
                }
                else if (elementType == typeof(UIntPtr))
                {
                    traceLoggingTypeInfo = new UIntPtrArrayTypeInfo();
                }
                else if (elementType == typeof(Guid))
                {
                    traceLoggingTypeInfo = new GuidArrayTypeInfo();
                }
                else
                {
                    traceLoggingTypeInfo = (TraceLoggingTypeInfo <DataType>)Statics.CreateInstance(typeof(ArrayTypeInfo <>).MakeGenericType(new Type[]
                    {
                        elementType
                    }), new object[]
                    {
                        Statics.GetTypeInfoInstance(elementType, recursionCheck)
                    });
                }
            }
            else if (Statics.IsEnum(typeFromHandle))
            {
                Type underlyingType = Enum.GetUnderlyingType(typeFromHandle);
                if (underlyingType == typeof(int))
                {
                    traceLoggingTypeInfo = new EnumInt32TypeInfo <DataType>();
                }
                else if (underlyingType == typeof(uint))
                {
                    traceLoggingTypeInfo = new EnumUInt32TypeInfo <DataType>();
                }
                else if (underlyingType == typeof(byte))
                {
                    traceLoggingTypeInfo = new EnumByteTypeInfo <DataType>();
                }
                else if (underlyingType == typeof(sbyte))
                {
                    traceLoggingTypeInfo = new EnumSByteTypeInfo <DataType>();
                }
                else if (underlyingType == typeof(short))
                {
                    traceLoggingTypeInfo = new EnumInt16TypeInfo <DataType>();
                }
                else if (underlyingType == typeof(ushort))
                {
                    traceLoggingTypeInfo = new EnumUInt16TypeInfo <DataType>();
                }
                else if (underlyingType == typeof(long))
                {
                    traceLoggingTypeInfo = new EnumInt64TypeInfo <DataType>();
                }
                else
                {
                    if (!(underlyingType == typeof(ulong)))
                    {
                        throw new NotSupportedException(Environment.GetResourceString("EventSource_NotSupportedEnumType", new object[]
                        {
                            typeFromHandle.Name,
                            underlyingType.Name
                        }));
                    }
                    traceLoggingTypeInfo = new EnumUInt64TypeInfo <DataType>();
                }
            }
            else if (typeFromHandle == typeof(string))
            {
                traceLoggingTypeInfo = new StringTypeInfo();
            }
            else if (typeFromHandle == typeof(bool))
            {
                traceLoggingTypeInfo = new BooleanTypeInfo();
            }
            else if (typeFromHandle == typeof(byte))
            {
                traceLoggingTypeInfo = new ByteTypeInfo();
            }
            else if (typeFromHandle == typeof(sbyte))
            {
                traceLoggingTypeInfo = new SByteTypeInfo();
            }
            else if (typeFromHandle == typeof(short))
            {
                traceLoggingTypeInfo = new Int16TypeInfo();
            }
            else if (typeFromHandle == typeof(ushort))
            {
                traceLoggingTypeInfo = new UInt16TypeInfo();
            }
            else if (typeFromHandle == typeof(int))
            {
                traceLoggingTypeInfo = new Int32TypeInfo();
            }
            else if (typeFromHandle == typeof(uint))
            {
                traceLoggingTypeInfo = new UInt32TypeInfo();
            }
            else if (typeFromHandle == typeof(long))
            {
                traceLoggingTypeInfo = new Int64TypeInfo();
            }
            else if (typeFromHandle == typeof(ulong))
            {
                traceLoggingTypeInfo = new UInt64TypeInfo();
            }
            else if (typeFromHandle == typeof(char))
            {
                traceLoggingTypeInfo = new CharTypeInfo();
            }
            else if (typeFromHandle == typeof(double))
            {
                traceLoggingTypeInfo = new DoubleTypeInfo();
            }
            else if (typeFromHandle == typeof(float))
            {
                traceLoggingTypeInfo = new SingleTypeInfo();
            }
            else if (typeFromHandle == typeof(DateTime))
            {
                traceLoggingTypeInfo = new DateTimeTypeInfo();
            }
            else if (typeFromHandle == typeof(decimal))
            {
                traceLoggingTypeInfo = new DecimalTypeInfo();
            }
            else if (typeFromHandle == typeof(IntPtr))
            {
                traceLoggingTypeInfo = new IntPtrTypeInfo();
            }
            else if (typeFromHandle == typeof(UIntPtr))
            {
                traceLoggingTypeInfo = new UIntPtrTypeInfo();
            }
            else if (typeFromHandle == typeof(Guid))
            {
                traceLoggingTypeInfo = new GuidTypeInfo();
            }
            else if (typeFromHandle == typeof(TimeSpan))
            {
                traceLoggingTypeInfo = new TimeSpanTypeInfo();
            }
            else if (typeFromHandle == typeof(DateTimeOffset))
            {
                traceLoggingTypeInfo = new DateTimeOffsetTypeInfo();
            }
            else if (typeFromHandle == typeof(EmptyStruct))
            {
                traceLoggingTypeInfo = new NullTypeInfo <EmptyStruct>();
            }
            else if (Statics.IsGenericMatch(typeFromHandle, typeof(KeyValuePair <, >)))
            {
                Type[] genericArguments = Statics.GetGenericArguments(typeFromHandle);
                traceLoggingTypeInfo = (TraceLoggingTypeInfo <DataType>)Statics.CreateInstance(typeof(KeyValuePairTypeInfo <, >).MakeGenericType(new Type[]
                {
                    genericArguments[0],
                    genericArguments[1]
                }), new object[]
                {
                    recursionCheck
                });
            }
            else if (Statics.IsGenericMatch(typeFromHandle, typeof(Nullable <>)))
            {
                Type[] genericArguments2 = Statics.GetGenericArguments(typeFromHandle);
                traceLoggingTypeInfo = (TraceLoggingTypeInfo <DataType>)Statics.CreateInstance(typeof(NullableTypeInfo <>).MakeGenericType(new Type[]
                {
                    genericArguments2[0]
                }), new object[]
                {
                    recursionCheck
                });
            }
            else
            {
                Type type = Statics.FindEnumerableElementType(typeFromHandle);
                if (!(type != null))
                {
                    throw new ArgumentException(Environment.GetResourceString("EventSource_NonCompliantTypeError", new object[]
                    {
                        typeFromHandle.Name
                    }));
                }
                traceLoggingTypeInfo = (TraceLoggingTypeInfo <DataType>)Statics.CreateInstance(typeof(EnumerableTypeInfo <, >).MakeGenericType(new Type[]
                {
                    typeFromHandle,
                    type
                }), new object[]
                {
                    Statics.GetTypeInfoInstance(type, recursionCheck)
                });
            }
            return((TraceLoggingTypeInfo <DataType>)traceLoggingTypeInfo);
        }