DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
TypeResolveContext.cs
Go to the documentation of this file.
1 //
2 // Copyright 2010-2015 Deveel
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 using System;
18 using System.Collections.Generic;
19 using System.Linq;
20 
21 namespace Deveel.Data.Types {
22  public sealed class TypeResolveContext {
23  private Dictionary<string, DataTypeMeta> meta;
24 
25  public TypeResolveContext(SqlTypeCode typeCode)
26  : this(typeCode, typeCode.ToString().ToUpperInvariant()) {
27  }
28 
29  public TypeResolveContext(SqlTypeCode typeCode, string typeName)
30  : this(typeCode, typeName, new DataTypeMeta[0]) {
31  }
32 
33  public TypeResolveContext(SqlTypeCode typeCode, string typeName, DataTypeMeta[] meta) {
34  TypeCode = typeCode;
35  TypeName = typeName;
36 
37  this.meta = new Dictionary<string, DataTypeMeta>(StringComparer.OrdinalIgnoreCase);
38 
39  if (meta != null) {
40  foreach (var typeMeta in meta) {
41  this.meta[typeMeta.Name] = typeMeta;
42  }
43  }
44  }
45 
46  public SqlTypeCode TypeCode { get; private set; }
47 
48  public string TypeName { get; private set; }
49 
50  public bool IsPrimitive {
51  get { return PrimitiveTypes.IsPrimitive(TypeCode); }
52  }
53 
54  public bool HasAnyMeta {
55  get { return meta.Count > 0; }
56  }
57 
58  public bool HasMeta(string name) {
59  return meta.ContainsKey(name);
60  }
61 
62  public DataTypeMeta GetMeta(string name) {
63  DataTypeMeta typeMeta;
64  if (!meta.TryGetValue(name, out typeMeta))
65  return null;
66 
67  return typeMeta;
68  }
69 
70  public DataTypeMeta[] GetMeta() {
71  return meta.Values.ToArray();
72  }
73  }
74 }
Provides some helper functions for resolving and creating SqlType instances that are primitive to the...
Dictionary< string, DataTypeMeta > meta
TypeResolveContext(SqlTypeCode typeCode, string typeName, DataTypeMeta[] meta)
SqlTypeCode
Enumerates the codes of all SQL types handled by the system.
Definition: SqlTypeCode.cs:23
TypeResolveContext(SqlTypeCode typeCode, string typeName)
static bool IsPrimitive(SqlTypeCode sqlType)