public static IFieldBridge GuessType( string fieldName, System.Type fieldType, IFieldBridgeDefinition fieldBridgeDefinition, IDateBridgeDefinition dateBridgeDefinition ) { IFieldBridge bridge = null; if (fieldBridgeDefinition != null) { System.Type impl = fieldBridgeDefinition.Impl; try { object instance = Activator.CreateInstance(impl); if (instance is IFieldBridge) { bridge = (IFieldBridge)instance; } else if (instance is ITwoWayStringBridge) { bridge = new TwoWayString2FieldBridgeAdaptor((ITwoWayStringBridge)instance); } else if (instance is IStringBridge) { bridge = new String2FieldBridgeAdaptor((IStringBridge)instance); } if (fieldBridgeDefinition.Parameters.Count > 0 && instance is IParameterizedBridge) { ((IParameterizedBridge)instance).SetParameterValues(fieldBridgeDefinition.Parameters); } } catch (Exception e) { // TODO add classname throw new HibernateException("Unable to instantiate IFieldBridge for " + fieldName, e); } } else if (dateBridgeDefinition != null) { bridge = GetDateField(dateBridgeDefinition.Resolution); } else { // find in built-ins System.Type returnType = fieldType; if (IsNullable(returnType)) { returnType = returnType.GetGenericArguments()[0]; } builtInBridges.TryGetValue(returnType.Name, out bridge); if (bridge == null && returnType.IsEnum) { bridge = new TwoWayString2FieldBridgeAdaptor(new EnumBridge(returnType)); } } // TODO add classname if (bridge == null) { throw new HibernateException("Unable to guess IFieldBridge for " + fieldName); } return(bridge); }
public static IFieldBridge GuessType( string fieldName, System.Type fieldType, IFieldBridgeDefinition fieldBridgeDefinition, IDateBridgeDefinition dateBridgeDefinition ) { IFieldBridge bridge = null; if (fieldBridgeDefinition != null) { System.Type impl = fieldBridgeDefinition.Impl; try { object instance = Activator.CreateInstance(impl); if (instance is IFieldBridge) { bridge = (IFieldBridge) instance; } else if (instance is ITwoWayStringBridge) { bridge = new TwoWayString2FieldBridgeAdaptor((ITwoWayStringBridge) instance); } else if (instance is IStringBridge) { bridge = new String2FieldBridgeAdaptor((IStringBridge) instance); } if (fieldBridgeDefinition.Parameters.Count > 0 && instance is IParameterizedBridge) { ((IParameterizedBridge) instance).SetParameterValues(fieldBridgeDefinition.Parameters); } } catch (Exception e) { // TODO add classname throw new HibernateException("Unable to instantiate IFieldBridge for " + fieldName, e); } } else if (dateBridgeDefinition != null) { bridge = GetDateField(dateBridgeDefinition.Resolution); } else { // find in built-ins System.Type returnType = fieldType; if (IsNullable(returnType)) { returnType = returnType.GetGenericArguments()[0]; } builtInBridges.TryGetValue(returnType.Name, out bridge); if (bridge == null && returnType.IsEnum) { bridge = new TwoWayString2FieldBridgeAdaptor(new EnumBridge(returnType)); } } // TODO add classname if (bridge == null) { throw new HibernateException("Unable to guess IFieldBridge for " + fieldName); } return bridge; }
public static IFieldBridge GuessType(MemberInfo member) { IFieldBridge bridge = null; FieldBridgeAttribute bridgeAnn = AttributeUtil.GetFieldBridge(member); if (bridgeAnn != null) { System.Type impl = bridgeAnn.Impl; try { Object instance = Activator.CreateInstance(impl); if (typeof(IFieldBridge).IsAssignableFrom(impl)) bridge = (IFieldBridge) instance; else if (typeof(ITwoWayStringBridge).IsAssignableFrom(impl)) bridge = new TwoWayString2FieldBridgeAdaptor( (ITwoWayStringBridge) instance); else if (typeof(StringBridge).IsAssignableFrom(impl)) bridge = new String2FieldBridgeAdaptor((StringBridge) instance); if (bridgeAnn.Parameters.Count > 0 && typeof(IParameterizedBridge).IsAssignableFrom(impl)) ((IParameterizedBridge) instance).SetParameterValues(bridgeAnn.Parameters); } catch (Exception e) { //TODO add classname throw new HibernateException("Unable to instaniate IFieldBridge for " + member.Name, e); } } else if (AttributeUtil.IsDateBridge(member)) { Resolution resolution = AttributeUtil.GetDateBridge(member).Resolution; bridge = GetDateField(resolution); } else { //find in built-ins System.Type returnType = GetMemberType(member); if (IsNullable(returnType)) returnType = returnType.GetGenericArguments()[0]; builtInBridges.TryGetValue(returnType.Name, out bridge); if (bridge == null && returnType.IsEnum) bridge = new TwoWayString2FieldBridgeAdaptor( new EnumBridge(returnType) ); } //TODO add classname if (bridge == null) throw new HibernateException("Unable to guess IFieldBridge for " + member.Name); return bridge; }