public override bool Equals(TypeSpecifier other)
        {
            if (other == null)
                return false;

            StructureSpecifier stOther = other as StructureSpecifier;
            if (stOther == null)
                return false;

            if (this.Identifier != null)
            {
                if (this.Identifier.Equals(stOther.Identifier))
                    return true;
            }
            else if (stOther.Identifier == null)
            {
                if (this.StructureDeclarationList.Count == stOther.StructureDeclarationList.Count)
                {
                    for (int i = 0; i < this.StructureDeclarationList.Count; ++i)
                    {
                        if (!stOther.StructureDeclarationList[i].Equals(this.StructureDeclarationList[i]))
                            return false;
                    }

                    return true;
                }
            }

            return false;
        }
예제 #2
0
        public IEnumerable <ConstructorSpecifier> GetConstructors(TypeSpecifier typeSpecifier)
        {
            var symbol = GetTypeFromSpecifier <INamedTypeSymbol>(typeSpecifier);

            if (symbol != null)
            {
                return(symbol.Constructors.Select(c => ReflectionConverter.ConstructorSpecifierFromSymbol(c)));
            }

            return(new ConstructorSpecifier[0]);
        }
예제 #3
0
        public void AddReturnType()
        {
            if (this != Method.MainReturnNode)
            {
                throw new InvalidOperationException("Can only add return types on the main return node.");
            }

            int returnIndex = InputDataPins.Count;

            AddInputDataPin($"Output{returnIndex}", new ObservableValue <BaseType>(TypeSpecifier.FromType <object>()));
            AddInputTypePin($"Output{returnIndex}Type");
        }
예제 #4
0
        /// <summary>
        /// Translates an object into a literal value (eg. a float 32.32 -> "32.32f")
        /// </summary>
        /// <param name="obj">Object value to translate.</param>
        /// <param name="type">Specifier for the type of the literal.</param>
        /// <returns></returns>
        public static string ObjectToLiteral(object obj, TypeSpecifier type)
        {
            // Interpret object string as enum field
            if (type.IsEnum)
            {
                return($"{type}.{obj}");
            }

            // Null
            if (obj is null)
            {
                return("null");
            }

            // Put quotes around string literals
            if (type == TypeSpecifier.FromType <string>())
            {
                return($"\"{obj}\"");
            }
            else if (type == TypeSpecifier.FromType <float>())
            {
                return($"{obj}F");
            }
            else if (type == TypeSpecifier.FromType <double>())
            {
                return($"{obj}D");
            }
            else if (type == TypeSpecifier.FromType <uint>())
            {
                return($"{obj}U");
            }
            // Put single quotes around char literals
            else if (type == TypeSpecifier.FromType <char>())
            {
                return($"'{obj}'");
            }
            else if (type == TypeSpecifier.FromType <long>())
            {
                return($"{obj}L");
            }
            else if (type == TypeSpecifier.FromType <ulong>())
            {
                return($"{obj}UL");
            }
            else if (type == TypeSpecifier.FromType <decimal>())
            {
                return($"{obj}M");
            }
            else
            {
                return(obj.ToString());
            }
        }
