コード例 #1
0
        private void WriteSingleApiExtensionMethodXML(ApiExtensionMethod method, XmlWriter writer)
        {
            Document doc = new Document(writer);

            using (doc.StartElement("ApiExtension"))
            {
                writer.WriteElementString("MethodName", method.ExtendedMethod.Name);
                writer.WriteElementString("OverrideFunctionText", method.OverridingFunctionBody);
            }
        }
コード例 #2
0
        public static FunctionInfo CreateFunctionInfoFrom(ApiExtensionMethod extMethod)
        {
            MethodInfo method = extMethod.ExtendedMethod;

            string formattedCode = extMethod.OverridingFunctionBody;

            if (extMethod.HasOverride == false && string.IsNullOrEmpty(extMethod.DefaultCode) == false)
            {
                CSharpParser parser = new CSharpParser();
                parser.FormatSettings.MaintainWhitespace = false;

                string methodText = string.Format("public void {0} () {{ {1} }}", method.Name, extMethod.DefaultCode);

                var bc = parser.ParseSingleConstruct(methodText, BaseConstructType.MethodDeclaration);

                // Remove the start and end braces
                formattedCode = Utility.StandardizeLineBreaks(bc.ToString(), "\n");
                // + 1 to get past the {, +1 to remove the first line break.
                formattedCode = formattedCode.Substring(formattedCode.IndexOf('{') + 2);
                formattedCode = formattedCode.Substring(0, formattedCode.LastIndexOf('}') - 1);

                formattedCode = RemoveTabs(formattedCode);
            }

            FunctionInfo fi = new FunctionInfo(
                method.Name,
                method.ReturnType,
                formattedCode,
                true,
                SyntaxEditorHelper.ScriptLanguageTypes.CSharp,
                extMethod.Description,
                "C#",
                "Extension Methods");

            return(fi);
        }
コード例 #3
0
        private void SetPanelToMethod(MethodInfo info)
        {
            SaveCurrentFunctionInfo();

            Utility.SuspendPainting(panelContent);

            ClearPanel();

            // Try find Api Extension in the current project
            if (Project.Instance.TryGetApiExtensionFor(info, out currentExtentionMethod) == false)
            {
                currentExtentionMethod = new ApiExtensionMethod(info);
                currentExtentionMethod.DefaultCode = Project.Instance.GetDefaultFunctionBodyFor(info);
            }

            functionScreen.CurrentFunction = currentExtentionMethod.FunctionInfo;
            functionScreen.AllowOverride = true;
            functionScreen.OverrideFunctionChecked = currentExtentionMethod.HasOverride;

            functionScreen.Populate();

            panelContent.Visible = true;

            Utility.ResumePainting(panelContent);

            formUserOptionDetails.Visible = false;
        }
コード例 #4
0
 private void ClearPanel()
 {
     panelContent.Visible = false;
     currentExtentionMethod = null;
 }
コード例 #5
0
        public static FunctionInfo CreateFunctionInfoFrom(ApiExtensionMethod extMethod)
        {
            MethodInfo method = extMethod.ExtendedMethod;

            string formattedCode = extMethod.OverridingFunctionBody;

            if (extMethod.HasOverride == false && string.IsNullOrEmpty(extMethod.DefaultCode) == false)
            {
                CSharpParser parser = new CSharpParser();
                parser.FormatSettings.MaintainWhitespace = false;

                string methodText = string.Format("public void {0} () {{ {1} }}", method.Name, extMethod.DefaultCode);

                var bc = parser.ParseSingleConstruct(methodText, BaseConstructType.MethodDeclaration);

                // Remove the start and end braces
                formattedCode = Utility.StandardizeLineBreaks(bc.ToString(), "\n");
                // + 1 to get past the {, +1 to remove the first line break.
                formattedCode = formattedCode.Substring(formattedCode.IndexOf('{')+2);
                formattedCode = formattedCode.Substring(0, formattedCode.LastIndexOf('}')-1);

                formattedCode = RemoveTabs(formattedCode);
            }

            FunctionInfo fi = new FunctionInfo(
                method.Name,
                method.ReturnType,
                formattedCode,
                true,
                SyntaxEditorHelper.ScriptLanguageTypes.CSharp,
                extMethod.Description,
                "C#",
                "Extension Methods");

            return fi;
        }
コード例 #6
0
 private static object GetApiExtensionMethodName(ApiExtensionMethod method)
 {
     return method.ExtendedMethod.DeclaringType.FullName.Replace(".", "_").Replace("+", "_") + "_" + method.ExtendedMethod.Name;
 }
コード例 #7
0
        protected virtual ApiExtensionMethod ReadApiExtension(XmlNode extensionNode, Type extendedType)
        {
            NodeProcessor proc = new NodeProcessor(extensionNode);
            var methodName = proc.GetString("MethodName");
            MethodInfo method = extendedType.GetMethod(methodName);
            if (method == null)
                throw new DeserialisationException(string.Format("Cannot find method named {0} on type {1}", methodName, extendedType.FullName));

            string overrideText = proc.GetString("OverrideFunctionText");

            ApiExtensionMethod extMethod = new ApiExtensionMethod(method);
            extMethod.OverridingFunctionBody = overrideText;
            return extMethod;
        }
コード例 #8
0
ファイル: Project.cs プロジェクト: uQr/Visual-NHibernate
 public bool ContainsApiExtension(ApiExtensionMethod method)
 {
     return ApiExtensionMethods.ContainsKey(method.ExtendedMethod);
 }
コード例 #9
0
ファイル: Project.cs プロジェクト: uQr/Visual-NHibernate
        /// <summary>
        /// Returns an existing ApiExtension or creates a new one, depending on whether
        /// one has been created for that 
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public ApiExtensionMethod GetOrCreateApiExtensionFor(MethodInfo info)
        {
            ApiExtensionMethod ext;
            if (TryGetApiExtensionFor(info, out ext))
                return ext;

            ext = new ApiExtensionMethod(info);
            AddApiExtension(ext);

            return ext;
        }
コード例 #10
0
ファイル: Project.cs プロジェクト: uQr/Visual-NHibernate
 public void AddApiExtension(ApiExtensionMethod extension)
 {
     ApiExtensionMethods.Add(extension.ExtendedMethod, extension);
 }
コード例 #11
0
ファイル: Project.cs プロジェクト: uQr/Visual-NHibernate
 public bool TryGetApiExtensionFor(MethodInfo info, out ApiExtensionMethod extension)
 {
     return ApiExtensionMethods.TryGetValue(info, out extension);
 }
コード例 #12
0
ファイル: Project.cs プロジェクト: uQr/Visual-NHibernate
 public void RemoveApiExtension(ApiExtensionMethod extension)
 {
     ApiExtensionMethods.Remove(extension.ExtendedMethod);
 }
コード例 #13
0
 public void SetUp()
 {
     fileController = MockRepository.GenerateMock<IFileController>();
     ExtensionMethod = new ApiExtensionMethod(typeof(ApiExtensionTest).GetMethod("Method1"));
     ExtensionMethod.OverridingFunctionBody = "return \"<>\";"; // Testing XML Escaping
 }
コード例 #14
0
        public void SetUp()
        {
            fileController = MockRepository.GenerateMock<IFileController>();
            fileController.Stub(f => f.DirectoryExists("Folder")).Return(true);
            fileController.Stub(f => f.CanCreateFilesIn("Folder")).Return(true);

            ExtensionMethod = new ApiExtensionMethod(typeof(ApiExtensionTest).GetMethod("Method1"));
        }