コード例 #1
0
        public static object RegisterTypeTraits <T>()
        {
            object traits;
            var    type = typeof(T);

            if (IsEflObject(type))
            {
                System.Type concrete = type;
                if (!type.Name.EndsWith("Concrete"))
                {
                    var c = type.Assembly.GetType(type.FullName + "Concrete");
                    if (c != null && type.IsAssignableFrom(c))
                    {
                        concrete = c;
                    }
                }
                traits = new EflObjectElementTraits <T>(concrete);
            }
            else if (IsString(type))
            {
                traits = new StringElementTraits <T>();
            }
            else if (type.IsValueType)
            {
                if (Marshal.SizeOf <T>() <= 4)
                {
                    traits = new Primitive32ElementTraits <T>();
                }
                else
                {
                    traits = new Primitive64ElementTraits <T>();
                }
            }
            else
            {
                throw new Exception("No traits registered for this type");
            }

            register[type] = traits;
            return(traits);
        }
コード例 #2
0
        public static object RegisterTypeTraits <T>()
        {
            object traits;
            var    type = typeof(T);

            if (IsEflObject(type))
            {
                System.Type concrete = AsEflInstantiableType(type);
                if (concrete == null || !type.IsAssignableFrom(concrete))
                {
                    throw new Exception("Failed to get a suitable concrete class for this type.");
                }
                traits = new EflObjectElementTraits <T>(concrete);
            }
            else if (IsString(type))
            {
                traits = new StringElementTraits <T>();
            }
            else if (type.IsValueType)
            {
                if (Marshal.SizeOf <T>() <= 4)
                {
                    traits = new Primitive32ElementTraits <T>();
                }
                else
                {
                    traits = new Primitive64ElementTraits <T>();
                }
            }
            else
            {
                throw new Exception("No traits registered for this type");
            }

            register[type] = traits;
            return(traits);
        }