예제 #5
0
        private static MethodSpecifier TryMakeClosedMethod(MethodSpecifier method,
                                                           BaseType typeToReplace, TypeSpecifier replacementType)
        {
            // Create a list of generic types to replace with another type
            // These will then look for those generic types in the argument-
            // and return types and replace them with the new type

            Dictionary <GenericType, BaseType> replacedGenericTypes =
                new Dictionary <GenericType, BaseType>();

            // If the arg is already generic itself, replace it directly with the
            // passed type specifier
            // Otherwise, recursively check if the generic arguments should
            // be replaced

            if (typeToReplace is GenericType genType)
            {
                replacedGenericTypes.Add(genType, replacementType);
            }
            else if (typeToReplace is TypeSpecifier argTypeSpec)
            {
                if (!FindGenericArgumentsToReplace(argTypeSpec.GenericArguments,
                                                   replacementType.GenericArguments, ref replacedGenericTypes))
                {
                    return(null);
                }
            }

            IList <BaseType> methodArgTypes = method.ArgumentTypes.ToList();

            ReplaceGenericTypes(methodArgTypes, replacedGenericTypes);

            // Replace method arguments' types by the replaced ones
            for (int i = 0; i < method.Arguments.Count; i++)
            {
                method.Arguments[i].Value = methodArgTypes[i];
            }

            ReplaceGenericTypes(method.ReturnTypes, replacedGenericTypes);

            // Remove the replaced generic arguments from the method
            replacedGenericTypes.Keys.ToList().ForEach(g =>
                                                       method.GenericArguments.Remove(g));

            // Only add fully closed methods
            if (!method.GenericArguments.Any(a => a is GenericType))
            {
                return(method);
            }

            return(null);
        }
예제 #6
0
        public void TestGenericTypeConversionEquality()
        {
            TypeSpecifier typeInt = typeof(System.Collections.Generic.List <int>);

            Assert.AreEqual(typeInt, typeof(System.Collections.Generic.List <int>));
            Assert.AreEqual(typeof(System.Collections.Generic.List <int>), typeInt);

            Assert.AreNotEqual(typeInt, typeof(System.Collections.Generic.List <string>));
            Assert.AreNotEqual(typeof(System.Collections.Generic.List <string>), typeInt);

            Assert.AreNotEqual(typeInt, typeof(System.Collections.Generic.Stack <string>));
            Assert.AreNotEqual(typeof(System.Collections.Generic.Stack <string>), typeInt);
        }
예제 #7
0
        public ConstantExpression(object value, TypeSpecifier type, ISourcePositionInfo location = null) : base(type, location)
        {
            if (value == null)
            {
                Error.ArgumentNull("value");
            }
            if (value is P.Any && (value is P.Boolean || value is P.Decimal || value is P.Integer || value is P.Long || value is P.String))
            {
                throw new ArgumentException("Internal error: not yet ready to handle Any-based primitives in FhirPath.");
            }

            Value = value;
        }
예제 #8
0
        public object Find(TypeSpecifier typeSpecifier)
        {
            if (typeSpecifier is SimpleType)
            {
                var t = typeSpecifier as SimpleType;
                if (t.TypeKind == SimpleTypeKind.Class)
                {
                    return(Classes.Where(_ => _.Name == t.TypeName && _.Namespace == _.Namespace).FirstOrDefault());
                }
            }

            return(null);
        }
예제 #9
0
        public IEnumerable <string> GetEnumNames(TypeSpecifier typeSpecifier)
        {
            var symbol = GetTypeFromSpecifier(typeSpecifier);

            if (symbol != null)
            {
                return(symbol.GetAllMembers()
                       .Where(member => member.Kind == SymbolKind.Field)
                       .Select(member => member.Name));
            }

            return(new string[0]);
        }
예제 #10
0
        public void TestGetNativeType()
        {
            Assert.AreEqual(typeof(string), TypeSpecifier.String.GetNativeType());
            Assert.AreEqual(typeof(Quantity), TypeSpecifier.Quantity.GetNativeType());
            Assert.AreEqual(typeof(object), TypeSpecifier.Any.GetNativeType());
            Assert.AreEqual(typeof(PartialTime), TypeSpecifier.Time.GetNativeType());
            Assert.AreEqual(typeof(Guid), TypeSpecifier.ForNativeType(typeof(Guid)).GetNativeType());

#if !NET40
            Assert.ThrowsException <NotSupportedException>(() => TypeSpecifier.GetByName("DotNet", "NoSuchType").GetNativeType());
            Assert.ThrowsException <NotSupportedException>(() => TypeSpecifier.GetByName("Internal", "NoSuchType").GetNativeType());
#endif
        }
