public static Task <IEnumerable <Type> > FindTypes(Assembly assembly, TypeClassification classification, Func <Type, bool> filter = null) { var query = new TypeQuery(classification, filter); return(_assemblies[assembly].ContinueWith(t => query.Find(t.Result))); }
/// <summary> /// Initializes a new instance of the <see cref="DocumentedType" /> class. /// </summary> /// <param name="info">The type information.</param> /// <param name="properties">The type's properties.</param> /// <param name="methods">The type's methods.</param> /// <param name="fields">The type's fields.</param> /// <param name="summary">The summary.</param> /// <param name="remarks">The remarks.</param> /// <param name="examples">The examples.</param> /// <param name="metadata">The type metadata.</param> public DocumentedType( ITypeInfo info, IEnumerable <DocumentedProperty> properties, IEnumerable <DocumentedMethod> methods, IEnumerable <DocumentedField> fields, SummaryComment summary, RemarksComment remarks, IEnumerable <ExampleComment> examples, IDocumentationMetadata metadata) : base(MemberClassification.Type, summary, remarks, examples, metadata) { Definition = info.Definition; TypeClassification = info.Definition.GetTypeClassification(); Identity = info.Identity; Properties = new List <DocumentedProperty>(properties); Fields = new List <DocumentedField>(fields); // Materialize all methods. var documentedMethods = methods as DocumentedMethod[] ?? methods.ToArray(); Constructors = new List <DocumentedMethod>(GetConstructors(documentedMethods)); Methods = new List <DocumentedMethod>(GetMethods(documentedMethods)); Operators = new List <DocumentedMethod>(GetOperators(documentedMethods)); _extensionMethods = new List <DocumentedMethod>(); }
public IEnumerable <IList <Type> > SelectLists(TypeClassification classification) { var interfaces = classification.HasFlag(TypeClassification.Interfaces); var concretes = classification.HasFlag(TypeClassification.Concretes); var abstracts = classification.HasFlag(TypeClassification.Abstracts); if (interfaces || concretes || abstracts) { if (interfaces) { yield return(Interfaces); } if (concretes) { yield return(Concretes); } if (abstracts) { yield return(Abstracts); } } else { yield return(Interfaces); yield return(Concretes); yield return(Abstracts); } }
public IEnumerable <Type> FindTypes(TypeClassification classification) { if (classification == TypeClassification.All) { return(ClosedTypes.AllTypes().Concat(OpenTypes.AllTypes())); } if (classification == TypeClassification.Interfaces) { return(allTypes(ClosedTypes.Interfaces, OpenTypes.Interfaces)); } if (classification == TypeClassification.Abstracts) { return(allTypes(ClosedTypes.Abstracts, OpenTypes.Abstracts)); } if (classification == TypeClassification.Concretes) { return(allTypes(ClosedTypes.Concretes, OpenTypes.Concretes)); } if (classification == TypeClassification.Open) { return(OpenTypes.AllTypes()); } if (classification == TypeClassification.Closed) { return(ClosedTypes.AllTypes()); } return(allTypes(selectGroups(classification).ToArray())); }
public IEnumerable<Type> FindTypes(TypeClassification classification) { if (classification == TypeClassification.All) { return ClosedTypes.AllTypes().Concat(OpenTypes.AllTypes()); } if (classification == TypeClassification.Interfaces) { return allTypes(ClosedTypes.Interfaces, OpenTypes.Interfaces); } if (classification == TypeClassification.Abstracts) { return allTypes(ClosedTypes.Abstracts, OpenTypes.Abstracts); } if (classification == TypeClassification.Concretes) { return allTypes(ClosedTypes.Concretes, OpenTypes.Concretes); } if (classification == TypeClassification.Open) { return OpenTypes.AllTypes(); } if (classification == TypeClassification.Closed) { return ClosedTypes.AllTypes(); } return allTypes(selectGroups(classification).ToArray()); }
private void Add(string typename, Type type, int typeId, int?baseTypeId, int?surrogateId, int?underlyingEnumTypeId, TypeClassification classification, IEnumerable <FieldDescription> fields) { var baseTypeDescription = baseTypeId != null ? _typeDescriptionsById[baseTypeId.Value] : null; var underlyingEnumTypeDescription = underlyingEnumTypeId != null ? _typeDescriptionsById[underlyingEnumTypeId.Value] : null; var typeDescription = TypeDescription.Create(type, typename, typeId, baseTypeDescription, underlyingEnumTypeDescription, classification, fields); AddTypeDescription(typeDescription); if (surrogateId != null) { var surrogateDescription = GetTypeDescription(surrogateId.Value); typeDescription.SurrogateType = surrogateDescription; surrogateDescription.SurrogatedType = typeDescription; } }
public static Task<IEnumerable<Type>> FindTypes(IEnumerable<Assembly> assemblies, TypeClassification classification, Func<Type, bool> filter = null) { var query = new TypeQuery(classification, filter); Task<IEnumerable<Type>>[] tasks = assemblies.Select(assem => ForAssembly(assem).ContinueWith(t => query.Find(t.Result))).ToArray(); return Task.Factory.ContinueWhenAll(tasks, results => results.SelectMany(x => x.Result)); }
public TypeReferenceNode(string name, TypeClassification classification, TypeModifiers modifiers, TypeReferenceNode inner, Token token, int tokenIndex) : base(token, tokenIndex) { Name = name; Classification = classification; Modifiers = modifiers; InnerType = inner; }
private void TryAddType(int typeId, string typeName, int?baseId, int?surrogateId, int?underlyingEnumTypeId, TypeClassification classification, TypeResolver typeResolver) { try { _nextId = Math.Max(_nextId, typeId + 1); var type = typeResolver.Resolve(typeName); Add(typeName, type, typeId, baseId, surrogateId, underlyingEnumTypeId, classification, fields: null); if (type == null) { Log.ErrorFormat("Unable to resolve '{0}' to a .NET type! Values of this type will not be readable", typeName); } } catch (BreakingChangeException) { throw; } catch (Exception e) { Log.ErrorFormat("Unable to resolve '{0}' to a .NET type! Values of this type will not be readable: {1}", typeName, e); } }
/// <summary> /// Given the name of a Hibernate type such as Decimal, Decimal(19,0) /// , Int32, or even NHibernate.Type.DecimalType, NHibernate.Type.DecimalType(19,0), /// NHibernate.Type.Int32Type, then return an instance of NHibernate.Type.IType /// </summary> /// <param name="name">The name of the type.</param> /// <returns>The instance of the IType that the string represents.</returns> /// <remarks> /// This method will return null if the name is not found in the basicNameMap. /// </remarks> public static IType Basic(string name) { string typeName; // Use the basic name (such as String or String(255)) to get the // instance of the IType object. IType returnType; if (typeByTypeOfName.TryGetValue(name, out returnType)) { return(returnType); } // if we get to here then the basic type with the length or precision/scale // combination doesn't exists - so lets figure out which one we have and // invoke the appropriate delegate TypeClassification typeClassification = GetTypeClassification(name); if (typeClassification == TypeClassification.PrecisionScale) { //precision/scale based string[] parsedName = name.Split(PrecisionScaleSplit); if (parsedName.Length < 4) { throw new ArgumentOutOfRangeException("TypeClassification.PrecisionScale", name, "It is not a valid Precision/Scale name"); } typeName = parsedName[0].Trim(); byte precision = Byte.Parse(parsedName[1].Trim()); byte scale = Byte.Parse(parsedName[2].Trim()); return(BuiltInType(typeName, precision, scale)); } else if (typeClassification == TypeClassification.Length) { //length based string[] parsedName = name.Split(LengthSplit); if (parsedName.Length < 3) { throw new ArgumentOutOfRangeException("TypeClassification.Length", name, "It is not a valid Length name"); } typeName = parsedName[0].Trim(); int length = Int32.Parse(parsedName[1].Trim()); return(BuiltInType(typeName, length)); } else { // it is not in the basicNameMap and typeByTypeOfName // nor is it a Length or Precision/Scale based type // so it must be a user defined type or something else that NHibernate // doesn't have built into it. return(null); } }
public static Task<IEnumerable<Type>> FindTypes(Assembly assembly, TypeClassification classification, Func<Type, bool> filter = null) { var query = new TypeQuery(classification, filter); return ForAssembly(assembly).ContinueWith(t => query.Find(t.Result)); }
/// <summary> /// Initializes a new instance of the <see cref="DocumentedType" /> class. /// </summary> /// <param name="info">The type information.</param> /// <param name="properties">The type's properties.</param> /// <param name="methods">The type's methods.</param> /// <param name="fields">The type's fields.</param> /// <param name="summary">The summary.</param> /// <param name="remarks">The remarks.</param> /// <param name="examples">The examples.</param> public DocumentedType( ITypeInfo info, IEnumerable<DocumentedProperty> properties, IEnumerable<DocumentedMethod> methods, IEnumerable<DocumentedField> fields, SummaryComment summary, RemarksComment remarks, IEnumerable<ExampleComment> examples, IDocumentationMetadata metadata) : base(MemberClassification.Type, summary, remarks, examples, metadata) { _definition = info.Definition; _typeClassification = info.Definition.GetTypeClassification(); _identity = info.Identity; _properties = new List<DocumentedProperty>(properties); _fields = new List<DocumentedField>(fields); // Materialize all methods. var documentedMethods = methods as DocumentedMethod[] ?? methods.ToArray(); _constructors = new List<DocumentedMethod>(GetConstructors(documentedMethods)); _methods = new List<DocumentedMethod>(GetMethods(documentedMethods)); _extensionMethods = new List<DocumentedMethod>(); _operators = new List<DocumentedMethod>(GetOperators(documentedMethods)); }
public static Task <IEnumerable <Type> > FindTypes(IEnumerable <Assembly> assemblies, TypeClassification classification, Func <Type, bool> filter = null) { var query = new TypeQuery(classification, filter); var tasks = assemblies.Select(assem => ForAssembly(assem).ContinueWith(t => query.Find(t.Result))).ToArray(); return(Task.Factory.ContinueWhenAll(tasks, results => results.SelectMany(x => x.Result))); }
//タブ描画 private void TabDraw() { string tableName = TabItems[TabIndex].Header; //Content //DataTable初期化 var table = new DataTable(); //List<PRAGMAModel> var allColumns = DBOperation.AllColumns(SelectedPath, tableName, true); //DataTableのColumns foreach (var v in allColumns) { var t = TypeClassification.Judge(v.Type); table.Columns.Add(v.Name, t); } //テーブル全レコード var allRecords = DBOperation.AllRecords(SelectedPath, tableName); foreach (var v1 in allRecords) { var row = table.NewRow(); //DapperRowオブジェクトをキャスト var data = (IDictionary <string, object>)v1; var n = 0; foreach (var v2 in allColumns) { if (data[v2.Name] != null) { //改行削除 data[v2.Name] = data[v2.Name].ToString().Replace("\r", "").Replace("\n", ""); //長文を短くする int len = data[v2.Name].ToString().Length; if (len > 50) { data[v2.Name] = data[v2.Name].ToString().Substring(0, 50) + "…"; } row[n] = data[v2.Name]; } else { row[n] = DBNull.Value; } n++; } table.Rows.Add(row); } TabItems[TabIndex].Content = table; }
private TypeClassification ComputeClassification() { TypeClassification classification = TypeClassification.Computed; if (IsCustomAttributeDefined(Utf8Constants.SystemRuntimeCompilerServices, Utf8Constants.IsByRefLikeAttribute)) { classification |= TypeClassification.IsByRefLike; } return(classification); }
public void Dispose() { Log.Dispose(); TypeDiscovery.Dispose(); DelegateDiscovery.Dispose(); DelegateDiscoveryGrouped.Dispose(); DelegateClassification.Dispose(); DelegateMethods.Dispose(); TypeClassification.Dispose(); CustomMethodDiscovery.Dispose(); Error.Dispose(); }
public static Task <IEnumerable <Type> > FindTypes(Assembly assembly, TypeClassification classification, Func <Type, bool> filter = null) { if (assembly == null) { return(Task.FromResult((IEnumerable <Type>) new Type[0])); } var query = new TypeQuery(classification, filter); return(ForAssembly(assembly).ContinueWith(t => query.Find(t.Result))); }
public static IHtmlString TypeClassificationName(this HtmlHelper helper, TypeClassification classification) { switch (classification) { case TypeClassification.Class: return MvcHtmlString.Create("Class"); case TypeClassification.Enum: return MvcHtmlString.Create("Enumeration"); case TypeClassification.Interface: return MvcHtmlString.Create("Interface"); case TypeClassification.Struct: return MvcHtmlString.Create("Struct"); default: return MvcHtmlString.Create("Unknown"); } }
public static TypeDescription Create(Type type, string typename, int typeId, TypeDescription baseTypeDescription, TypeDescription underlyingEnumTypeDescription, TypeClassification classification, IEnumerable <FieldDescription> fields) { return(new TypeDescription(type, typename, typeId, baseTypeDescription, underlyingEnumTypeDescription, classification, fields)); }
private static LevelType GetLevelTypeFromClass(TypeClassification cls) { switch (cls) { case TypeClassification.Dictionary: return(LevelType.Dictionary); case TypeClassification.Collection: return(LevelType.Collection); case TypeClassification.Complex: return(LevelType.Single); default: return(LevelType.Value); } }
public IEnumerable<IList<Type>> SelectLists(TypeClassification classification) { var interfaces = classification.HasFlag(TypeClassification.Interfaces); var concretes = classification.HasFlag(TypeClassification.Concretes); var abstracts = classification.HasFlag(TypeClassification.Abstracts); if (interfaces || concretes || abstracts) { if (interfaces) yield return Interfaces; if (concretes) yield return Concretes; if (abstracts) yield return Abstracts; } else { yield return Interfaces; yield return Concretes; yield return Abstracts; } }
private IEnumerable <AssemblyShelf> selectShelves(TypeClassification classification) { var open = classification.HasFlag(TypeClassification.Open); var closed = classification.HasFlag(TypeClassification.Closed); if ((open && closed) || (!open && !closed)) { yield return(OpenTypes); yield return(ClosedTypes); } else if (open) { yield return(OpenTypes); } else if (closed) { yield return(ClosedTypes); } }
private TypeDescription(string name, string @namespace, string fullTypeName, Type resolvedType, int typeId, TypeDescription baseType, TypeDescription underlyingEnumTypeDescription, TypeClassification classification, IReadOnlyList <FieldDescription> fields) { Name = name; Namespace = @namespace; FullTypeName = fullTypeName; ResolvedType = resolvedType; TypeId = typeId; BaseType = baseType; _fields = fields.ToList(); Classification = classification; UnderlyingEnumTypeDescription = underlyingEnumTypeDescription; }
IEnumerable <AssemblyTypeList> SelectLists(TypeClassification classification) { var open = classification.HasFlag(TypeClassification.Open); var closed = classification.HasFlag(TypeClassification.Closed); if ((open && closed) || (!open && !closed)) { yield return(OpenTypes); yield return(ClosedTypes); } else if (open) { yield return(OpenTypes); } else if (closed) { yield return(ClosedTypes); } }
public static IHtmlString TypeClassificationName(this HtmlHelper helper, TypeClassification classification) { switch (classification) { case TypeClassification.Class: return(MvcHtmlString.Create("Class")); case TypeClassification.Enum: return(MvcHtmlString.Create("Enumeration")); case TypeClassification.Interface: return(MvcHtmlString.Create("Interface")); case TypeClassification.Struct: return(MvcHtmlString.Create("Struct")); default: return(MvcHtmlString.Create("Unknown")); } }
private TypeDescription(Type resolvedType, string typename, int typeId, TypeDescription baseTypeDescription, TypeDescription underlyingEnumTypeDescription, TypeClassification classification, IEnumerable <FieldDescription> fields) { ResolvedType = resolvedType; TypeId = typeId; var idx = typename.LastIndexOf(".", StringComparison.InvariantCulture); Namespace = typename.Substring(startIndex: 0, length: idx); Name = typename.Substring(idx + 1); FullTypeName = typename; Classification = classification; BaseType = baseTypeDescription; UnderlyingEnumTypeDescription = underlyingEnumTypeDescription; _fields = fields?.ToList() ?? new List <FieldDescription>(); }
/// <summary> /// Initializes a new instance of the <see cref="DocumentedType" /> class. /// </summary> /// <param name="info">The type information.</param> /// <param name="properties">The type's properties.</param> /// <param name="methods">The type's methods.</param> /// <param name="fields">The type's fields.</param> /// <param name="summary">The summary.</param> /// <param name="remarks">The remarks.</param> /// <param name="example">The example.</param> public DocumentedType( ITypeInfo info, IEnumerable <DocumentedProperty> properties, IEnumerable <DocumentedMethod> methods, IEnumerable <DocumentedField> fields, SummaryComment summary, RemarksComment remarks, ExampleComment example) : base(MemberClassification.Type, summary, remarks, example) { _definition = info.Definition; _typeClassification = info.Definition.GetTypeClassification(); _identity = info.Identity; _properties = new List <DocumentedProperty>(properties); _fields = new List <DocumentedField>(fields); // Materialize all methods. var documentedMethods = methods as DocumentedMethod[] ?? methods.ToArray(); _constructors = new List <DocumentedMethod>(GetConstructors(documentedMethods)); _methods = new List <DocumentedMethod>(GetMethods(documentedMethods)); _operators = new List <DocumentedMethod>(GetOperators(documentedMethods)); }
public TypeSubscriber(TypeClassification classification, string dataType) { this.TypeClassification = classification; this.DataType = dataType; }
public ObjectSubscriber(TypeClassification classification, string type, string id) { this.TypeClassification = classification; this.DataType = type; this.Id = id; }
private IEnumerable<IList<Type>> selectGroups(TypeClassification classification) { return selectShelves(classification).SelectMany(x => x.SelectLists(classification)); }
IEnumerable<AssemblyTypeList> SelectLists(TypeClassification classification) { var open = classification.HasFlag(TypeClassification.Open); var closed = classification.HasFlag(TypeClassification.Closed); if ((open && closed) || (!open && !closed)) { yield return OpenTypes; yield return ClosedTypes; } else if (open) { yield return OpenTypes; } else if (closed) { yield return ClosedTypes; } }
private IEnumerable<AssemblyShelf> selectShelves(TypeClassification classification) { var open = classification.HasFlag(TypeClassification.Open); var closed = classification.HasFlag(TypeClassification.Closed); if ((open && closed) || (!open && !closed)) { yield return OpenTypes; yield return ClosedTypes; } else if (open) { yield return OpenTypes; } else if (closed) { yield return ClosedTypes; } }
public TypeQuery(TypeClassification classification, Func<Type, bool> filter = null) { Filter = filter ?? (t => true); _classification = classification; }
/// <summary> /// Find any types in this TypeSet that match any combination of the TypeClassification enumeration values /// </summary> /// <param name="classification"></param> /// <returns></returns> public IEnumerable<Type> FindTypes(TypeClassification classification) { IEnumerable<Type> types = _allTypes.SelectMany(x => x.FindTypes(classification)); return _filter == null ? types : types.Where(_filter); }
/// <summary> /// Find any types in this TypeSet that match any combination of the TypeClassification enumeration values /// </summary> /// <param name="classification"></param> /// <returns></returns> public IEnumerable <Type> FindTypes(TypeClassification classification) { return(_allTypes.SelectMany(x => x.FindTypes(classification)).Where(_filter).ToArray()); }
IEnumerable<IList<Type>> SelectGroups(TypeClassification classification) { return SelectLists(classification).SelectMany(x => x.SelectTypes(classification)); }
/// <summary> /// Find any types in this TypeSet that match any combination of the TypeClassification enumeration values /// </summary> /// <param name="classification"></param> /// <returns></returns> public IEnumerable<Type> FindTypes(TypeClassification classification) { return _allTypes.SelectMany(x => x.FindTypes(classification)).Where(_filter).ToArray(); }
private IEnumerable <IList <Type> > selectGroups(TypeClassification classification) { return(selectShelves(classification).SelectMany(x => x.SelectLists(classification))); }
/// <summary> /// Uses heuristics to deduce a NHibernate type given a string naming the /// type. /// </summary> /// <param name="typeName"></param> /// <returns>An instance of <c>NHibernate.Type.IType</c></returns> /// <remarks> /// When looking for the NHibernate type it will look in the cache of the Basic types first. /// If it doesn't find it in the cache then it uses the typeName to get a reference to the /// Class (Type in .NET). Once we get the reference to the .NET class we check to see if it /// implements IType, ICompositeUserType, IUserType, ILifecycle (Association), or /// IPersistentEnum. If none of those are implemented then we will serialize the Type to the /// database using NHibernate.Type.SerializableType(typeName) /// </remarks> public static IType HeuristicType(string typeName) { IType type = TypeFactory.Basic(typeName); if (type == null) { string[] parsedTypeName; TypeClassification typeClassification = GetTypeClassification(typeName); if (typeClassification == TypeClassification.Length) { parsedTypeName = typeName.Split(lengthSplit); } else if (typeClassification == TypeClassification.PrecisionScale) { parsedTypeName = typeName.Split(precisionScaleSplit); } else { parsedTypeName = new string[] { typeName }; } System.Type typeClass; try { typeClass = ReflectHelper.ClassForName(parsedTypeName[0]); //typeName); } catch (Exception) { typeClass = null; } if (typeClass != null) { if (typeof(IType).IsAssignableFrom(typeClass)) { try { type = ( IType )Activator.CreateInstance(typeClass); } catch (Exception e) { throw new MappingException("Could not instantiate IType " + typeClass.Name + ": " + e, e); } } else if (typeof(ICompositeUserType).IsAssignableFrom(typeClass)) { type = new CompositeCustomType(typeClass); } else if (typeof(IUserType).IsAssignableFrom(typeClass)) { type = new CustomType(typeClass); } else if (typeof(ILifecycle).IsAssignableFrom(typeClass)) { type = NHibernateUtil.Entity(typeClass); } else if (typeClass.IsEnum) { type = NHibernateUtil.Enum(typeClass); } else if (typeClass.IsSerializable) { if (typeClassification == TypeClassification.Length) { type = GetSerializableType(typeClass, Int32.Parse(parsedTypeName[1])); } else { type = GetSerializableType(typeClass); } } } } return(type); }
IEnumerable <IList <Type> > SelectGroups(TypeClassification classification) { return(SelectLists(classification).SelectMany(x => x.SelectTypes(classification))); }
/// <summary> /// Find any types in this TypeSet that match any combination of the TypeClassification enumeration values /// </summary> /// <param name="classification"></param> /// <returns></returns> public IEnumerable <Type> FindTypes(TypeClassification classification) { IEnumerable <Type> types = _allTypes.SelectMany(x => x.FindTypes(classification)); return(_filter == null ? types : types.Where(_filter)); }
public TypeQuery(TypeClassification classification, Func <Type, bool> filter = null) { Filter = filter ?? (t => true); _classification = classification; }
/// <summary> /// Given the name of a Hibernate type such as Decimal, Decimal(19,0), /// Int32, or even NHibernate.Type.DecimalType, NHibernate.Type.DecimalType(19,0), /// NHibernate.Type.Int32Type, then return an instance of NHibernate.Type.IType /// </summary> /// <param name="name">The name of the type.</param> /// <param name="parameters">The parameters for the type, if any.</param> /// <returns>The instance of the IType that the string represents.</returns> /// <remarks> /// This method will return null if the name is not found in the basicNameMap. /// </remarks> public static IType Basic(string name, IDictionary <string, string> parameters) { string typeName; // Use the basic name (such as String or String(255)) to get the // instance of the IType object. IType returnType; if (typeByTypeOfName.TryGetValue(name, out returnType)) { if (_obsoleteMessageByAlias.TryGetValue(name, out string obsoleteMessage)) { _log.Warn("{0} is obsolete. {1}", name, obsoleteMessage); } if (parameters?.Count > 0 && returnType is IParameterizedType) { // The type is parameterized, must apply the parameters to a new instance of the type. // Some built-in types have internal default constructor like StringType, so we need to // allow non-public constructors. returnType = (IType)Activator.CreateInstance(returnType.GetType(), true); InjectParameters(returnType, parameters); } return(returnType); } // if we get to here then the basic type with the length or precision/scale // combination doesn't exists - so lets figure out which one we have and // invoke the appropriate delegate TypeClassification typeClassification = GetTypeClassification(name); if (typeClassification == TypeClassification.PrecisionScale) { //precision/scale based string[] parsedName = name.Split(PrecisionScaleSplit); if (parsedName.Length < 4) { throw new ArgumentOutOfRangeException( "TypeClassification.PrecisionScale", name, "It is not a valid Precision/Scale name"); } typeName = parsedName[0].Trim(); byte precision = Byte.Parse(parsedName[1].Trim()); byte scale = Byte.Parse(parsedName[2].Trim()); returnType = BuiltInType(typeName, precision, scale); } else if (typeClassification == TypeClassification.LengthOrScale) { //length or scale based string[] parsedName = name.Split(LengthSplit); if (parsedName.Length < 3) { throw new ArgumentOutOfRangeException( "TypeClassification.LengthOrScale", name, "It is not a valid Length or Scale name"); } typeName = parsedName[0].Trim(); int length = Int32.Parse(parsedName[1].Trim()); returnType = BuiltInType(typeName, length); } else { // it is not in the basicNameMap and typeByTypeOfName // nor is it a Length or Precision/Scale based type // so it must be a user defined type or something else that NHibernate // doesn't have built into it. return(null); } InjectParameters(returnType, parameters); return(returnType); }
/// <summary> /// Uses heuristics to deduce a NHibernate type given a string naming the type. /// </summary> /// <param name="typeName">the type name</param> /// <param name="parameters">parameters for the type</param> /// <param name="length">optionally, the size of the type</param> /// <returns></returns> public static IType HeuristicType(string typeName, IDictionary <string, string> parameters, int?length) { IType type = Basic(typeName); if (type != null) { return(type); } string[] parsedTypeName; TypeClassification typeClassification = GetTypeClassification(typeName); if (typeClassification == TypeClassification.Length) { parsedTypeName = typeName.Split(LengthSplit); } else { parsedTypeName = typeClassification == TypeClassification.PrecisionScale ? typeName.Split(PrecisionScaleSplit) : new[] { typeName } }; System.Type typeClass; try { typeClass = ReflectHelper.ClassForName(parsedTypeName[0]); //typeName); } catch (Exception) { typeClass = null; } if (typeClass == null) { return(null); } if (typeof(IType).IsAssignableFrom(typeClass)) { try { type = (IType)Cfg.Environment.BytecodeProvider.ObjectsFactory.CreateInstance(typeClass); } catch (Exception e) { throw new MappingException("Could not instantiate IType " + typeClass.Name + ": " + e, e); } InjectParameters(type, parameters); return(type); } if (typeof(ICompositeUserType).IsAssignableFrom(typeClass)) { return(new CompositeCustomType(typeClass, parameters)); } if (typeof(IUserType).IsAssignableFrom(typeClass)) { return(new CustomType(typeClass, parameters)); } if (typeof(ILifecycle).IsAssignableFrom(typeClass)) { return(NHibernateUtil.Entity(typeClass)); } var unwrapped = typeClass.UnwrapIfNullable(); if (unwrapped.IsEnum) { return((IType)Activator.CreateInstance(typeof(EnumType <>).MakeGenericType(unwrapped))); } if (!typeClass.IsSerializable) { return(null); } if (typeClassification == TypeClassification.Length) { return(GetSerializableType(typeClass, Int32.Parse(parsedTypeName[1]))); } if (length.HasValue) { return(GetSerializableType(typeClass, length.Value)); } return(GetSerializableType(typeClass)); }
/// <summary> /// Given the name of a Hibernate type such as Decimal, Decimal(19,0) /// , Int32, or even NHibernate.Type.DecimalType, NHibernate.Type.DecimalType(19,0), /// NHibernate.Type.Int32Type, then return an instance of NHibernate.Type.IType /// </summary> /// <param name="name">The name of the type.</param> /// <returns>The instance of the IType that the string represents.</returns> /// <remarks> /// This method will return null if the name is not found in the basicNameMap. /// </remarks> public static IType Basic(string name) { string typeName = String.Empty; // Use the basic name (such as String or String(255)) to get the // instance of the IType object. IType returnType = null; returnType = ( IType )typeByTypeOfName[name]; if (returnType != null) { return(returnType); } // if we get to here then the basic type with the length or precision/scale // combination doesn't exists - so lets figure out which one we have and // invoke the appropriate delegate TypeClassification typeClassification = GetTypeClassification(name); if (typeClassification == TypeClassification.PrecisionScale) { //precision/scale based GetNullableTypeWithPrecision precisionDelegate; byte precision; byte scale; string[] parsedName = name.Split(precisionScaleSplit); if (parsedName.Length < 4) { throw new ApplicationException("The name " + name + " is not a valid Precision/Scale name"); } typeName = parsedName[0].Trim(); precision = Byte.Parse(parsedName[1].Trim()); scale = Byte.Parse(parsedName[2].Trim()); if (getTypeDelegatesWithPrecision.ContainsKey(typeName) == false) { return(null); } precisionDelegate = ( GetNullableTypeWithPrecision )getTypeDelegatesWithPrecision[typeName]; return(precisionDelegate(precision, scale)); } else if (typeClassification == TypeClassification.Length) { //length based GetNullableTypeWithLength lengthDelegate; int length; string[] parsedName = name.Split(lengthSplit); if (parsedName.Length < 3) { throw new ApplicationException("The name " + name + " is not a valid Length name"); } typeName = parsedName[0].Trim(); length = Int32.Parse(parsedName[1].Trim()); if (getTypeDelegatesWithLength.ContainsKey(typeName) == false) // we were not able to find a delegate to get the Type { return(null); } lengthDelegate = ( GetNullableTypeWithLength )getTypeDelegatesWithLength[typeName]; return(lengthDelegate(length)); } else { // it is not in the basicNameMap and typeByTypeOfName // nor is it a Length or Precision/Scale based type // so it must be a user defined type or something else that NHibernate // doesn't have built into it. return(null); } }