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); }
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); }