예제 #11
0
 public static Parser <Expression> FunctionParameter(string name)
 {
     // Make exception for is() and as() FUNCTIONS (operators are handled elsewhere), since they don't
     // take a normal parameter, but an identifier (which is not normally a FhirPath type)
     if (name != "is" && name != "as")
     {
         return(Grammar.Expression);
     }
     else
     {
         return(TypeSpecifier.Select(s => new ConstantExpression(s)));
     }
 }
예제 #12
0
        public VariableSetterNode(NodeGraph graph, VariableSpecifier variable)
            : base(graph, variable)
        {
            AddInputExecPin("Exec");
            AddOutputExecPin("Exec");

            AddInputDataPin("NewValue", variable.Type);

            if (this.IsEvent)
            {
                AddInputDataPin("Subscribe", TypeSpecifier.FromType <bool>());
            }
        }
예제 #13
0
        public void TestGenericTypeConversionEquality()
        {
            TypeSpecifier typeInt = TypeSpecifier.FromType <List <int> >();

            Assert.AreEqual(typeInt, TypeSpecifier.FromType <List <int> >());
            Assert.AreEqual(TypeSpecifier.FromType <List <int> >(), typeInt);

            Assert.AreNotEqual(typeInt, TypeSpecifier.FromType <List <string> >());
            Assert.AreNotEqual(TypeSpecifier.FromType <List <string> >(), typeInt);

            Assert.AreNotEqual(typeInt, TypeSpecifier.FromType <Stack <string> >());
            Assert.AreNotEqual(TypeSpecifier.FromType <Stack <string> >(), typeInt);
        }
예제 #14
0
        public override bool Equals(TypeSpecifier other)
        {
            if (other == null)
                return false;

            EnumSpecifier enOther = other as EnumSpecifier;
            if (enOther == null)
                return false;

            if (Identifier.Equals(enOther.Identifier))
                return true;

            return false;
        }
        public void TestEquality()
        {
            Assert.AreEqual(TypeSpecifier.Concept, TypeSpecifier.Concept);
            Assert.AreNotEqual(TypeSpecifier.Concept, TypeSpecifier.Code);
#pragma warning disable CS1718 // Comparison made to same variable - we're testing the '==' operator here
            Assert.IsTrue(TypeSpecifier.Concept == TypeSpecifier.Concept);
#pragma warning restore CS1718 // Comparison made to same variable
            Assert.IsTrue(TypeSpecifier.Concept != TypeSpecifier.Code);
            Assert.AreEqual(TypeSpecifier.Concept, TypeSpecifier.GetByName("Concept"));
            Assert.AreEqual(TypeSpecifier.Concept, TypeSpecifier.GetByName("System", "Concept"));

            Assert.AreNotEqual(TypeSpecifier.Concept, TypeSpecifier.GetByName("System", "concept"));
            Assert.AreNotEqual(TypeSpecifier.GetByName("System", "Concept"), TypeSpecifier.GetByName("System", "concept"));
        }
        private static void AddOperator(string opName, bool unary, TypeSpecifier argType, TypeSpecifier returnType)
        {
            IEnumerable <MethodParameter> parameters = new[]
            {
                new MethodParameter("a", argType, MethodParameterPassType.Default),
            };

            if (!unary)
            {
                parameters = parameters.Concat(new[] { new MethodParameter("b", argType, MethodParameterPassType.Default) });
            }

            all.Add(new MethodSpecifier(opName, parameters, new[] { returnType }, MethodModifiers.Static, MemberVisibility.Public, returnType, new BaseType[0]));
        }
예제 #17
0
        public ForLoopNode(Method method)
            : base(method)
        {
            AddInputExecPin("Exec");
            AddInputExecPin("Continue");

            AddOutputExecPin("Loop");
            AddOutputExecPin("Completed");

            AddInputDataPin("InitialIndex", TypeSpecifier.FromType <int>());
            AddInputDataPin("MaxIndex", TypeSpecifier.FromType <int>());

            AddOutputDataPin("Index", TypeSpecifier.FromType <int>());
        }
