DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
UserTypeInfo.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 
20 using Deveel.Data.Sql;
21 
22 namespace Deveel.Data.Types {
23  public class UserTypeInfo : IObjectInfo {
24  private readonly Dictionary<string, UserTypeMember> memberNamesCache;
25  private List<UserTypeMember> members;
26 
27  public UserTypeInfo(ObjectName typeName)
28  : this(typeName, null) {
29  }
30 
31  public UserTypeInfo(ObjectName typeName, ObjectName parentType) {
32  if (typeName == null)
33  throw new ArgumentNullException("typeName");
34 
35  TypeName = typeName;
36  ParentType = parentType;
37 
38  memberNamesCache = new Dictionary<string, UserTypeMember>();
39  }
40 
41  public ObjectName TypeName { get; private set; }
42 
43  public bool IsSealed { get; set; }
44 
45  public ObjectName ParentType { get; private set; }
46 
47  public UserTypeMember this[int offset] {
48  get { return members[offset]; }
49  }
50 
51  public UserTypeMember FindMember(string name) {
52  UserTypeMember member;
53  if (!memberNamesCache.TryGetValue(name, out member)) {
54  foreach (var typeMember in members) {
55  if (typeMember.MemberName.Equals(name, StringComparison.OrdinalIgnoreCase)) {
56  memberNamesCache[typeMember.MemberName] = typeMember;
57  member = typeMember;
58  break;
59  }
60  }
61  }
62 
63  return member;
64  }
65 
66  public int IndexOfMember(string name) {
67  for (int i = 0; i < members.Count; i++) {
68  var typeMember = members[i];
69  if (typeMember.MemberName.Equals(name, StringComparison.OrdinalIgnoreCase)) {
70  return i;
71  }
72  }
73 
74  return -1;
75  }
76 
78  get { return DbObjectType.Type; }
79  }
80 
82  get { return TypeName; }
83  }
84  }
85 }
UserTypeInfo(ObjectName typeName, ObjectName parentType)
Definition: UserTypeInfo.cs:31
UserTypeMember FindMember(string name)
Definition: UserTypeInfo.cs:51
readonly Dictionary< string, UserTypeMember > memberNamesCache
Definition: UserTypeInfo.cs:24
Describes the name of an object within a database.
Definition: ObjectName.cs:44
List< UserTypeMember > members
Definition: UserTypeInfo.cs:25
UserTypeInfo(ObjectName typeName)
Definition: UserTypeInfo.cs:27
int IndexOfMember(string name)
Definition: UserTypeInfo.cs:66
DbObjectType
The kind of objects that can be handled by a database system and its managers
Definition: DbObjectType.cs:27