示例#1
0
        public MonadicScalar()
        {
            this.allowedTypes = new HashSet <ATypes>();
            Type currentType = this.GetType();

            DefaultResultAttribute attribute = currentType.GetSingleAttribute <DefaultResultAttribute>();

            this.defaultResultType = (attribute != null) ? attribute.DefaultType : ATypes.AType;

            MethodInfo[] methods = currentType.GetMethods(
                BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public
                );

            foreach (MethodInfo method in methods)
            {
                if (!method.IsVirtual)
                {
                    continue;
                }

                ParameterInfo[] parameterInfo = method.GetParameters();

                this.allowedTypes.Add(Utils.GetATypesFromType(parameterInfo[0].ParameterType));
            }
        }
示例#2
0
        public DyadicScalar()
        {
            this.allowedMethods = new Dictionary <byte, MethodInfo>();
            Type currentType = this.GetType();

            DefaultResultAttribute attribute = currentType.GetSingleAttribute <DefaultResultAttribute>();

            this.defaultResultType = (attribute != null) ? attribute.DefaultType : ATypes.AType;

            MethodInfo[] methods = currentType.GetMethods(
                BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public
                );

            // Detect the methods and add a rule for it based on the parameter types
            foreach (MethodInfo method in methods)
            {
                DyadicScalarMethodAttribute scalarAttribute =
                    method.GetSingleAttribute <DyadicScalarMethodAttribute>();

                if (scalarAttribute == null)
                {
                    continue;
                }

                ParameterInfo[] parameterInfo = method.GetParameters();

                // Add the method to the allowed method's list
                this.allowedMethods.Add(
                    ATypeMask(
                        Utils.GetATypesFromType(parameterInfo[0].ParameterType),
                        Utils.GetATypesFromType(parameterInfo[1].ParameterType)
                        ),
                    method
                    );
            }
        }