예제 #18
0
        public void TestGenerics()
        {
            // Create the open class<T> which contains a List<T>

            GenericType genericClassArg = new GenericType("T");

            Class openClass = new Class();

            openClass.Name      = "OpenClass";
            openClass.Namespace = "Namespace";
            openClass.DeclaredGenericArguments.Add(genericClassArg);

            TypeSpecifier listType = typeof(List <>);

            Assert.AreEqual(listType.GenericArguments.Count, 1);

            listType.GenericArguments[0] = genericClassArg;

            Method openMethod = new Method("OpenMethod");

            openMethod.ArgumentTypes.Add(listType);
            GraphUtil.ConnectExecPins(openMethod.EntryNode.InitialExecutionPin, openMethod.ReturnNode.ReturnPin);

            openClass.Methods.Add(openMethod);

            // Create the closed class which contains a List<string>

            Class closedClass = new Class();

            closedClass.Name      = "ClosedClass";
            closedClass.Namespace = "Namespace";

            TypeSpecifier closedListType = typeof(List <string>);

            Method closedMethod = new Method("ClosedMethod");

            closedMethod.ArgumentTypes.Add(closedListType);
            GraphUtil.ConnectExecPins(closedMethod.EntryNode.InitialExecutionPin, closedMethod.ReturnNode.ReturnPin);

            closedClass.Methods.Add(closedMethod);

            // Translate the classes

            ClassTranslator translator = new ClassTranslator();

            string openClassTranslated = translator.TranslateClass(openClass);

            string closedClassTranslated = translator.TranslateClass(closedClass);
        }
예제 #19
0
        public void CreateStringLengthMethod()
        {
            List <TypeSpecifier> argumentTypes = new List <TypeSpecifier>()
            {
                TypeSpecifier.FromType <string>(),
            };

            // Create method
            stringLengthMethod = new Method("StringLength")
            {
                Visibility = MemberVisibility.Public
            };

            // Add arguments
            List <TypeNode> argTypeNodes = new List <TypeNode>()
            {
                new TypeNode(stringLengthMethod, TypeSpecifier.FromType <string>()),
            };

            for (int i = 0; i < argTypeNodes.Count; i++)
            {
                stringLengthMethod.EntryNode.AddArgument();
                GraphUtil.ConnectTypePins(argTypeNodes[i].OutputTypePins[0], stringLengthMethod.EntryNode.InputTypePins[i]);
            }

            // Add return types
            List <TypeNode> returnTypeNodes = new List <TypeNode>()
            {
                new TypeNode(stringLengthMethod, TypeSpecifier.FromType <int>()),
            };

            for (int i = 0; i < returnTypeNodes.Count; i++)
            {
                stringLengthMethod.MainReturnNode.AddReturnType();
                GraphUtil.ConnectTypePins(returnTypeNodes[i].OutputTypePins[0], stringLengthMethod.MainReturnNode.InputTypePins[i]);
            }

            // Create nodes
            var getLengthNode = new VariableGetterNode(stringLengthMethod, new VariableSpecifier("Length", TypeSpecifier.FromType <int>(),
                                                                                                 MemberVisibility.Public, MemberVisibility.Public, TypeSpecifier.FromType <string>(), VariableModifiers.None));

            // Connect node execs
            GraphUtil.ConnectExecPins(stringLengthMethod.EntryNode.InitialExecutionPin, stringLengthMethod.ReturnNodes.First().ReturnPin);

            // Connect node data
            GraphUtil.ConnectDataPins(stringLengthMethod.EntryNode.OutputDataPins[0], getLengthNode.InputDataPins[0]);
            GraphUtil.ConnectDataPins(getLengthNode.OutputDataPins[0], stringLengthMethod.ReturnNodes.First().InputDataPins[0]);
        }
