コード例 #1
0
        private object GetValue(object value)
        {
            if (value == null)
            {
                return(null);
            }

            // Check for primitive type.

            PrimitiveTypeInfo typeInfo = PrimitiveTypeInfo.GetPrimitiveTypeInfo(value.GetType());

            if (typeInfo != null)
            {
                return(TypeClone.Clone(value));
            }

            // Check if it is instrumentable.

            IInstrumentable instrumentable = value as IInstrumentable;

            if (instrumentable != null)
            {
                InstrumentationDetails details = new InstrumentationDetails();
                instrumentable.Write(details);
                return(details);
            }

            // Return the string.

            return(value.ToString());
        }
コード例 #2
0
ファイル: EventParameter.cs プロジェクト: formist/LinkMe
        private bool WriteInstrumentableParameter(BinaryWriter writer)
        {
            // Ask it.

            IInstrumentable instrumentable = m_value as IInstrumentable;

            if (instrumentable == null)
            {
                return(false);
            }

            // Ask it to save its details.

            InstrumentationDetails details = new InstrumentationDetails();

            instrumentable.Write(details);

            // Write to a stream.

            IBinarySerializable serializable = details;
            MemoryStream        stream       = new MemoryStream();

            using (BinaryWriter valueWriter = new BinaryWriter(stream))
            {
                serializable.Write(valueWriter);
                WriteValueInfo(writer, new ClassInfo(typeof(InstrumentationDetails)), ValueFormat.LinkMeBinary);
                BinaryWriteAdaptor adaptor = new BinaryWriteAdaptor(writer);
                adaptor.Write(stream.ToArray());
            }

            return(true);
        }