Exemplo n.º 1
0
        public Method FindMethodByName(string name)
        {
            //
            // First make a quick, case-sensitive look-up.
            //

            int i = InvariantStringArray.BinarySearch(_methodNames, name);

            if (i >= 0)
            {
                return(_sortedMethods[i]);
            }

            //
            // Failing, use a slower case-insensitive look-up.
            // TODO: Consider speeding up FindMethodByName for case-insensitive look-ups.
            //

            foreach (Method method in _methods)
            {
                if (CaselessString.Equals(method.Name, name))
                {
                    return(method);
                }
            }

            return(null);
        }
Exemplo n.º 2
0
 private object[] MapArguments(string[] names, object[] args)
 {
     Debug.Assert(names != null);
     Debug.Assert(args != null);
     Debug.Assert(names.Length == args.Length);
     object[] objArray = new object[this._parameters.Length];
     for (int i = 0; i < names.Length; i++)
     {
         string s = names[i];
         if ((s != null) && (s.Length != 0))
         {
             object obj2 = args[i];
             if (obj2 != null)
             {
                 int index = -1;
                 if (s.Length <= 2)
                 {
                     char ch;
                     char ch2;
                     if (s.Length == 2)
                     {
                         ch  = s[0];
                         ch2 = s[1];
                     }
                     else
                     {
                         ch  = '0';
                         ch2 = s[0];
                     }
                     if ((((ch >= '0') && (ch <= '9')) && (ch2 >= '0')) && (ch2 <= '9'))
                     {
                         index = int.Parse(s, NumberStyles.Number, CultureInfo.InvariantCulture);
                         if (index < this._parameters.Length)
                         {
                             objArray[index] = obj2;
                         }
                     }
                 }
                 if (index < 0)
                 {
                     int num3 = InvariantStringArray.BinarySearch(this._parameterNames, s);
                     if (num3 >= 0)
                     {
                         index = this._sortedParameters[num3].Position;
                     }
                 }
                 if (index >= 0)
                 {
                     objArray[index] = obj2;
                 }
             }
         }
     }
     return(objArray);
 }
Exemplo n.º 3
0
        private readonly Method[] _sortedMethods;    // FIXME: [ NonSerialized ]

        internal ServiceClass(ServiceClassBuilder classBuilder)
        {
            Debug.Assert(classBuilder != null);

            _serviceName = classBuilder.Name;
            _description = classBuilder.Description;

            //
            // Set up methods and their names.
            //

            ICollection methodBuilders = classBuilder.Methods;

            _methods     = new Method[methodBuilders.Count];
            _methodNames = new string[methodBuilders.Count];
            int methodIndex = 0;

            foreach (MethodBuilder methodBuilder in methodBuilders)
            {
                Method method = new Method(methodBuilder, this);

                //
                // Check for duplicates.
                //

                if (Array.IndexOf(_methodNames, method.Name) >= 0)
                {
                    throw new DuplicateMethodException(string.Format("The method '{0}' cannot be exported as '{1}' because this name has already been used by another method on the '{2}' service.", method.Name, method.InternalName, _serviceName));
                }

                //
                // Add the method to the class and index it by its name.
                //

                _methods[methodIndex]       = method;
                _methodNames[methodIndex++] = method.Name;
            }

            //
            // Keep a sorted list of parameters and their names so we can
            // do fast look ups using binary search.
            //

            _sortedMethods = (Method[])_methods.Clone();
            InvariantStringArray.Sort(_methodNames, _sortedMethods);
        }
Exemplo n.º 4
0
        public static Method FromMethodInfo(MethodInfo methodInfo)
        {
            Method method = new Method {
                _name           = methodInfo.Name,
                _resultType     = methodInfo.ReturnType,
                _description    = null,
                _parameters     = new Parameter[methodInfo.GetParameters().Length],
                _parameterNames = new string[methodInfo.GetParameters().Length]
            };

            foreach (ParameterInfo info in methodInfo.GetParameters())
            {
                Parameter parameter = Parameter.FromParameterInfo(info);
                int       position  = parameter.Position;
                method._parameters[position]     = parameter;
                method._parameterNames[position] = parameter.Name;
            }
            method._sortedParameters = (Parameter[])method._parameters.Clone();
            InvariantStringArray.Sort(method._parameterNames, method._sortedParameters);
            return(method);
        }
