public DSFunction(WorkspaceModel ws, FunctionDescriptor definition) : base(ws) { ArgumentLacing = LacingStrategy.Shortest; Definition = definition; Initialize(); }
private static string GetMemberElement( FunctionDescriptor function, XmlReader xml, DocumentElementType property, string paramName = "") { //customNodeDefinitions typedParameters don't have functionDescriptors if (function == null) { return string.Empty; } var assemblyName = function.Assembly; if (string.IsNullOrEmpty(assemblyName)) return String.Empty; var fullyQualifiedName = MemberDocumentNode.MakeFullyQualifiedName (assemblyName, GetMemberElementName(function)); if (!documentNodes.ContainsKey(fullyQualifiedName)) { if (xml == null) xml = DocumentationServices.GetForAssembly(function.Assembly, function.PathManager); LoadDataFromXml(xml, assemblyName); } MemberDocumentNode documentNode = null; if (documentNodes.ContainsKey(fullyQualifiedName)) documentNode = documentNodes[fullyQualifiedName]; else { var overloadedName = documentNodes.Keys. Where(key => key.Contains(function.ClassName + "." + function.FunctionName)).FirstOrDefault(); if (overloadedName == null) return String.Empty; if (documentNodes.ContainsKey(overloadedName)) documentNode = documentNodes[overloadedName]; } if (documentNode == null) return String.Empty; if (property.Equals(DocumentElementType.Description) && !documentNode.Parameters.ContainsKey(paramName)) return String.Empty; switch (property) { case DocumentElementType.Summary: return documentNode.Summary; case DocumentElementType.Description: return documentNode.Parameters[paramName]; case DocumentElementType.SearchTags: return documentNode.SearchTags; default: throw new ArgumentException("property"); } }
public ZeroTouchSearchElement(FunctionDescriptor functionDescriptor) { this.functionDescriptor = functionDescriptor; var displayName = functionDescriptor.UserFriendlyName; if (functionDescriptor.IsOverloaded) displayName += "(" + string.Join(", ", functionDescriptor.Parameters) + ")"; Name = displayName; UserFriendlyName = functionDescriptor.UserFriendlyName; FullCategoryName = functionDescriptor.Category; Description = functionDescriptor.Description; Assembly = functionDescriptor.Assembly; ElementType = ElementTypes.ZeroTouch; if (functionDescriptor.IsBuiltIn) ElementType |= ElementTypes.BuiltIn; // Assembly, that is located in package directory, considered as part of package. if (Assembly.StartsWith(functionDescriptor.PathManager.PackagesDirectory)) ElementType |= ElementTypes.Packaged; inputParameters = new List<Tuple<string, string>>(functionDescriptor.InputParameters); outputParameters = new List<string>() { functionDescriptor.ReturnType }; foreach (var tag in functionDescriptor.GetSearchTags()) SearchKeywords.Add(tag); iconName = GetIconName(); }
public void UpdateFunctionDescriptor(FunctionDescriptor funcDesc) { Function = funcDesc; // Setting 'summary' to 'null' so its value is retrieved later // when 'Summary' property is invoked. See 'Summary' for details. summary = null; }
/// <summary> /// Add a function descriptor to the group /// </summary> /// <param name="function"></param> /// <returns></returns> public bool AddFunctionDescriptor(FunctionDescriptor function) { if (!QualifiedName.Equals(function.QualifiedName) || functions.Contains(function)) return false; functions.Add(function); return true; }
public ZeroTouchSearchElement(FunctionDescriptor functionDescriptor) { this.functionDescriptor = functionDescriptor; var displayName = functionDescriptor.UserFriendlyName; if (functionDescriptor.IsOverloaded) displayName += "(" + string.Join(", ", functionDescriptor.Parameters) + ")"; Name = displayName; UserFriendlyName = functionDescriptor.UserFriendlyName; FullCategoryName = functionDescriptor.Category; Description = functionDescriptor.Description; Assembly = functionDescriptor.Assembly; ElementType = ElementTypes.ZeroTouch; if (functionDescriptor.IsBuiltIn) ElementType |= ElementTypes.BuiltIn; // Assembly, that is located in package directory, considered as part of package. var packageDirectories = functionDescriptor.PathManager.PackagesDirectories; if (packageDirectories.Any(directory => Assembly.StartsWith(directory))) ElementType |= ElementTypes.Packaged; inputParameters = new List<Tuple<string, string>>(functionDescriptor.InputParameters); outputParameters = new List<string>() { functionDescriptor.ReturnType }; foreach (var tag in functionDescriptor.GetSearchTags()) SearchKeywords.Add(tag); var weights = functionDescriptor.GetSearchTagWeights(); foreach (var weight in weights) { // Search tag weight can't be more then 1. if (weight <= 1) keywordWeights.Add(weight); } int weightsCount = weights.Count(); // If there weren't added weights for search tags, then add default value - 0.5 if (weightsCount != SearchKeywords.Count) { int numberOfLackingWeights = SearchKeywords.Count - weightsCount; // Number of lacking weights should be more than 0. // It can be less then 0 only if there was some mistake in xml file. if (numberOfLackingWeights > 0) { for (int i = 0; i < numberOfLackingWeights; i++) { keywordWeights.Add(0.5); } } } iconName = GetIconName(); }
public void DescriptionTest() { var assembly = System.Reflection.Assembly.UnsafeLoadFrom("FFITarget.dll"); var testClass = assembly.GetType("FFITarget.DummyZeroTouchClass"); MethodInfo methodWithDesc = testClass.GetMethod("FunctionWithDescription"); MethodInfo methodWithoutDesc = testClass.GetMethod("FunctionWithoutDescription"); NodeDescriptionAttribute atr = new NodeDescriptionAttribute(""); IEnumerable<TypedParameter> arguments; FunctionDescriptor fucDescriptor; // 1 case. Method with description. var attributes = methodWithDesc.GetCustomAttributes(typeof(NodeDescriptionAttribute), false); Assert.IsNotNull(attributes); Assert.Greater(attributes.Length, 0); atr = attributes[0] as NodeDescriptionAttribute; arguments = methodWithDesc.GetParameters().Select( arg => { var type = new ProtoCore.Type(); type.Name = arg.ParameterType.ToString(); return new TypedParameter(arg.Name, type); }); fucDescriptor = new FunctionDescriptor(new FunctionDescriptorParams { FunctionName = methodWithDesc.Name, Summary = atr.ElementDescription, Parameters = arguments }); NodeModel node = new DSFunction(fucDescriptor); Assert.AreEqual(atr.ElementDescription + "\n\n" + fucDescriptor.Signature, node.Description); // 2 case. Method without description. atr = new NodeDescriptionAttribute(""); attributes = methodWithoutDesc.GetCustomAttributes(typeof(NodeDescriptionAttribute), false); Assert.IsNotNull(attributes); Assert.AreEqual(attributes.Length, 0); arguments = methodWithoutDesc.GetParameters().Select( arg => { var type = new ProtoCore.Type(); type.Name = arg.ParameterType.ToString(); return new TypedParameter(arg.Name, type); }); fucDescriptor = new FunctionDescriptor(new FunctionDescriptorParams { FunctionName = methodWithDesc.Name, Summary = atr.ElementDescription, Parameters = arguments }); node = new DSFunction(fucDescriptor); Assert.AreEqual(fucDescriptor.Signature, node.Description); }
public TypedParameter( FunctionDescriptor function, string name, string type, object defaultValue = null) { if (string.IsNullOrEmpty(name)) throw new ArgumentException(); Name = name; if (null == type) throw new ArgumentNullException("type", @"Type cannot be null."); Type = type; DefaultValue = defaultValue; Function = function; }
private FunctionDescriptor GetConstructorMethod() { var funcDesc = new FunctionDescriptor(new FunctionDescriptorParams { Assembly = "MyAssembly.dll", ClassName = "MyNamespace.MyClass", FunctionName = "MyClass", ReturnType = TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.kTypeVar), FunctionType = FunctionType.Constructor }); return funcDesc; }
/// <summary> /// Add a function descriptor to the group /// </summary> /// <param name="function"></param> /// <returns></returns> public bool AddFunctionDescriptor(FunctionDescriptor function) { if (!QualifiedName.Equals(function.QualifiedName) || functions.Contains(function)) return false; functions.Add(function); if (functions.Count > 1) { functions[0].IsOverloaded = true; functions[functions.Count - 1].IsOverloaded = true; } return true; }
private static object GetMemberElementName(FunctionDescriptor member) { char prefixCode; string memberName = member.ClassName + "." + member.Name; switch (member.Type) { case FunctionType.Constructor: // XML documentation uses slightly different constructor names memberName = memberName.Replace(".ctor", "#ctor"); goto case FunctionType.InstanceMethod; case FunctionType.InstanceMethod: prefixCode = 'M'; // parameters are listed according to their type, not their name string paramTypesList = String.Join( ",", member.Parameters.Select(x => x.Type).Select(PrimitiveMap).ToArray() ); if (!String.IsNullOrEmpty(paramTypesList)) memberName += "(" + paramTypesList + ")"; break; case FunctionType.StaticMethod: goto case FunctionType.InstanceMethod; break; case FunctionType.InstanceProperty: prefixCode = 'P'; break; case FunctionType.StaticProperty: goto case FunctionType.InstanceProperty; break; default: throw new ArgumentException("Unknown member type", "member"); } // elements are of the form "M:Namespace.Class.Method" return String.Format("{0}:{1}", prefixCode, memberName); }
private static FunctionDescriptor GetTranslateMethod() { var parms = new List<TypedParameter>() { new TypedParameter("xTranslation", "double"), new TypedParameter("yTranslation", "double"), new TypedParameter("zTranslation", "double") }; var funcDesc = new FunctionDescriptor( "ProtoGeometry.dll", "Autodesk.DesignScript.Geometry.Geometry", "Translate", parms, "Autodesk.DesignScript.Geometry.Geometry", FunctionType.InstanceMethod); parms.ForEach(x => x.Function = funcDesc); return funcDesc; }
private static MemberDocumentNode GetMemberDocumentNode( FunctionDescriptor function, XmlReader xml ) { //customNodeDefinitions typedParameters don't have functionDescriptors if (function == null) { return null; } var assemblyName = function.Assembly; if (string.IsNullOrEmpty(assemblyName)) return null; var fullyQualifiedName = MemberDocumentNode.MakeFullyQualifiedName (assemblyName, GetMemberElementName(function)); if (!documentNodes.ContainsKey(fullyQualifiedName)) { if (xml == null) xml = DocumentationServices.GetForAssembly(function.Assembly, function.PathManager); LoadDataFromXml(xml, assemblyName); } MemberDocumentNode documentNode = null; if (documentNodes.ContainsKey(fullyQualifiedName)) documentNode = documentNodes[fullyQualifiedName]; else { var overloadedName = documentNodes.Keys. Where(key => key.Contains(function.ClassName + "." + function.FunctionName)).FirstOrDefault(); if (overloadedName == null) return null; if (documentNodes.ContainsKey(overloadedName)) documentNode = documentNodes[overloadedName]; } return documentNode; }
private FunctionDescriptor GetMyMethod() { var parms = new List<TypedParameter>() { new TypedParameter("a", TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.kTypeDouble, 0)), new TypedParameter("b", TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.kTypeDouble, 0)), new TypedParameter("c", TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.kTypeDouble, 0)) }; var funcDesc = new FunctionDescriptor(new FunctionDescriptorParams { Assembly = "MyAssembly.dll", ClassName = "MyNamespace.MyClass", FunctionName = "MyMethod", Parameters = parms, ReturnType = TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.kTypeVar), FunctionType = FunctionType.InstanceMethod }); parms.ForEach(x => x.UpdateFunctionDescriptor(funcDesc)); return funcDesc; }
private static string GetMemberElement( FunctionDescriptor function, XmlReader xml, DocumentElementType property, string paramName = "") { //customNodeDefinitions typedParameters don't have functionDescriptors if (function == null) { return(string.Empty); } var assemblyName = function.Assembly; if (string.IsNullOrEmpty(assemblyName)) { return(String.Empty); } var fullyQualifiedName = MemberDocumentNode.MakeFullyQualifiedName (assemblyName, GetMemberElementName(function)); if (!documentNodes.ContainsKey(fullyQualifiedName)) { if (xml == null) { xml = DocumentationServices.GetForAssembly(function.Assembly, function.PathManager); } LoadDataFromXml(xml, assemblyName); } MemberDocumentNode documentNode = null; if (documentNodes.ContainsKey(fullyQualifiedName)) { documentNode = documentNodes[fullyQualifiedName]; } else { var overloadedName = documentNodes.Keys. Where(key => key.Contains(function.ClassName + "." + function.FunctionName)).FirstOrDefault(); if (overloadedName == null) { return(String.Empty); } if (documentNodes.ContainsKey(overloadedName)) { documentNode = documentNodes[overloadedName]; } } if (documentNode == null) { return(String.Empty); } if (property.Equals(DocumentElementType.Description) && !documentNode.Parameters.ContainsKey(paramName)) { return(String.Empty); } switch (property) { case DocumentElementType.Summary: return(documentNode.Summary); case DocumentElementType.Description: return(documentNode.Parameters[paramName]); case DocumentElementType.SearchTags: return(documentNode.SearchTags); default: throw new ArgumentException("property"); } }
private void ImportProcedure(string library, ProcedureNode proc) { string procName = proc.name; if (proc.isAutoGeneratedThisProc || CoreUtils.IsSetter(procName) || CoreUtils.IsDisposeMethod(procName) || CoreUtils.StartsWithDoubleUnderscores(procName)) { return; } string obsoleteMessage = ""; int classScope = proc.classScope; string className = string.Empty; MethodAttributes methodAttribute = proc.MethodAttribute; ClassAttributes classAttribute = null; if (classScope != Constants.kGlobalScope) { var classNode = LibraryManagementCore.ClassTable.ClassNodes[classScope]; classAttribute = classNode.ClassAttributes; className = classNode.name; } // MethodAttribute's HiddenInLibrary has higher priority than // ClassAttribute's HiddenInLibrary bool isVisible = true; if (methodAttribute != null) { isVisible = !methodAttribute.HiddenInLibrary; } else { if (classAttribute != null) { isVisible = !classAttribute.HiddenInLibrary; } } FunctionType type; if (classScope == Constants.kGlobalScope) { type = FunctionType.GenericFunction; } else { if (CoreUtils.IsGetter(procName)) { type = proc.isStatic ? FunctionType.StaticProperty : FunctionType.InstanceProperty; string property; if (CoreUtils.TryGetPropertyName(procName, out property)) { procName = property; } } else { if (proc.isConstructor) { type = FunctionType.Constructor; } else if (proc.isStatic) { type = FunctionType.StaticMethod; } else { type = FunctionType.InstanceMethod; } } } IEnumerable <TypedParameter> arguments = proc.argInfoList.Zip( proc.argTypeList, (arg, argType) => { object defaultValue = null; if (arg.IsDefault) { var binaryExpr = arg.DefaultExpression as BinaryExpressionNode; if (binaryExpr != null) { AssociativeNode vnode = binaryExpr.RightNode; if (vnode is IntNode) { defaultValue = (vnode as IntNode).Value; } else if (vnode is DoubleNode) { defaultValue = (vnode as DoubleNode).Value; } else if (vnode is BooleanNode) { defaultValue = (vnode as BooleanNode).Value; } else if (vnode is StringNode) { defaultValue = (vnode as StringNode).value; } } } return(new TypedParameter(arg.Name, argType.ToString(), defaultValue)); }); IEnumerable <string> returnKeys = null; if (proc.MethodAttribute != null) { if (proc.MethodAttribute.ReturnKeys != null) { returnKeys = proc.MethodAttribute.ReturnKeys; } if (proc.MethodAttribute.IsObsolete) { obsoleteMessage = proc.MethodAttribute.ObsoleteMessage; } } var function = new FunctionDescriptor( library, className, procName, arguments, proc.returntype.ToString(), type, false, isVisible, returnKeys, proc.isVarArg, obsoleteMessage); AddImportedFunctions(library, new[] { function }); }
public ZeroTouchNodeController(FunctionDescriptor zeroTouchDef) : base(zeroTouchDef) { }
public DSVarArgFunction(WorkspaceModel workspaceModel, FunctionDescriptor descriptor) : base(workspaceModel, new ZeroTouchVarArgNodeController(workspaceModel.DynamoModel.EngineController, descriptor)) { VarInputController = new ZeroTouchVarInputController(this); }
private static string GetMemberElement(FunctionDescriptor function, string suffix, XDocument xml) { // Construct the entire function descriptor name, including CLR style names string clrMemberName = GetMemberElementName(function); // match clr member name var match = xml.XPathEvaluate( String.Format("string(/doc/members/member[@name='{0}']/{1})", clrMemberName, suffix)); if (match is String && !string.IsNullOrEmpty((string)match)) { return match as string; } // fallback, namespace qualified method name var methodName = function.QualifiedName; // match with fallback match = xml.XPathEvaluate( String.Format( "string(/doc/members/member[contains(@name,'{0}')]/{1})", methodName, suffix)); if (match is String && !string.IsNullOrEmpty((string)match)) { return match as string; } return String.Empty; }
public DSFunction(WorkspaceModel workspaceModel, FunctionDescriptor descriptor) : base(workspaceModel, new ZeroTouchNodeController(workspaceModel.DynamoModel.EngineController, descriptor)) { }
private void ImportProcedure(string library, ClassNode classNode, ProcedureNode proc) { if (proc.isAutoGeneratedThisProc) { return; } bool isVisibleInLibrary = !(null != proc.MethodAttribute && proc.MethodAttribute.HiddenInLibrary); //If the class is Hidden all methods are hidden. if (null != classNode.ClassAttributes && classNode.ClassAttributes.HiddenInLibrary) { isVisibleInLibrary = null != proc.MethodAttribute && !proc.MethodAttribute.HiddenInLibrary; //But if a particular method is not hidden, then this method is visible } string procName = proc.name; if (CoreUtils.IsSetter(procName) || CoreUtils.IsDisposeMethod(procName) || CoreUtils.StartsWithDoubleUnderscores(procName)) { return; } FunctionType type; if (CoreUtils.IsGetter(procName)) { type = proc.isStatic ? FunctionType.StaticProperty : FunctionType.InstanceProperty; string property; if (CoreUtils.TryGetPropertyName(procName, out property)) { procName = property; } } else { if (proc.isConstructor) { type = FunctionType.Constructor; } else if (proc.isStatic) { type = FunctionType.StaticMethod; } else { type = FunctionType.InstanceMethod; } } IEnumerable <TypedParameter> arguments = proc.argInfoList.Zip( proc.argTypeList, (arg, argType) => { object defaultValue = null; if (arg.IsDefault) { var binaryExpr = arg.DefaultExpression as BinaryExpressionNode; if (binaryExpr != null) { AssociativeNode vnode = binaryExpr.RightNode; if (vnode is IntNode) { defaultValue = (vnode as IntNode).Value; } else if (vnode is DoubleNode) { defaultValue = (vnode as DoubleNode).Value; } else if (vnode is BooleanNode) { defaultValue = (vnode as BooleanNode).Value; } else if (vnode is StringNode) { defaultValue = (vnode as StringNode).value; } } } return(new TypedParameter(arg.Name, argType.ToString(), defaultValue)); }); IEnumerable <string> returnKeys = null; if (proc.MethodAttribute != null && proc.MethodAttribute.ReturnKeys != null) { returnKeys = proc.MethodAttribute.ReturnKeys; } var function = new FunctionDescriptor( library, classNode.name, procName, arguments, proc.returntype.ToString(), type, isVisibleInLibrary, returnKeys, proc.isVarArg); AddImportedFunctions(library, new[] { function }); }
private void ImportProcedure(string library, ProcedureNode proc) { string procName = proc.name; if (proc.isAutoGeneratedThisProc || CoreUtils.IsSetter(procName) || CoreUtils.IsDisposeMethod(procName) || CoreUtils.StartsWithDoubleUnderscores(procName)) { return; } string obsoleteMessage = ""; int classScope = proc.classScope; string className = string.Empty; MethodAttributes methodAttribute = proc.MethodAttribute; ClassAttributes classAttribute = null; if (classScope != Constants.kGlobalScope) { var classNode = LibraryManagementCore.ClassTable.ClassNodes[classScope]; classAttribute = classNode.ClassAttributes; className = classNode.name; } // MethodAttribute's HiddenInLibrary has higher priority than // ClassAttribute's HiddenInLibrary var isVisible = true; var canUpdatePeriodically = false; if (methodAttribute != null) { isVisible = !methodAttribute.HiddenInLibrary; canUpdatePeriodically = methodAttribute.CanUpdatePeriodically; } else { if (classAttribute != null) { isVisible = !classAttribute.HiddenInLibrary; } } FunctionType type; if (classScope == Constants.kGlobalScope) { type = FunctionType.GenericFunction; } else { if (CoreUtils.IsGetter(procName)) { type = proc.isStatic ? FunctionType.StaticProperty : FunctionType.InstanceProperty; string property; if (CoreUtils.TryGetPropertyName(procName, out property)) { procName = property; } } else { if (proc.isConstructor) { type = FunctionType.Constructor; } else if (proc.isStatic) { type = FunctionType.StaticMethod; } else { type = FunctionType.InstanceMethod; } } } List <TypedParameter> arguments = proc.argInfoList.Zip( proc.argTypeList, (arg, argType) => { AssociativeNode defaultArgumentNode; // Default argument specified by DefaultArgumentAttribute // takes higher priority if (!TryGetDefaultArgumentFromAttribute(arg, out defaultArgumentNode) && arg.IsDefault) { var binaryExpr = arg.DefaultExpression as BinaryExpressionNode; if (binaryExpr != null) { defaultArgumentNode = binaryExpr.RightNode; } } string shortName = null; if (defaultArgumentNode != null) { shortName = defaultArgumentNode.ToString(); var rewriter = new ElementRewriter(LibraryManagementCore.ClassTable, LibraryManagementCore.BuildStatus.LogSymbolConflictWarning); defaultArgumentNode = defaultArgumentNode.Accept(rewriter); } return(new TypedParameter(arg.Name, argType, defaultArgumentNode, shortName)); }).ToList(); IEnumerable <string> returnKeys = null; if (proc.MethodAttribute != null) { if (proc.MethodAttribute.ReturnKeys != null) { returnKeys = proc.MethodAttribute.ReturnKeys; } if (proc.MethodAttribute.IsObsolete) { obsoleteMessage = proc.MethodAttribute.ObsoleteMessage; } } var function = new FunctionDescriptor(new FunctionDescriptorParams { Assembly = library, ClassName = className, FunctionName = procName, Parameters = arguments, ReturnType = proc.returntype, FunctionType = type, IsVisibleInLibrary = isVisible, ReturnKeys = returnKeys, PathManager = pathManager, IsVarArg = proc.isVarArg, ObsoleteMsg = obsoleteMessage, CanUpdatePeriodically = canUpdatePeriodically, IsBuiltIn = pathManager.PreloadedLibraries.Contains(library) }); AddImportedFunctions(library, new[] { function }); }
public DSVarArgFunction(WorkspaceModel ws, FunctionDescriptor definition) : base(ws) { Definition = definition; Initialize(); }
/// <param name="xml">Don't set it, it's just for tests.</param> public static string GetSummary(this FunctionDescriptor member, XmlReader xml = null) { return(GetMemberElement(member, xml, DocumentElementType.Summary)); }
private static string GetMemberElementName(FunctionDescriptor member) { char prefixCode; string memberName = member.FunctionName; if (!string.IsNullOrEmpty(member.ClassName)) { memberName = member.ClassName + "." + member.FunctionName; } switch (member.Type) { case FunctionType.Constructor: // XML documentation uses slightly different constructor names int lastPoint = member.ClassName.LastIndexOf("."); if (lastPoint == -1) { goto case FunctionType.InstanceMethod; } string classNameWithoutNamespace = member.ClassName.Substring(lastPoint + 1); // If classname is the same as function name, then it's usual constructor. // Otherwise it's static method which return type is the same as class. if (classNameWithoutNamespace == member.FunctionName) { memberName = member.ClassName + ".#ctor"; } goto case FunctionType.InstanceMethod; case FunctionType.InstanceMethod: prefixCode = 'M'; // parameters are listed according to their type, not their name string paramTypesList = String.Join( ",", member.Parameters.Select(x => x.Type.ToString()).Select(PrimitiveMap).ToArray() ); if (!String.IsNullOrEmpty(paramTypesList)) { memberName += "(" + paramTypesList + ")"; } break; case FunctionType.StaticMethod: goto case FunctionType.InstanceMethod; break; case FunctionType.InstanceProperty: prefixCode = 'P'; break; case FunctionType.StaticProperty: goto case FunctionType.InstanceProperty; break; default: throw new ArgumentException("Unknown member type", "member"); } // elements are of the form "M:Namespace.Class.Method" return(String.Format("{0}:{1}", prefixCode, memberName)); }
public ZeroTouchVarArgNodeController(EngineController engineController, FunctionDescriptor zeroTouchDef) : base(engineController, zeroTouchDef) { }
private void AddZeroTouchNodeToSearch(FunctionDescriptor functionDescriptor) { if (functionDescriptor.IsVisibleInLibrary) { SearchModel.Add(new ZeroTouchSearchElement(functionDescriptor)); } }
public DSFunction(FunctionDescriptor definition) { ArgumentLacing = LacingStrategy.Shortest; Definition = definition; Initialize(); }
public ZeroTouchNodeController( EngineController engineController, FunctionDescriptor zeroTouchDef) : base(zeroTouchDef) { this.engineController = engineController; }
public DSVarArgFunction(FunctionDescriptor descriptor) : base(new ZeroTouchVarArgNodeController(descriptor)) { VarInputController = new ZeroTouchVarInputController(this); }
private static string GetMemberElementName(FunctionDescriptor member) { char prefixCode; string memberName = member.FunctionName; if (!string.IsNullOrEmpty(member.ClassName)) memberName = member.ClassName + "." + member.FunctionName; switch (member.Type) { case FunctionType.Constructor: // XML documentation uses slightly different constructor names int lastPoint = member.ClassName.LastIndexOf("."); if (lastPoint == -1) goto case FunctionType.InstanceMethod; string classNameWithoutNamespace = member.ClassName.Substring(lastPoint + 1); // If classname is the same as function name, then it's usual constructor. // Otherwise it's static method which return type is the same as class. if (classNameWithoutNamespace == member.FunctionName) memberName = member.ClassName + ".#ctor"; goto case FunctionType.InstanceMethod; case FunctionType.InstanceMethod: prefixCode = 'M'; // parameters are listed according to their type, not their name string paramTypesList = String.Join( ",", member.Parameters.Select(x => x.Type.ToString()).Select(PrimitiveMap).ToArray() ); if (!String.IsNullOrEmpty(paramTypesList)) memberName += "(" + paramTypesList + ")"; break; case FunctionType.StaticMethod: goto case FunctionType.InstanceMethod; break; case FunctionType.InstanceProperty: prefixCode = 'P'; break; case FunctionType.StaticProperty: goto case FunctionType.InstanceProperty; break; case FunctionType.GenericFunction: return member.FunctionName; break; default: throw new ArgumentException("Unknown member type", "member"); } // elements are of the form "M:Namespace.Class.Method" return String.Format("{0}:{1}", prefixCode, memberName); }
public void TypedParametersToStringTest() { //1. Foo(x: double, y : double) -> Foo.double-double //2. Foo(point : Point) -> Foo.Point //3. Foo(a : bool [ ] [ ] , b : var[], c : double[][]) -> Foo.bool2-var1-double2 //4. Foo(arr : var[]..[], a : int) -> Foo.varN-int //5. Foo(a: Autodesk.DesignScript.Geometry.Circle, b: Xxxx.Yyy.Curve) //6. Empty string(a: int) // 1 case var parameters1 = new List<TypedParameter>(); parameters1.Add(new TypedParameter("x", new ProtoCore.Type { Name = "double" })); parameters1.Add(new TypedParameter("y", new ProtoCore.Type { Name = "double" })); var functionItem1 = new FunctionDescriptor(new FunctionDescriptorParams { FunctionName = "Foo", Parameters = parameters1, FunctionType = FunctionType.GenericFunction }); System.Console.WriteLine(functionItem1.Parameters.Count()); Assert.AreEqual("Foo.double-double", Utils.TypedParametersToString(functionItem1)); //2 case var parameters2 = new List<TypedParameter>(); parameters2.Add(new TypedParameter("point", new ProtoCore.Type { Name = "Point" })); var functionItem2 = new FunctionDescriptor(new FunctionDescriptorParams { FunctionName = "Foo", Parameters = parameters2, FunctionType = FunctionType.GenericFunction }); Assert.AreEqual("Foo.Point", Utils.TypedParametersToString(functionItem2)); //3 case var parameters3 = new List<TypedParameter>(); parameters3.Add(new TypedParameter("a", new ProtoCore.Type { Name = "bool [ ] [ ] " })); parameters3.Add(new TypedParameter("b", new ProtoCore.Type { Name = "var[]" })); parameters3.Add(new TypedParameter("c", new ProtoCore.Type { Name = "double[][]" })); var functionItem3 = new FunctionDescriptor(new FunctionDescriptorParams { FunctionName = "Foo", Parameters = parameters3, FunctionType = FunctionType.GenericFunction }); Assert.AreEqual("Foo.bool2-var1-double2", Utils.TypedParametersToString(functionItem3)); //4 case var parameters4 = new List<TypedParameter>(); parameters4.Add(new TypedParameter("arr", new ProtoCore.Type { Name = "var[]..[]" })); parameters4.Add(new TypedParameter("a", new ProtoCore.Type { Name = "int" })); var functionItem4 = new FunctionDescriptor(new FunctionDescriptorParams { FunctionName = "Foo", Parameters = parameters4, FunctionType = FunctionType.GenericFunction }); Assert.AreEqual("Foo.varN-int", Utils.TypedParametersToString(functionItem4)); //5 case var parameters5 = new List<TypedParameter>(); parameters5.Add(new TypedParameter("a", new ProtoCore.Type { Name = "Autodesk.DesignScript.Geometry.Circle" })); parameters5.Add(new TypedParameter("b", new ProtoCore.Type { Name = "Xxxx.Yyy.Curve" })); var functionItem5 = new FunctionDescriptor(new FunctionDescriptorParams { FunctionName = "Foo", Parameters = parameters5, FunctionType = FunctionType.GenericFunction }); Assert.AreEqual("Foo.Circle-Curve", Utils.TypedParametersToString(functionItem5)); //6 case var parameters6 = new List<TypedParameter>(); parameters6.Add(new TypedParameter("a", new ProtoCore.Type { Name = "int" })); var functionItem6 = new FunctionDescriptor(new FunctionDescriptorParams { FunctionName = "", Parameters = parameters6, FunctionType = FunctionType.GenericFunction }); Assert.AreEqual(".int", Utils.TypedParametersToString(functionItem6)); }
public DSFunction(FunctionDescriptor descriptor) : base(new ZeroTouchNodeController(descriptor)) { }
/// <summary> /// This method returns a name for the icon based on name of the node. /// </summary> /// <param name="descriptor">Function descriptor, that contains all info about node.</param> /// <param name="overridePrefix"> /// overridePrefix is used as default value for generating node icon name. /// If overridePrefix is empty, it uses QualifiedName property. /// e.g. Autodesk.DesignScript.Geometry.CoordinateSystem.ByOrigin /// </param> public static string TypedParametersToString(FunctionDescriptor descriptor, string overridePrefix = "") { var builder = new StringBuilder(); foreach (TypedParameter tp in descriptor.Parameters) { string typeOfParameter = tp.Type.ToString(); // Check to see if there is array indexer symbols '[]', if so turn their // dimensionality into a number (e.g. 'bool[][]' turned into 'bool2'). int squareBrackets = typeOfParameter.Count(x => x == '['); if (squareBrackets > 0) { if (typeOfParameter.Contains("[]..[]")) { // Remove square brackets. typeOfParameter = typeOfParameter.Replace("[]..[]", ""); // Add number of them. typeOfParameter = String.Concat(typeOfParameter, "N"); } else { // Remove square brackets. int index = typeOfParameter.IndexOf('['); typeOfParameter = typeOfParameter.Substring(0, index).TrimEnd(); // Add number of them. typeOfParameter = String.Concat(typeOfParameter, squareBrackets.ToString()); } } if (builder.Length > 0) builder.Append("-"); typeOfParameter = typeOfParameter.Split('.').Last(); builder.Append(typeOfParameter); } // If the caller does not supply a prefix, use default logic to generate one. if (string.IsNullOrEmpty(overridePrefix)) overridePrefix = NormalizeAsResourceName(descriptor.QualifiedName); return overridePrefix + "." + builder.ToString(); }
public DSVarArgFunction(FunctionDescriptor definition) { Definition = definition; Initialize(); }
private static string GetMemberElement( FunctionDescriptor function, XmlReader xml, DocumentElementType property, string paramName = "") { var documentNode = GetMemberDocumentNode(function, xml); if (documentNode == null) return String.Empty; if (property.Equals(DocumentElementType.Description) && !documentNode.Parameters.ContainsKey(paramName)) return String.Empty; switch (property) { case DocumentElementType.Summary: return documentNode.Summary; case DocumentElementType.Description: return documentNode.Parameters[paramName]; case DocumentElementType.SearchTags: return documentNode.SearchTags; default: throw new ArgumentException("property"); } }