public static void MakeCreator(Type type, Dictionary <Type, CreatorBase> typeCreators, string as3apidocpath, string csharpnativecodepath, string linkcodenamespace) { if (type.IsInterface) { if (!typeCreators.ContainsKey(type) && !IsSkipCreator(type)) { typeCreators.Add(type, null); typeCreators[type] = new InterfaceCreator(type, as3apidocpath, csharpnativecodepath, typeCreators, linkcodenamespace); } } else if (type.IsEnum) { if (!typeCreators.ContainsKey(type) && !IsSkipCreator(type)) { typeCreators.Add(type, null); typeCreators[type] = new EnumCreator(type, as3apidocpath, csharpnativecodepath, linkcodenamespace); } } else if (type.IsArray) { var elementtype = type.GetElementType(); if (elementtype != null) { MakeCreator(elementtype, typeCreators, as3apidocpath, csharpnativecodepath, linkcodenamespace); } } else if (type.IsClass || type.IsValueType) { if (!typeCreators.ContainsKey(type) && !IsSkipCreator(type)) { typeCreators.Add(type, null); typeCreators[type] = new ClassCreator(type, as3apidocpath, csharpnativecodepath, typeCreators, linkcodenamespace); } } }
public override void SetUp() { base.SetUp(); classCreator = new ClassCreator(new FuncHelper()); internalContainer = NewMock <IInternalContainer>(); context = GetMock <IInjectionContext>(); }
private static ClassCreator GetClassCreator(string typeName) { // get delegate from dictionary if (ClassCreators.ContainsKey(typeName)) { return(ClassCreators [typeName]); } // get the default constructor of the type Type t = Type.GetType(typeName); ConstructorInfo ctor = t.GetConstructor(new Type[0]); // create a new dynamic method that constructs and returns the type string methodName = t.Name + "Ctor"; DynamicMethod dm = new DynamicMethod(methodName, t, new Type[0], typeof(object).Module); ILGenerator lgen = dm.GetILGenerator(); lgen.Emit(OpCodes.Newobj, ctor); lgen.Emit(OpCodes.Ret); // add delegate to dictionary and return ClassCreator creator = (ClassCreator)dm.CreateDelegate(typeof(ClassCreator)); ClassCreators.Add(typeName, creator); // return a delegate to the method return(creator); }
public ContainerContext(IContainerConfiguration configuration, IClassWrapperCreator classWrapperCreator) { Configuration = configuration; ClassWrapperCreator = classWrapperCreator; ITypesHelper typesHelper = new TypesHelper(); var funcHelper = new FuncHelper(); FuncBuilder = new FuncBuilder(); var classCreator = new ClassCreator(funcHelper); var constructorSelector = new ConstructorSelector(); CreationContext = new CreationContext(classCreator, constructorSelector, classWrapperCreator); var implementationTypesCollection = new ImplementationTypesCollection(configuration.GetTypesToScan(), typesHelper); ImplementationCache = new ImplementationCache(); IAbstractionsCollection abstractionsCollection = new AbstractionsCollection(implementationTypesCollection, ImplementationCache); ImplementationConfigurationCache = new ImplementationConfigurationCache(); //l var factory = new AutoAbstractionConfigurationFactory(typesHelper, abstractionsCollection, ImplementationConfigurationCache); AbstractionConfigurationCollection = new AbstractionConfigurationCollection(factory); AbstractionConfigurationCollection.Add(typeof(IContainer), new StupidAbstractionConfiguration(new ContainerImplementationConfiguration())); }
public void CreateEntity(Table table, string nameSpace, string dir) { List <string> profiles = new List <string>(); string dataType = string.Empty; foreach (Field val in table.Fields) { if (!SqlType.DonetType.Contains(val.DataType)) { foreach (string[] vals in SqlType.TypeSet) { if (vals.Contains(val.DataType)) { dataType = vals[0]; break; } } } else { dataType = val.DataType; } profiles.Add(ClassCreator.CreateProfile(val.Name, dataType)); } ClassCreator.CreateClassFile(nameSpace, table.Name, string.Format(@"{0}\{1}.cs", dir, table.Name), profiles); }
public CompositeContainerContext(IContainerConfiguration configuration, IClassWrapperCreator classWrapperCreator, IContainerSelector containerSelector) { this.Configuration = configuration; ClassWrapperCreator = classWrapperCreator; typesHelper = new TypesHelper(); var funcHelper = new FuncHelper(); FuncBuilder = new FuncBuilder(); var classCreator = new ClassCreator(funcHelper); var constructorSelector = new ConstructorSelector(); CreationContext = new CreationContext(classCreator, constructorSelector, classWrapperCreator); var implementationTypesCollection = new ImplementationTypesCollection(configuration, typesHelper); ImplementationCache = new ImplementationCache(); abstractionsCollection = new AbstractionsCollection(implementationTypesCollection, ImplementationCache); ImplementationConfigurationCache = new ImplementationConfigurationCache(); var factory = new AutoAbstractionConfigurationFactory(typesHelper, abstractionsCollection, ImplementationConfigurationCache); compositeCollection = new CompositeCollection(new[] { new AbstractionConfigurationCollection(factory) }, containerSelector); compositeCollection.Add(typeof(IContainer), new StupidAbstractionConfiguration( new ContainerImplementationConfiguration())); }
private void BuliderModel() { StringBuilder str_Model = new StringBuilder(Environment.NewLine); ClassCreator ClassCreator = new ClassCreator(); // CSBaseClass CSBaseClass = new CSBaseClass(); foreach (TreeNode node in Home.form_Database.GetTreeView1Selected()) { foreach (var item in node.Nodes) { Column column = new Model.Column(); string data = item.ToString();//TreeNode: AdminID(uniqueidentifier,not null) data = data.Contains("TreeNode:") ? data.Replace("TreeNode:", "") : data; var str = data.Split('('); column.Name = str[0].ToString().Trim(); column.Type = StaticTool.GetColumnsType(str[1].ToString().Trim().Split(',')[0].ToString().Trim()); str_Model.Append("\t\t" + string.Format(CSBaseClass.baseAttributeTemplate, column.Type, "_" + column.Name)); str_Model.Append(string.Format(CSBaseClass.basePropertyTemplate, column.Name, column.Type, "_" + column.Name)); } } Form_Code_Area fca_business = new Form_Code_Area(str_Model.ToString(), "Model生成"); fca_business.Show(Home.Instance.dockPanel1); }
public static long MeasureC(string typeName) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); for (int i = 0; i < repetitions; i++) { ClassCreator classCreator = GetClassCreator(typeName); classCreator(); } stopwatch.Stop(); return(stopwatch.ElapsedMilliseconds); }
public static long Measure(string typeName) { Stopwatch s = new Stopwatch(); s.Start(); for (int i = 0; i < reps; i++) { ClassCreator c = GetClassCreator(typeName); var o = c(); } s.Stop(); return(s.ElapsedMilliseconds); }
private static ClassCreator GetClassCreator(string typeName) { if (ClassCreators.ContainsKey(typeName)) { return(ClassCreators[typeName]); } var t = Type.GetType(typeName); ConstructorInfo ctor = t.GetConstructor(new Type[0]); string methodName = t.Name + "Ctor"; DynamicMethod dm = new DynamicMethod(methodName, t, new Type[0], typeof(object).Module); ILGenerator lgen = dm.GetILGenerator(); lgen.Emit(OpCodes.Newobj, ctor); lgen.Emit(OpCodes.Ret); // add delegate to dictionary and return ClassCreator creator = (ClassCreator)dm.CreateDelegate(typeof(ClassCreator)); ClassCreators.Add(typeName, creator); return(creator); }
private static void Main(string[] args) { var c = new ClassCreator(); c.DumpClasses(); c.KnockoutObservables(); Console.ReadKey(); }
/// <summary> /// 方法负责: create each solution project /// </summary> /// <param name="tvTables">tree view with the data base's tables</param> /// <param name="architectureType">architecture type</param> /// <param name="dataAccessType">data access type</param> /// <param name="path">the application path</param> /// <param name="item">current project</param> /// <param name="connectionString">the connection string</param> /// <param name="nameIdTable">table with the projects (name => id)</param> /// <param name="gvProjects">grid with the solutions data</param> public void CreateProjects(TreeView tvTables, Architecture architectureType, DataAccess dataAccessType, string path, DataGridViewRow item, string connectionString, Hashtable nameIdTable, DataGridView gvProjects) { // load attributes from solutionCreator this.nameIdTable = nameIdTable; this.gvProjects = gvProjects; classCreator = new ClassCreator(gvProjects); // .csproj file content StringBuilder files = new StringBuilder(); StringBuilder mapContent = new StringBuilder(); string dllReference = String.Empty; string projReference = String.Empty; string csprojContent = String.Empty; bool baseDAOAdded = false; bool controllerAdded = false; #region files references // Creating the file references foreach (AdvancedTreeNode node in tvTables.Nodes) { if (node.Checked) { if (architectureType == Architecture.MVC) { if (Convert.ToInt32(item.Cells["ProjectType"].Value) == (int)ProjectType.MODEL) { files.Append(String.Format(CSProjBaseClass.baseFilesTemplate, node.Text + item.Cells["Suffix"].Value + ".cs")); // Data access if (dataAccessType == DataAccess.ADONET) { // Verifies if baseDAO is already added in the project if (!baseDAOAdded) { files.Append(String.Format(CSProjBaseClass.baseFilesTemplate, BASE_DAO_CLASS)); baseDAOAdded = true; } } else if (dataAccessType == DataAccess.NHIBERNATE) { // Verifies if baseDAO is already added in the project if (!baseDAOAdded) { files.Append(String.Format(CSProjBaseClass.baseFilesTemplate, NHIBERNATE_HELPER_CLASS)); baseDAOAdded = true; } // Nhibernate mapping mapContent.Append(String.Format(CSProjBaseClass.embeddedResourceTemplate, node.Text + item.Cells["Suffix"].Value + ".hbm.xml")); } else //DataAccess.LINQ { // Verifies if baseDAO is already added in the project if (!baseDAOAdded) { files.Append(String.Format(CSProjBaseClass.baseFilesTemplate, DBML_FILE)); files.Append(String.Format(CSProjBaseClass.baseFilesTemplate, BASE_DAO_CLASS)); baseDAOAdded = true; } } } else if (Convert.ToInt32(item.Cells["ProjectType"].Value) == (int)ProjectType.CONTROLLER) { // Verifies if controller is already added in the project if (!controllerAdded) { files.Append(String.Format(CSProjBaseClass.baseFilesTemplate, "Controller" + item.Cells["Suffix"].Value + ".cs")); controllerAdded = true; } } } else //Architecture.THREETIER { files.Append(String.Format(CSProjBaseClass.baseFilesTemplate, node.Text + item.Cells["Suffix"].Value + ".cs")); if (Convert.ToInt32(item.Cells["ProjectType"].Value) == (int)ProjectType.DAO) { if (dataAccessType == DataAccess.ADONET) { // Verifies if baseDAO is already added in the project if (!baseDAOAdded) { files.Append(String.Format(CSProjBaseClass.baseFilesTemplate, BASE_DAO_CLASS)); baseDAOAdded = true; } } else if (dataAccessType == DataAccess.NHIBERNATE) { // Verifies if baseDAO is already added in the project if (!baseDAOAdded) { files.Append(String.Format(CSProjBaseClass.baseFilesTemplate, NHIBERNATE_HELPER_CLASS)); baseDAOAdded = true; } // Nhibernate mapping mapContent.Append(String.Format(CSProjBaseClass.embeddedResourceTemplate, node.Text + item.Cells["Suffix"].Value + ".hbm.xml")); } else //DataAccess.LINQ { // Verifies if baseDAO is already added in the project // if (!baseDAOAdded && dataAccessType == DataAccess.LINQ) if (!baseDAOAdded) { files.Append(String.Format(CSProjBaseClass.baseFilesTemplate, DBML_FILE)); files.Append(String.Format(CSProjBaseClass.baseFilesTemplate, BASE_DAO_CLASS)); baseDAOAdded = true; } } } } } } #endregion // If architecture type is MVC if (architectureType == Architecture.MVC) { if (Convert.ToInt32(item.Cells["ProjectType"].Value) == (int)ProjectType.MODEL) { classCreator.CreateMVCModel(tvTables, path, item, dataAccessType, connectionString); projReference = ""; // Model does not have project references if (dataAccessType == DataAccess.ADONET) { dllReference = String.Format(CSProjBaseClass.baseReferenceTemplate, SYSTEM_CONFIGURATION); } else if (dataAccessType == DataAccess.NHIBERNATE) { dllReference = String.Format(CSProjBaseClass.baseReferenceTemplate, NHIBERNATE_REFERENCE); } } else if (Convert.ToInt32(item.Cells["ProjectType"].Value) == (int)ProjectType.CONTROLLER) { classCreator.CreateController(tvTables, path, item, dataAccessType); // Model projReference = String.Format(CSProjBaseClass.baseProjectReferenceTemplate, Helper.GetProjectPath(ProjectType.MODEL, gvProjects), Helper.GetProjectGUID(ProjectType.MODEL, gvProjects, nameIdTable), Helper.GetProjectName(ProjectType.MODEL, gvProjects)); } else // ProjectType.View { // Controller projReference = String.Format(CSProjBaseClass.baseProjectReferenceTemplate, Helper.GetProjectPath(ProjectType.CONTROLLER, gvProjects), Helper.GetProjectGUID(ProjectType.CONTROLLER, gvProjects, nameIdTable), Helper.GetProjectName(ProjectType.CONTROLLER, gvProjects)); } } else //ArchitectureType.THREETIER { if (Convert.ToInt32(item.Cells["ProjectType"].Value) == (int)ProjectType.MODEL) { classCreator.CreateModel(tvTables, path, item, dataAccessType); projReference = ""; // Model does not have project references } else if (Convert.ToInt32(item.Cells["ProjectType"].Value) == (int)ProjectType.BUSINESS) { classCreator.CreateBusiness(tvTables, path, item, dataAccessType); // Model projReference = String.Format(CSProjBaseClass.baseProjectReferenceTemplate, Helper.GetProjectPath(ProjectType.MODEL, gvProjects), Helper.GetProjectGUID(ProjectType.MODEL, gvProjects, nameIdTable), Helper.GetProjectName(ProjectType.MODEL, gvProjects)); // DAO projReference += String.Format(CSProjBaseClass.baseProjectReferenceTemplate, Helper.GetProjectPath(ProjectType.DAO, gvProjects), Helper.GetProjectGUID(ProjectType.DAO, gvProjects, nameIdTable), Helper.GetProjectName(ProjectType.DAO, gvProjects)); } else // ProjectType.DAO { classCreator.CreateDAO(tvTables, path, item, dataAccessType, connectionString); // Model projReference = String.Format(CSProjBaseClass.baseProjectReferenceTemplate, Helper.GetProjectPath(ProjectType.MODEL, gvProjects), Helper.GetProjectGUID(ProjectType.MODEL, gvProjects, nameIdTable), Helper.GetProjectName(ProjectType.MODEL, gvProjects)); if (dataAccessType == DataAccess.ADONET) { dllReference = String.Format(CSProjBaseClass.baseReferenceTemplate, SYSTEM_CONFIGURATION); } else if (dataAccessType == DataAccess.NHIBERNATE) { dllReference = String.Format(CSProjBaseClass.baseReferenceTemplate, NHIBERNATE_REFERENCE); } } } // .csproj file content csprojContent = String.Format(CSProjBaseClass.baseClassTemplate, nameIdTable[item.Cells["Name"].Value].ToString(), item.Cells["Namespace"].Value, item.Cells["Assembly"].Value, files.ToString(), projReference, dllReference, mapContent.ToString()); // Creating .csproj file using (StreamWriter sw = File.CreateText(path + "\\" + item.Cells["Name"].Value + "\\" + item.Cells["Name"].Value + ".csproj")) { sw.WriteLine(csprojContent); sw.Close(); } }
private static IEnumerable <Class> CreateClasses(GeneratorSettings settings, Entity entity) { ClassCreator creator = new ClassCreator(); return(creator.Create(entity)); }