Пример #1
0
        /// <summary>
        /// Adds a new method (with a hard-coded name and empty body) to the selected class.
        /// </summary>
        /// <param name="c">The class to which the method will be added.</param>
        /// <remarks>
        /// The method is added to the underlying file, but not to the designer.
        /// Visual Studio will detect the change and asks the user if the file should be reloaded.
        /// Another approach is needed to update the designer directly.
        /// </remarks>
        void AddMethodToFile(ClassItem c)
        {
            AxClass axClass = (AxClass)c.GetMetadataType();

            // Add the method to the class
            axClass.AddMethod(BuildMethod());

            // Prepare objects needed for saving
            var metaModelProviders = ServiceLocator.GetService(typeof(IMetaModelProviders)) as IMetaModelProviders;
            var metaModelService = metaModelProviders.CurrentMetaModelService;
            // Getting the model will likely have to be more sophisticated, such as getting the model of the project and checking
            // if the object has the same model.
            // But this shold do for demonstration.
            ModelInfo model = DesignMetaModelService.Instance.CurrentMetadataProvider.Classes.GetModelInfo(axClass.Name).FirstOrDefault<ModelInfo>();

            // Update the file
            metaModelService.UpdateClass(axClass, new ModelSaveInfo(model));
        }
Пример #2
0
        /// <summary>
        /// Adds a new method (with a hard-coded name and empty body) to the selected class.
        /// </summary>
        /// <param name="c">The class to which the method will be added.</param>
        /// <remarks>
        /// The method is added to the underlying file, but not to the designer.
        /// Visual Studio will detect the change and asks the user if the file should be reloaded.
        /// Another approach is needed to update the designer directly.
        /// </remarks>
        void AddMethodToFile(ClassItem c)
        {
            AxClass axClass = (AxClass)c.GetMetadataType();

            // Add the method to the class
            axClass.AddMethod(BuildMethod());

            // Prepare objects needed for saving
            var metaModelProviders = ServiceLocator.GetService(typeof(IMetaModelProviders)) as IMetaModelProviders;
            var metaModelService   = metaModelProviders.CurrentMetaModelService;
            // Getting the model will likely have to be more sophisticated, such as getting the model of the project and checking
            // if the object has the same model.
            // But this shold do for demonstration.
            ModelInfo model = DesignMetaModelService.Instance.CurrentMetadataProvider.Classes.GetModelInfo(axClass.Name).FirstOrDefault <ModelInfo>();

            // Update the file
            metaModelService.UpdateClass(axClass, new ModelSaveInfo(model));
        }