private void mnuHelperItemViewFunction_Click(object sender, EventArgs e) { Controller.MainForm.Cursor = Cursors.WaitCursor; TreeListNode selectedNode = treeListAPIHelper.Selection[0]; Type objectType = (Type)selectedNode.ParentNode.Tag; string methodName = selectedNode[0].ToString(); string functionName = objectType.FullName.Replace("ArchAngel.Providers.Database.", "") + "." + methodName; functionName = functionName.Replace(".", "_"); Project.FunctionInfo function = Project.Instance.FindFunction(functionName); if (function == null) { System.Reflection.MethodInfo method = objectType.GetMethod(methodName); ArchAngel.Interfaces.Attributes.ApiExtensionAttribute[] attributes = (ArchAngel.Interfaces.Attributes.ApiExtensionAttribute[])method.GetCustomAttributes(typeof(ArchAngel.Interfaces.Attributes.ApiExtensionAttribute), true); if (attributes.Length == 0) { throw new NotImplementedException(string.Format("DefaultCodeAttribute not implemented for {0}.{1} yet.", objectType.FullName, methodName)); } Type returnType = method.ReturnType; function = new Project.FunctionInfo(functionName, returnType, "XXX", false, Project.ScriptLanguageTypes.CSharp, string.Format("Override of helper function: {0}.{1}.", objectType.Name, methodName), "XXX", "Helper Overrides"); System.Reflection.ParameterInfo[] parameters = method.GetParameters(); foreach (System.Reflection.ParameterInfo parameter in parameters) { ArchAngel.Designer.Project.ParamInfo par = new Project.ParamInfo(parameter.Name, parameter.ParameterType); function.AddParameter(par); } Project.Instance.AddFunction(function); //int funcCount = Project.Instance.Functions.Length; //Project.FunctionInfo[] coll = new Project.FunctionInfo[funcCount + 1]; //coll[coll.Length - 1] = function; //Array.Copy(Project.Instance.Functions, coll, funcCount); //Project.Instance.Functions = coll; } Project.DefaultValueFunction defValFunc = Project.Instance.FindDefaultValueFunction(functionName); if (defValFunc == null) { Project.ParamInfo[] parameterTypes = new Project.ParamInfo[function.Parameters.Length]; for (int i = 0; i < function.Parameters.Length; i++) { parameterTypes[i] = new Project.ParamInfo(Slyce.Common.Utility.GetCamelCase(function.Parameters[i].Name), function.Parameters[i].DataType); } defValFunc = new Project.DefaultValueFunction(objectType, methodName, false, Project.DefaultValueFunction.FunctionTypes.HelperOverride, false); defValFunc.ParameterTypes = parameterTypes; Project.Instance.DefaultValueFunctions.Add(defValFunc); function.Body = defValFunc.GetFormattedDefaultCode(); Project.Instance.IsDirty = true; } Controller.MainForm.ShowFunction(functionName, defValFunc, false, this); Controller.MainForm.Cursor = Cursors.Default; }
/// <summary> /// /// </summary> /// <param name="parentNode"></param> /// <param name="myReferencedFile"></param> /// <param name="theirReferencedFile"></param> /// <returns>True if the referenced files were different and a node was added, false if they were the same and no node was added.</returns> private bool AddDefaultValueFunctionNode(TreeListNode parentNode, Project.DefaultValueFunction myDefaultValueFunction, Project.DefaultValueFunction theirDefaultValueFunction) { int originalNumChildNodes = parentNode.Nodes.Count; if (myDefaultValueFunction != null && theirDefaultValueFunction != null) { //if (myDefaultValueFunction.FunctionName != theirDefaultValueFunction.FunctionName) { AddNode("FunctionName", theirDefaultValueFunction.FunctionName, myDefaultValueFunction.FunctionName, parentNode, null); } if (myDefaultValueFunction.FunctionType != theirDefaultValueFunction.FunctionType) { AddNodeBoth("FunctionType", theirDefaultValueFunction.FunctionType, myDefaultValueFunction.FunctionType, parentNode, null); } if (myDefaultValueFunction.IsForUserOption != theirDefaultValueFunction.IsForUserOption) { AddNodeBoth("IsForUserOption", theirDefaultValueFunction.IsForUserOption, myDefaultValueFunction.IsForUserOption, parentNode, null); } if (myDefaultValueFunction.ObjectType != theirDefaultValueFunction.ObjectType) { AddNodeBoth("ObjectType", theirDefaultValueFunction.ObjectType, myDefaultValueFunction.ObjectType, parentNode, null); } if (myDefaultValueFunction.ParameterTypes != theirDefaultValueFunction.ParameterTypes) { AddNodeBoth("ParameterTypes", theirDefaultValueFunction.ParameterTypes, myDefaultValueFunction.ParameterTypes, parentNode, null); } if (myDefaultValueFunction.PropertyName != theirDefaultValueFunction.PropertyName) { AddNodeBoth("PropertyName", theirDefaultValueFunction.PropertyName, myDefaultValueFunction.PropertyName, parentNode, null); } if (myDefaultValueFunction.UseCustomCode != theirDefaultValueFunction.UseCustomCode) { AddNodeBoth("UseCustomCode", theirDefaultValueFunction.UseCustomCode, myDefaultValueFunction.UseCustomCode, parentNode, null); } return(originalNumChildNodes != parentNode.Nodes.Count); } else if (theirDefaultValueFunction != null) { //AddNode("FunctionName", theirDefaultValueFunction.FunctionName, null, parentNode, null); AddNodeTheirs("FunctionType", theirDefaultValueFunction.FunctionType, null, parentNode, null); AddNodeTheirs("IsForUserOption", theirDefaultValueFunction.IsForUserOption, null, parentNode, null); AddNodeTheirs("ObjectType", theirDefaultValueFunction.ObjectType, null, parentNode, null); AddNodeTheirs("ParameterTypes", theirDefaultValueFunction.ParameterTypes, null, parentNode, null); AddNodeTheirs("PropertyName", theirDefaultValueFunction.PropertyName, null, parentNode, null); AddNodeTheirs("UseCustomCode", theirDefaultValueFunction.UseCustomCode, null, parentNode, null); } else if (myDefaultValueFunction != null) { //AddNode("FunctionName", myDefaultValueFunction.FunctionName, null, parentNode, null); AddNodeMine("FunctionType", null, myDefaultValueFunction.FunctionType, parentNode, null); AddNodeMine("IsForUserOption", null, myDefaultValueFunction.IsForUserOption, parentNode, null); AddNodeMine("ObjectType", null, myDefaultValueFunction.ObjectType, parentNode, null); AddNodeMine("ParameterTypes", null, myDefaultValueFunction.ParameterTypes, parentNode, null); AddNodeMine("PropertyName", null, myDefaultValueFunction.PropertyName, parentNode, null); AddNodeMine("UseCustomCode", null, myDefaultValueFunction.UseCustomCode, parentNode, null); } return(true); }
private void DeleteHelperFunction(string functionName) { if (MessageBox.Show(string.Format("Delete {0}?", functionName), "Delete Function", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes) { Project.FunctionInfo function = Project.Instance.FindFunction(functionName); if (function != null) { // Delete function deletes the DefaultValueFunction as well, if it exists. Project.Instance.DeleteFunction(function); } else { Project.DefaultValueFunction defValFunc = Project.Instance.FindDefaultValueFunction(functionName); if (defValFunc != null) { Project.Instance.DefaultValueFunctions.Remove(defValFunc); } } } //Populate(); treeListAPIHelper.Invalidate(); }