@@ -21,15 +21,15 @@ public partial class DataMigrationManager : IDataMigrationManager
2121 private static readonly Expression < Func < MethodInfo , bool > > _createMethodExpression = m
2222 => m . Name == "Create" && m . ReturnType == typeof ( int ) || m . Name == "CreateAsync" && m . ReturnType == typeof ( Task < int > ) ;
2323
24- private static readonly Expression < Func < MethodInfo , bool > > _updateMethodExpression = m
25- => UpdateFromRegex ( ) . IsMatch ( m . Name ) && m . ReturnType == typeof ( int ) ||
26- UpdateFromAsyncRegex ( ) . IsMatch ( m . Name ) && m . ReturnType == typeof ( Task < int > ) ;
24+ // private static readonly Expression<Func<MethodInfo, bool>> _updateMethodExpression = m
25+ // => UpdateFromRegex().IsMatch(m.Name) && m.ReturnType == typeof(int) ||
26+ // UpdateFromAsyncRegex().IsMatch(m.Name) && m.ReturnType == typeof(Task<int>);
2727
2828 private static readonly Expression < Func < MethodInfo , bool > > _uninstallMethodExpression = m
2929 => m . Name == "Uninstall" && m . ReturnType == typeof ( void ) || m . Name == "UninstallAsync" && m . ReturnType == typeof ( Task ) ;
3030
3131 private static readonly Func < MethodInfo , bool > _createMethod = _createMethodExpression . Compile ( ) ;
32- private static readonly Func < MethodInfo , bool > _updateMethod = _updateMethodExpression . Compile ( ) ;
32+ // private static readonly Func<MethodInfo, bool> _updateMethod = _updateMethodExpression.Compile();
3333 private static readonly Func < MethodInfo , bool > _uninstallMethod = _uninstallMethodExpression . Compile ( ) ;
3434
3535 private readonly IEnumerable < IDataMigration > _dataMigrations ;
@@ -98,7 +98,10 @@ public async Task<IEnumerable<string>> GetFeaturesThatNeedUpdateAsync()
9898 return CreateUpgradeLookupTable ( dataMigration ) . ContainsKey ( record . Version . Value ) ;
9999 }
100100
101- return GetMethod ( dataMigration , "Create" ) != null ;
101+ return dataMigration . GetType ( )
102+ . GetMethods ( BindingFlags . Public | BindingFlags . Instance )
103+ . Where ( _createMethod )
104+ . SingleOrDefault ( ) is not null ;
102105 } ) ;
103106
104107 return outOfDateMigrations . Select ( m => _typeFeatureProvider . GetFeatureForDependency ( m . GetType ( ) ) . Id ) . ToArray ( ) ;
@@ -119,7 +122,10 @@ public async Task Uninstall(string feature)
119122 // get current version for this migration
120123 var dataMigrationRecord = await GetDataMigrationRecordAsync ( tempMigration ) ;
121124
122- var uninstallMethod = GetMethod ( migration , "Uninstall" ) ;
125+ var uninstallMethod = migration . GetType ( )
126+ . GetMethods ( BindingFlags . Public | BindingFlags . Instance )
127+ . Where ( _uninstallMethod )
128+ . SingleOrDefault ( ) ;
123129
124130 if ( uninstallMethod != null )
125131 {
@@ -217,7 +223,10 @@ private async Task UpdateAsync(string featureId)
217223 if ( current == 0 )
218224 {
219225 // Try to get a Create method.
220- var createMethod = GetMethod ( migration , "Create" ) ;
226+ var createMethod = migration . GetType ( )
227+ . GetMethods ( BindingFlags . Public | BindingFlags . Instance )
228+ . Where ( _createMethod )
229+ . SingleOrDefault ( ) ;
221230
222231 if ( createMethod == null )
223232 {
@@ -323,24 +332,9 @@ private static Tuple<int, MethodInfo> GetUpdateFromMethod(MethodInfo methodInfo)
323332 return null ;
324333 }
325334
326- /// <summary>
327- /// Returns the method from a data migration class that matches the given name if found.
328- /// </summary>
329- private static MethodInfo GetMethod ( IDataMigration dataMigration , string name )
330- {
331- var methodInfo = dataMigration . GetType ( ) . GetMethod ( name , BindingFlags . Public | BindingFlags . Instance ) ;
332-
333- if ( methodInfo is not null && ( _createMethod ( methodInfo ) || _updateMethod ( methodInfo ) || _uninstallMethod ( methodInfo ) ) )
334- {
335- return methodInfo ;
336- }
337-
338- return null ;
339- }
340-
341- [ GeneratedRegex ( @"^UpdateFrom(\d+)$" ) ]
342- private static partial Regex UpdateFromRegex ( ) ;
335+ //[GeneratedRegex(@"^UpdateFrom(\d+)$")]
336+ //private static partial Regex UpdateFromRegex();
343337
344- [ GeneratedRegex ( @"^UpdateFrom(\d+)Async$" ) ]
345- private static partial Regex UpdateFromAsyncRegex ( ) ;
338+ // [GeneratedRegex(@"^UpdateFrom(\d+)Async$")]
339+ // private static partial Regex UpdateFromAsyncRegex();
346340}
0 commit comments