@@ -8,35 +8,50 @@ namespace SQLiteAbstractCrud.Proxy
88 public class ProxyBase
99 {
1010 private Type _type ;
11- private readonly List < OriginalPropertyInfo > _originalPropertiesInfos = new ( ) ;
1211 private readonly List < ProxyPropertyInfo > _proxyPropertiesInfos = new ( ) ;
12+ private readonly List < ProxyCtorParameterInfo > _proxyCtorParametersInfos = new ( ) ;
1313
14- internal Fields Fields { get ; } = new ( ) ;
14+ internal Fields Fields ;
1515
1616 public ProxyBase ( Type type )
1717 {
1818 this . _type = type ;
19- var properties = this . _type . GetProperties ( ) . ToList ( ) ;
20-
21- int i = 0 ;
22- properties . ForEach ( x =>
23- {
24- _originalPropertiesInfos . Add ( new OriginalPropertyInfo ( i , x . Name ) ) ;
25- i ++ ;
26- } ) ;
27-
28- int j = 0 ;
29- properties . OrderBy ( x => x . Name ) . ToList ( ) . ForEach ( x =>
30- {
31- var originalOrder = _originalPropertiesInfos . First ( y => y . Name == x . Name ) . Order ;
32- _proxyPropertiesInfos . Add ( new ProxyPropertyInfo ( originalOrder , x , j ) ) ;
33- j ++ ;
34- } ) ;
35-
36- foreach ( var item in _proxyPropertiesInfos )
37- {
38- Fields . AddField ( item . OriginalName , item . CSharpType , item . IsPrimaryKey , item . IsAutoIncrement ) ;
39- }
19+
20+ var ctorParameters = _type . GetConstructors ( ) . Single ( ) . GetParameters ( ) . ToList ( ) ;
21+ ctorParameters . ForEach ( p => _proxyCtorParametersInfos . Add ( new ProxyCtorParameterInfo ( p ) ) ) ;
22+
23+ var propertiesInfos = this . _type . GetProperties ( ) . ToList ( ) ;
24+ propertiesInfos . ForEach ( p => _proxyPropertiesInfos . Add ( new ProxyPropertyInfo ( p ) ) ) ;
25+
26+ Fields = new Fields ( _proxyPropertiesInfos ) ;
27+
28+ //ctorParameters.ForEach(ctorParameter =>Fields.AddField(new Field(ctorParameter)));
29+ //foreach (var item in _proxyPropertiesInfos)
30+ //{
31+ // Fields.AddField(item.OriginalName, item.CSharpType, item.IsPrimaryKey, item.IsAutoIncrement);
32+ //}
33+
34+
35+ //var originalProperties = this._type.GetProperties().ToList();
36+
37+ //int i = 0;
38+ //originalProperties.ForEach(x =>
39+ //{
40+ // _originalPropertiesInfos.Add(new OriginalPropertyInfo(i, x.Name));
41+ // i++;
42+ //});
43+
44+ //int h = 0;
45+ //originalProperties.ForEach(originalProperty =>
46+ //{
47+ // var originalOrder = _originalPropertiesInfos.First(y => y.Name == originalProperty.Name).Order;
48+ // _proxyPropertiesInfos.Add(new ProxyPropertyInfo(originalOrder, originalProperty, h));
49+ // h++;
50+ //});
51+ //foreach (var item in _proxyPropertiesInfos)
52+ //{
53+ // Fields.AddField(item.OriginalName, item.CSharpType, item.IsPrimaryKey, item.IsAutoIncrement);
54+ //}
4055 }
4156
4257 [ Obsolete ]
@@ -65,15 +80,44 @@ public int GetFieldsCount()
6580 {
6681 return this . Fields . Items . Count ;
6782 }
83+ public int GetCtorParametersCount ( )
84+ {
85+ return this . _proxyCtorParametersInfos . Count ;
86+ }
6887
6988 public string GetFieldTypeSQLite ( int index )
7089 {
71- return this . Fields . Items [ index ] . TypeSQLite ;
90+ return this . Fields . Items [ index ] . SQLiteType ;
91+ }
92+
93+ public string GetCtorParameterSQLiteType ( int index )
94+ {
95+ return this . _proxyCtorParametersInfos [ index ] . SQLiteType ;
7296 }
7397
7498 public string GetFieldTypeCSharp ( int index )
7599 {
76100 return this . Fields . Items [ index ] . TypeCSharp ;
77101 }
102+
103+ public List < ProxyCtorParameterInfo > GetCtorParemetersInfos ( )
104+ {
105+ return this . _proxyCtorParametersInfos ;
106+ }
107+
108+ public string GetCtorParemeterCSharpType ( int index )
109+ {
110+ return this . _proxyCtorParametersInfos [ index ] . CSharpType ;
111+ }
112+
113+ public string GetTableName ( )
114+ {
115+ return _type . Name ;
116+ }
117+
118+ public bool FieldExists ( string fieldName )
119+ {
120+ return Fields . Items . Any ( x => x . NameOnDb . ToLower ( ) == fieldName . ToLower ( ) ) ;
121+ }
78122 }
79123}
0 commit comments