예제 #20
0
        public static bool Prompt(out TypeSpecifier type)
        {
            var selectTypeDialog = new SelectTypeDialog();

            if (selectTypeDialog.ShowDialog() == true)
            {
                type = (TypeSpecifier)selectTypeDialog.SelectedItem;
                if (type is not null && type.Equals(null) == false)
                {
                    return(true);
                }
            }

            type = default;
            return(false);
        }
예제 #21
0
        public ForeachLoopNode(NodeGraph graph) :
            base(graph)
        {
            AddInputExecPin("Exec");
            //AddInputExecPin("Break");

            AddOutputExecPin("Completed");
            AddOutputExecPin("Loop");

            AddOutputDataPin("Index", TypeSpecifier.FromType <int>());
            AddOutputDataPin("Element", TypeSpecifier.FromType <object>());
            AddInputDataPin("Collection", TypeSpecifier.FromType <IEnumerable <object> >());

            SetupEvents();
            UpdateElementPin();
        }
예제 #22
0
        public static TypeSpecifier DetermineTypeNodeType(TypeNode node)
        {
            // TODO: Copy node.Type

            // Replace generic arguments with input pins
            foreach (NodeInputTypePin inputTypePin in node.InputTypePins)
            {
                // TODO: Check inputTypePin constraints
                TypeSpecifier inputType = DetermineTypeNodeType(inputTypePin.Node);

                int pinIndex = node.InputTypePins.IndexOf(inputTypePin);
                node.Type.GenericArguments[pinIndex] = inputType;
            }

            return(node.Type);
        }
예제 #23
0
        public ForLoopNode(NodeGraph graph)
            : base(graph)
        {
            AddInputExecPin("Exec");

            AddOutputExecPin("Completed");
            AddOutputExecPin("Loop");

            AddInputDataPin("InitialIndex", TypeSpecifier.FromType <int>());
            AddInputDataPin("MaxIndex", TypeSpecifier.FromType <int>());

            AddOutputDataPin("Index", TypeSpecifier.FromType <int>());

            InitialIndexPin.UsesExplicitDefaultValue = true;
            InitialIndexPin.ExplicitDefaultValue     = 0;
        }
예제 #24
0
        public void CreateIfElseMethod()
        {
            // Create method
            ifElseMethod = new Method("IfElse")
            {
                Visibility = MemberVisibility.Public
            };

            // Add arguments
            List <TypeNode> argTypeNodes = new List <TypeNode>()
            {
                new TypeNode(ifElseMethod, TypeSpecifier.FromType <int>()),
                new TypeNode(ifElseMethod, TypeSpecifier.FromType <bool>()),
            };

            for (int i = 0; i < argTypeNodes.Count; i++)
            {
                ifElseMethod.EntryNode.AddArgument();
                GraphUtil.ConnectTypePins(argTypeNodes[i].OutputTypePins[0], ifElseMethod.EntryNode.InputTypePins[i]);
            }

            // Add return types
            List <TypeNode> returnTypeNodes = new List <TypeNode>()
            {
                new TypeNode(ifElseMethod, TypeSpecifier.FromType <int>()),
            };

            for (int i = 0; i < returnTypeNodes.Count; i++)
            {
                ifElseMethod.MainReturnNode.AddReturnType();
                GraphUtil.ConnectTypePins(returnTypeNodes[i].OutputTypePins[0], ifElseMethod.MainReturnNode.InputTypePins[i]);
            }

            // Create nodes
            IfElseNode  ifElseNode  = new IfElseNode(ifElseMethod);
            LiteralNode literalNode = LiteralNode.WithValue(ifElseMethod, 123);

            // Connect exec nodes
            GraphUtil.ConnectExecPins(ifElseMethod.EntryNode.InitialExecutionPin, ifElseNode.ExecutionPin);
            GraphUtil.ConnectExecPins(ifElseNode.TruePin, ifElseMethod.ReturnNodes.First().ReturnPin);
            GraphUtil.ConnectExecPins(ifElseNode.FalsePin, ifElseMethod.ReturnNodes.First().ReturnPin);

            // Connect node data
            GraphUtil.ConnectDataPins(ifElseMethod.EntryNode.OutputDataPins[1], ifElseNode.ConditionPin);
            GraphUtil.ConnectDataPins(ifElseMethod.EntryNode.OutputDataPins[0], ifElseMethod.ReturnNodes.First().InputDataPins[0]);
            GraphUtil.ConnectDataPins(literalNode.ValuePin, ifElseMethod.ReturnNodes.First().InputDataPins[0]);
        }