Exemplo n.º 5
0
        internal Method(MethodBuilder methodBuilder, ServiceClass clazz)
        {
            Debug.Assert(methodBuilder != null);
            Debug.Assert(clazz != null);

            _name         = methodBuilder.Name;
            _internalName = Mask.EmptyString(methodBuilder.InternalName, methodBuilder.Name);
            _resultType   = methodBuilder.ResultType;
            _description  = methodBuilder.Description;
            _handler      = methodBuilder.Handler;
            _idempotent   = methodBuilder.Idempotent;
            _attributes   = methodBuilder.CustomAttributes;
            _class        = clazz;

            //
            // Set up parameters and their names.
            //

            ICollection parameterBuilders = methodBuilder.Parameters;

            _parameters     = new Parameter[parameterBuilders.Count];
            _parameterNames = new string[parameterBuilders.Count];

            foreach (ParameterBuilder parameterBuilder in parameterBuilders)
            {
                Parameter parameter = new Parameter(parameterBuilder, this);
                int       position  = parameter.Position;
                _parameters[position]     = parameter;
                _parameterNames[position] = parameter.Name;
            }

            //
            // Keep a sorted list of parameters and their names so we can
            // do fast look ups using binary search.
            //

            _sortedParameters = (Parameter[])_parameters.Clone();
            InvariantStringArray.Sort(_parameterNames, _sortedParameters);
        }
Exemplo n.º 6
0
        public static Method FromMethodInfo(MethodInfo methodInfo)
        {
            Method method = new Method();

            method._name        = methodInfo.Name;
            method._resultType  = methodInfo.ReturnType;
            method._description = null;

            method._parameters     = new Parameter[methodInfo.GetParameters().Length];
            method._parameterNames = new string[methodInfo.GetParameters().Length];
            foreach (ParameterInfo parameterInfo in methodInfo.GetParameters())
            {
                Parameter parameter = Parameter.FromParameterInfo(parameterInfo);
                int       position  = parameter.Position;
                method._parameters[position]     = parameter;
                method._parameterNames[position] = parameter.Name;
            }
            // Keep a sorted list of parameters and their names so we can do fast look ups using binary search.
            method._sortedParameters = (Parameter[])method._parameters.Clone();
            InvariantStringArray.Sort(method._parameterNames, method._sortedParameters);

            return(method);
        }
Exemplo n.º 7
0
        private object[] MapArguments(string[] names, object[] args)
        {
            Debug.Assert(names != null);
            Debug.Assert(args != null);
            Debug.Assert(names.Length == args.Length);

            object[] mapped = new object[_parameters.Length];

            for (int i = 0; i < names.Length; i++)
            {
                string name = names[i];

                if (name == null || name.Length == 0)
                {
                    continue;
                }

                object arg = args[i];

                if (arg == null)
                {
                    continue;
                }

                int position = -1;

                if (name.Length <= 2)
                {
                    char ch1;
                    char ch2;

                    if (name.Length == 2)
                    {
                        ch1 = name[0];
                        ch2 = name[1];
                    }
                    else
                    {
                        ch1 = '0';
                        ch2 = name[0];
                    }

                    if (ch1 >= '0' && ch1 <= '9' &&
                        ch2 >= '0' && ch2 <= '9')
                    {
                        position = int.Parse(name, NumberStyles.Number, CultureInfo.InvariantCulture);

                        if (position < _parameters.Length)
                        {
                            mapped[position] = arg;
                        }
                    }
                }

                if (position < 0)
                {
                    int order = InvariantStringArray.BinarySearch(_parameterNames, name, /* ignoreCase */ true);
                    if (order >= 0)
                    {
                        position = _sortedParameters[order].Position;
                    }
                }

                if (position >= 0)
                {
                    mapped[position] = arg;
                }
            }

            return(mapped);
        }