Exemplo n.º 1
0
        /// <summary>
        /// Does the actual work of creating the converter.  Note that this does not operate lazily,
        /// it is merely called lazily.
        /// </summary>
        Converter <UnknownRecord, StdfRecord> LazyCreateConverterForType(Type type)
        {
            ILGenerator ilGenerator = null;
            Func <Converter <UnknownRecord, StdfRecord> > finalizeConverter = null;

            if (Debug)
            {
#if SILVERLIGHT
                throw new NotSupportedException(Resources.NoDebugInSilverlight);
#else
                ilGenerator = CreateNewRefEmitMethod <Converter <UnknownRecord, StdfRecord> >(string.Format("{0}Converter", type.Name), string.Format("ConvertTo{0}", type.Name), ref finalizeConverter);
#endif
            }
            else
            {
                ilGenerator = CreateNewLCGMethod <Converter <UnknownRecord, StdfRecord> >(string.Format("ConvertTo{0}", type.Name), ref finalizeConverter);
            }
            var generator = new ConverterGenerator(ilGenerator, type, _RecordsAndFields?.GetFieldsForType(type));
            {
                generator.GenerateConverter();
            }
            var converter = finalizeConverter();
            ConverterGenerated?.Invoke(ConverterType.Converter, type);
            return(converter);
        }
Exemplo n.º 2
0
        Func <StdfRecord, Endian, UnknownRecord> LazyCreateUnconverterForType(Type type)
        {
            ILGenerator ilGenerator = null;
            Func <Func <StdfRecord, Endian, UnknownRecord> > finalizeUnconverter = null;

            if (Debug)
            {
#if SILVERLIGHT
                throw new NotSupportedException(Resources.NoDebugInSilverlight);
#else
                ilGenerator = CreateNewRefEmitMethod <Func <StdfRecord, Endian, UnknownRecord> >(string.Format("{0}Unconverter", type.Name), string.Format("UnconvertFrom{0}", type.Name), ref finalizeUnconverter);
#endif
            }
            else
            {
                ilGenerator = CreateNewLCGMethod <Func <StdfRecord, Endian, UnknownRecord> >(string.Format("UnconvertFrom{0}", type.Name), ref finalizeUnconverter);
            }
            var generator = new UnconverterGenerator(ilGenerator, type);
            generator.GenerateUnconverter();
            var unconverter = finalizeUnconverter();
            ConverterGenerated?.Invoke(ConverterType.Unconverter, type);
            return(unconverter);
        }