Created
June 10, 2015 08:36
-
-
Save pjmagee/84ad28f56e188ae153da to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void Main() | |
| { | |
| // Write code to test your extensions here. Press F5 to compile and run. | |
| } | |
| public static class Extensions | |
| { | |
| static Extensions() | |
| { | |
| } | |
| // Write custom extension methods here. They will be available to all queries. | |
| public static void ConfigureMSharpRuntime(string file = "*.Model.dll") | |
| { | |
| var model = Path.Combine(Path.GetTempPath(), "LINQPad").AsDirectory().GetFiles(file, SearchOption.AllDirectories).WithMax(x => x.CreationTime); | |
| var assembly = Assembly.LoadFile(model.FullName); | |
| Type dataProviderFactoryType = assembly.GetType("AppData.AdoDotNetDataProviderFactory", throwOnError: true); | |
| if(Util.CurrentDataContext == null) | |
| MessageBox.Show("Select a Database connection for: {0}".FormatWith(dataProviderFactoryType.Assembly.FullName)); | |
| var factoriesField = typeof(Database).GetField("AssemblyProviderFactories", BindingFlags.NonPublic | BindingFlags.Static); | |
| var assemblyProviderFactories = (Dictionary<Assembly, IDataProviderFactory>)factoriesField.GetValue(null); | |
| var config = new DataProviderFactoryInfo | |
| { | |
| Assembly = dataProviderFactoryType.Assembly, | |
| AssemblyName = dataProviderFactoryType.Assembly.FullName, | |
| ConnectionStringKey = "AppDatabase", | |
| ConnectionString = Util.CurrentDataContext.Connection.ConnectionString, | |
| ProviderFactoryType = dataProviderFactoryType.FullName, | |
| }; | |
| var dataProviderFactory = (IDataProviderFactory)Activator.CreateInstance(dataProviderFactoryType, config); | |
| assemblyProviderFactories[dataProviderFactoryType.Assembly] = dataProviderFactory; | |
| } | |
| } | |
| // You can also define non-static classes, enums, etc. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment