![]() |
Shadowrun: Awakened 29 September 2011 - Build 871
|
00001 using System; 00002 using System.Collections.Generic; 00003 00004 namespace RoutineAnalyzer 00005 { 00014 public abstract class RoutineBase 00015 { 00016 #region Fields 00017 00018 protected string _sql; 00019 protected string _name; 00020 protected List<RoutineParamBase> _params = new List<RoutineParamBase>(); 00021 00022 #endregion 00023 00024 #region Methods 00025 00031 public RoutineBase(string sql) 00032 { 00033 _sql = sql; 00034 ParseDeclaration(_sql); 00035 } 00036 00041 void ParseDeclaration(string declaration) 00042 { 00043 //pull out the name 00044 int startOfParams = FindName(declaration); 00045 FindAndCreateRoutineParams(declaration, startOfParams); 00046 } 00047 00053 int FindName(string declaration) 00054 { 00055 int startOfParams = declaration.IndexOf("("); 00056 _name = declaration.Substring(0, startOfParams); 00057 return startOfParams; 00058 } 00059 00065 void FindAndCreateRoutineParams(string declaration, int startOfParams) 00066 { 00067 //pull out the arguents and pass them off to create our param list 00068 int endOfParams = declaration.LastIndexOf(")"); 00069 string args = declaration.Substring(startOfParams + 1, endOfParams - startOfParams - 1); 00070 string[] allArgs = args.Split(','); 00071 for(int i=0; i<allArgs.Length; ++ i) 00072 { 00073 RoutineParamBase param = CreateRoutineParam(allArgs[i], i); 00074 _params.Add(param); 00075 } 00076 } 00077 00082 public abstract string GetDeclaration(); 00083 00088 public abstract string GetCode(); 00089 00096 protected abstract RoutineParamBase CreateRoutineParam(string sql, int index); 00097 00098 #endregion 00099 } 00100 }
Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.