csharp/1996v/Bssom.Net/Bssom.Serializer/Resolvers/MapCodeGenResolverAllowPrivate.cs

MapCodeGenResolverAllowPrivate.cs
//using System.Runtime.CompilerServices;

using System.Reflection;
using System.Reflection.Emit;
using Bssom.Serializer.Internal;
using System;

namespace Bssom.Serializer.Resolvers
{
    /// 
    /// 对实体(对象)进行动态代码生成BssomMap格式的
    /// The ensaty(object) is dynamically coded to generate  in BssomMap format
    /// 
    /// 
    /// 对对象中的所有(公开的,非公开的)的可读且可写的元素进行字段编组
    /// Field marshalling of all readable and writable elements in an object (public, non-public)
    /// 
    public sealed clast MapCodeGenResolverAllowPrivate : IFormatterResolver
    {
        internal const string ModuleName = "Bssom.Serializer.Resolvers.MapCodeGenResolverAllowPrivate";
        internal static readonly DynamicFormatterastembly Dynamicastembly;

        /// 
        /// The singleton instance that can be used.
        /// 
        public static readonly MapCodeGenResolverAllowPrivate Instance;

        static MapCodeGenResolverAllowPrivate()
        {
            Instance = new MapCodeGenResolverAllowPrivate();
            Dynamicastembly = new DynamicFormatterastembly(ModuleName);
        }

        public IBssomFormatter GetFormatter()
        {
            return FormatterCache.Formatter;
        }

        private static clast FormatterCache
        {
            public static readonly IBssomFormatter Formatter;

            static FormatterCache()
            {
                Type t = typeof(T);
                Formatter = (IBssomFormatter)Activator.CreateInstance(MapCodeGenResolverBuilder.Build(Dynamicastembly, new ObjectSerializationInfo(t, true)));
            }
        }

#if NETFRAMEWORK 
        public astemblyBuilder Save()
        {
            return Dynamicastembly.Save();
        }
#endif
    }
}