Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        public static object RegisterTypeTraits <T>()
        {
            Eina.Log.Debug($"Finding TypeTraits for {typeof(T).Name}");
            object traits;
            var    type = typeof(T);

            if (IsEflObject(type))
            {
                traits = new EflObjectElementTraits <T>();
            }
            else if (IsString(type))
            {
                traits = new StringElementTraits();
            }
            else if (IsStringshare(type))
            {
                traits = new StringshareElementTraits();
            }
            else if (type.IsValueType)
            {
                if (type == typeof(int))
                {
                    traits = new IntElementTraits();
                }
                else if (type == typeof(char))
                {
                    traits = new CharElementTraits();
                }
                else if (type == typeof(long))
                {
                    traits = new LongElementTraits();
                }
                else if (type == typeof(short))
                {
                    traits = new ShortElementTraits();
                }
                else if (type == typeof(float))
                {
                    traits = new FloatElementTraits();
                }
                else if (type == typeof(double))
                {
                    traits = new DoubleElementTraits();
                }
                else if (type == typeof(byte))
                {
                    traits = new ByteElementTraits();
                }
                else
                {
                    throw new Exception("No traits registered for this type");
                }
            }
            else
            {
                throw new Exception("No traits registered for this type");
            }

            register[type] = traits;
            return(traits);
        }
Exemplo n.º 3
0
        public static object RegisterTypeTraits <T>()
        {
            Eina.Log.Debug($"Finding TypeTraits for {typeof(T).Name}");
            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.");
                }

                // No need to pass concrete as the traits class will use reflection to get the actually most
                // derived type returned.
                traits = new EflObjectElementTraits <T>();
            }
            else if (IsString(type))
            {
                traits = new StringElementTraits();
            }
            else if (IsStringshare(type))
            {
                traits = new StringshareElementTraits();
            }
            else if (type.IsValueType)
            {
                if (type == typeof(int))
                {
                    traits = new IntElementTraits();
                }
                else if (type == typeof(char))
                {
                    traits = new CharElementTraits();
                }
                else if (type == typeof(long))
                {
                    traits = new LongElementTraits();
                }
                else if (type == typeof(short))
                {
                    traits = new ShortElementTraits();
                }
                else if (type == typeof(float))
                {
                    traits = new FloatElementTraits();
                }
                else if (type == typeof(double))
                {
                    traits = new DoubleElementTraits();
                }
                else if (type == typeof(byte))
                {
                    traits = new ByteElementTraits();
                }
                else
                {
                    throw new Exception("No traits registered for this type");
                }
            }
            else
            {
                throw new Exception("No traits registered for this type");
            }

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