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);
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 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;
        }
Exemplo n.º 4
0
 private void ClearPanel()
 {
     panelContent.Visible = false;
     currentExtentionMethod = null;
 }
Exemplo n.º 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;
        }
Exemplo n.º 6
0
 private static object GetApiExtensionMethodName(ApiExtensionMethod method)
 {
     return method.ExtendedMethod.DeclaringType.FullName.Replace(".", "_").Replace("+", "_") + "_" + method.ExtendedMethod.Name;
 }
        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;
        }
Exemplo n.º 8
0
 public bool ContainsApiExtension(ApiExtensionMethod method)
 {
     return ApiExtensionMethods.ContainsKey(method.ExtendedMethod);
 }
Exemplo n.º 9
0
        /// <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;
        }
Exemplo n.º 10
0
 public void AddApiExtension(ApiExtensionMethod extension)
 {
     ApiExtensionMethods.Add(extension.ExtendedMethod, extension);
 }
Exemplo n.º 11
0
 public bool TryGetApiExtensionFor(MethodInfo info, out ApiExtensionMethod extension)
 {
     return ApiExtensionMethods.TryGetValue(info, out extension);
 }
Exemplo n.º 12
0
 public void RemoveApiExtension(ApiExtensionMethod extension)
 {
     ApiExtensionMethods.Remove(extension.ExtendedMethod);
 }
 public void SetUp()
 {
     fileController = MockRepository.GenerateMock<IFileController>();
     ExtensionMethod = new ApiExtensionMethod(typeof(ApiExtensionTest).GetMethod("Method1"));
     ExtensionMethod.OverridingFunctionBody = "return \"<>\";"; // Testing XML Escaping
 }
        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"));
        }