예제 #25
0
        public ConstantExpression(object value, ISourcePositionInfo location = null) : base(TypeSpecifier.Any, location)
        {
            if (value == null)
            {
                Error.ArgumentNull("value");
            }

            if (Any.TryConvertToSystemValue(value, out var systemValue))
            {
                Value          = systemValue;
                ExpressionType = TypeSpecifier.ForNativeType(value.GetType());
            }
            else
            {
                throw Error.InvalidOperation("Internal logic error: encountered unmappable Value of type " + Value.GetType().Name);
            }
        }
예제 #26
0
 public static string ObjectToLiteral(object obj, TypeSpecifier type)
 {
     // Interpret object string as enum field
     if (type.IsEnum)
     {
         return($"{type}.{obj}");
     }
     // Put quotes around string literals
     if (type == typeof(string))
     {
         return($"\"{obj}\"");
     }
     else if (type == typeof(float))
     {
         return($"{obj}F");
     }
     else if (type == typeof(double))
     {
         return($"{obj}D");
     }
     else if (type == typeof(uint))
     {
         return($"{obj}U");
     }
     // Put single quotes around char literals
     else if (type == typeof(char))
     {
         return($"'{obj}'");
     }
     else if (type == typeof(long))
     {
         return($"{obj}L");
     }
     else if (type == typeof(ulong))
     {
         return($"{obj}UL");
     }
     else if (type == typeof(decimal))
     {
         return($"{obj}M");
     }
     else
     {
         return(obj.ToString());
     }
 }
예제 #27
0
        public void Setup()
        {
            classTranslator = new ClassTranslator();

            cls = new ClassGraph()
            {
                Name      = "TestClass",
                Namespace = "TestNamespace",
            };

            CreateStringLengthMethod();
            CreateMainMethod();

            cls.Variables.Add(new Variable(cls, "testVariable", TypeSpecifier.FromType <string>(), null, null, VariableModifiers.None));
            cls.Methods.Add(stringLengthMethod);
            cls.Methods.Add(mainMethod);
        }
        public void TestConstruction()
        {
            var sysT = TypeSpecifier.GetByName("Concept");

            Assert.AreEqual("System", sysT.Namespace);
            Assert.AreEqual("Concept", sysT.Name);
            Assert.IsTrue(Object.ReferenceEquals(sysT, TypeSpecifier.Concept));

            sysT = TypeSpecifier.GetByName("AsYetUnknown");
            Assert.AreEqual("System", sysT.Namespace);
            Assert.AreEqual("AsYetUnknown", sysT.Name);

            var cusT = TypeSpecifier.GetByName("MySpace", "MyType");

            Assert.AreEqual("MySpace", cusT.Namespace);
            Assert.AreEqual("MyType", cusT.Name);
        }
예제 #29
0
        public LiteralNode(Method method, TypeSpecifier literalType)
            : base(method)
        {
            LiteralType = literalType;

            // Add type pins for each generic argument of the literal type
            // and monitor them for changes to reconstruct the actual pin types.
            foreach (var genericArg in literalType.GenericArguments.OfType <GenericType>())
            {
                AddInputTypePin(genericArg.Name);
            }

            AddInputDataPin("Value", literalType);
            AddOutputDataPin("Value", literalType);

            UpdatePinTypes();
        }
