Exemplo n.º 1
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.º 2
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.º 3
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.º 4
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);
        }