Added ability to order the execution of dictionary adapter behaviors.
[castle.git] / Experiments / Attic / Generator / Castle.ActiveRecord.Generator.Components / PlainFieldInferenceService.cs
bloba67fb24af157225d52ecb8b61c621f3142da1521
1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.ActiveRecord.Generator.Components
17 using System;
18 using System.Collections;
20 using Castle.ActiveRecord.Generator.Components.Database;
23 public class PlainFieldInferenceService : IPlainFieldInferenceService
25 private INamingService _namingService;
26 private ITypeInferenceService _typeInfService;
28 public PlainFieldInferenceService(INamingService namingService, ITypeInferenceService typeInfService)
30 _namingService = namingService;
31 _typeInfService = typeInfService;
34 #region IPlainFieldInferenceService Members
36 public ActiveRecordPropertyDescriptor[] InferProperties(TableDefinition tableDef)
38 ArrayList list = new ArrayList();
40 foreach(ColumnDefinition col in tableDef.Columns)
42 if (col.ForeignKey) continue;
44 String propertyName = _namingService.CreatePropertyName(col.Name);
45 Type propertyType = _typeInfService.ConvertOleType(col.Type);
46 String colType = col.Type.ToString();
47 String colName = col.Name;
49 ActiveRecordFieldDescriptor field = null;
51 if (col.PrimaryKey)
53 field = new ActiveRecordPrimaryKeyDescriptor(
54 colName, colType, propertyName, propertyType, "Native");
56 else
58 field = new ActiveRecordFieldDescriptor(
59 colName, colType, propertyName, propertyType, col.Nullable);
62 list.Add(field);
65 return (ActiveRecordFieldDescriptor[]) list.ToArray( typeof(ActiveRecordFieldDescriptor) );
68 #endregion