예제 #30
0
        public IEnumerable <MethodSpecifier> GetStaticFunctionsWithArgumentType(TypeSpecifier searchTypeSpec)
        {
            // Find all public static methods

            IEnumerable <IMethodSymbol> availableMethods = GetValidTypes()
                                                           .Where(t => t.IsPublic())
                                                           .SelectMany(t =>
                                                                       t.GetMethods()
                                                                       .Where(m => m.IsPublic() && m.IsStatic && !m.ContainingType.IsUnboundGenericType))
                                                           .OrderBy(m => m?.ContainingNamespace.Name)
                                                           .ThenBy(m => m?.ContainingType.Name)
                                                           .ThenBy(m => m.Name);

            ITypeSymbol searchType = GetTypeFromSpecifier(searchTypeSpec);

            List <MethodSpecifier> foundMethods = new List <MethodSpecifier>();

            // Find compatible methods

            foreach (IMethodSymbol availableMethod in availableMethods)
            {
                MethodSpecifier availableMethodSpec = ReflectionConverter.MethodSpecifierFromSymbol(availableMethod);

                // Check each argument whether it can be replaced by the wanted type
                for (int i = 0; i < availableMethodSpec.Arguments.Count; i++)
                {
                    ITypeSymbol argType = availableMethod.Parameters[i].Type;
                    BaseType    arg     = ReflectionConverter.BaseTypeSpecifierFromSymbol(argType);

                    if (arg == searchTypeSpec || searchType.IsSubclassOf(argType))
                    {
                        MethodSpecifier foundMethod = ReflectionConverter.MethodSpecifierFromSymbol(availableMethod);
                        foundMethod = TryMakeClosedMethod(foundMethod, arg, searchTypeSpec);

                        // Only add fully closed methods
                        if (foundMethod != null && !foundMethods.Contains(foundMethod))
                        {
                            foundMethods.Add(foundMethod);
                        }
                    }
                }
            }

            return(foundMethods);
        }
예제 #31
0
        public IEnumerable <MethodSpecifier> GetStaticFunctionsWithArgumentType(TypeSpecifier searchTypeSpec)
        {
            // Find all public static methods

            IEnumerable <MethodInfo> availableMethods = Assemblies
                                                        .SelectMany(a =>
                                                                    a.GetTypes()
                                                                    .Where(t => t.IsPublic)
                                                                    .SelectMany(t =>
                                                                                t.GetMethods(BindingFlags.Static | BindingFlags.Public)
                                                                                .Where(m => !m.IsSpecialName &&
                                                                                       !m.DeclaringType.ContainsGenericParameters)));

            Type searchType = GetTypeFromSpecifier(searchTypeSpec);

            List <MethodSpecifier> foundMethods = new List <MethodSpecifier>();

            // Find compatible methods

            foreach (MethodInfo availableMethod in availableMethods)
            {
                MethodSpecifier availableMethodSpec = availableMethod;

                // Check each argument whether it can be replaced by the wanted type
                for (int i = 0; i < availableMethodSpec.Arguments.Count; i++)
                {
                    Type     argType = availableMethod.GetParameters()[i].ParameterType;
                    BaseType arg     = argType;

                    if (arg == searchTypeSpec || searchType.IsSubclassOf(argType))
                    {
                        MethodSpecifier foundMethod = availableMethod;
                        foundMethod = TryMakeClosedMethod(foundMethod, arg, searchTypeSpec);

                        // Only add fully closed methods
                        if (foundMethod != null && !foundMethods.Contains(foundMethod))
                        {
                            foundMethods.Add(foundMethod);
                        }
                    }
                }
            }

            return(foundMethods);
        }
예제 #32
0
        public void GetPrimitiveName()
        {
            Dictionary <Type, string> data = new Dictionary <Type, string>
            {
                { typeof(PartialDateTime), "dateTime" },
                { typeof(UInt16), "integer" },
                { typeof(Boolean), "boolean" }
            };

            foreach (var pair in data)
            {
                var native   = pair.Key;
                var expected = pair.Value;

                Assert.IsTrue(TypeSpecifier.TryGetPrimitiveTypeName(native, out var actual));
                Assert.AreEqual(expected, actual);
            }
        }