internal Type GetConcreteType(ReferenceContext context, ICell cell) { var cType = context.SegmentType; if (cType != null && !cType.Type.IsAbstract) { return(cType.Type); } //use custom type resolver if there is a one which can resolve this type if (cType != null && Resolvers != null && Resolvers.Any()) { var resolver = Resolvers.FirstOrDefault(r => r.CanResolve(cType)); if (resolver != null) { return(resolver.Resolve(cType.Type, cell, context.CMapping, context.Mapping)); } } if (context.PropertyInfo != null) { var pType = context.PropertyInfo.PropertyType; pType = GetNonNullableType(pType); if (pType.IsValueType || pType == typeof(string)) { return(pType); } if (typeof(IEnumerable).IsAssignableFrom(pType)) { pType = pType.GetGenericArguments()[0]; if (pType.IsValueType || pType == typeof(string)) { return(pType); } } if (Resolvers != null && Resolvers.Any()) { var resolver = Resolvers.FirstOrDefault(r => r.CanResolve(pType)); if (resolver != null) { return(resolver.Resolve(pType, cell, context.CMapping, context.Mapping)); } } } Log.WriteLine("It wasn't possible to find a non-abstract type for table {0}, class {1}", context.CMapping.TableName, context.CMapping.Class); return(null); }
private ExpressType GetConcreteType(ReferenceContext context) { var cType = context.SegmentType; if (cType != null && !cType.Type.IsAbstract) { return(cType); } //use fallback to retrieve a non-abstract type (defined in a configuration file?) var fbTypeName = context.CMapping.FallBackConcreteType; if (context.IsRoot && !string.IsNullOrWhiteSpace(fbTypeName)) { var eType = MetaData.ExpressType(fbTypeName.ToUpper()); if (eType != null && !eType.Type.IsAbstract) { return(eType); } } //use custom type resolver if there is a one which can resolve this type if (cType != null && Resolvers != null && Resolvers.Any()) { var resolver = Resolvers.FirstOrDefault(r => r.CanResolve(cType)); if (resolver != null) { return(resolver.Resolve(cType, context, MetaData)); } } Log.WriteLine("It wasn't possible to find a non-abstract type for table {0}, class {1}", context.CMapping.TableName, context.CMapping.Class); return(null); }
private bool TripletDependenciesAreSatisfied(Settings.SettingsTriplet triplet) { return(triplet.PatternDependencies.All(d => Resolvers.Any(r => r.SatisfiesDependency(d)))); }
/// <summary> /// Determines whether this instance can resolve the specified type. /// </summary> /// <returns><c>true</c> if this instance can resolve the specified type; otherwise, <c>false</c>.</returns> /// <param name="type">Type.</param> public bool CanResolve(Type type) { return(Resolvers.Any(r => r.Key.Equals(type))); }