private static void BuildClass(JsonRpcServiceClass.Builder builder, Type type)
        {
            //
            // Build via attributes.
            //

            object[] attributes = type.GetCustomAttributes(typeof(IServiceClassReflector), true);
            foreach (IServiceClassReflector reflector in attributes)
                reflector.Build(builder, type);
            
            //
            // Fault in the type name if still without name.
            //

            if (builder.Name.Length == 0)
                builder.Name = type.Name;

            //
            // Get all the public instance methods on the type and create a
            // filtered table of those to expose from the service.
            //
            
            MethodInfo[] publicMethods = type.GetMethods(BindingFlags.Public | BindingFlags.Instance);

            foreach (MethodInfo method in publicMethods)
            {
                if (ShouldBuild(method))
                    BuildMethod(builder.DefineMethod(), method);
            }
        }
        public virtual JsonRpcServiceClass GetClass()
        {
            if (_class == null)
                _class = JsonRpcServiceClass.FromType(GetType());

            return _class;
        }
        internal JsonRpcMethod(JsonRpcMethodBuilder methodBuilder, JsonRpcServiceClass 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;
            _dispatcher = methodBuilder.Dispatcher;
            _attributes = DeepCopy(methodBuilder.GetCustomAttributes());
            _class = clazz;
            
            JsonRpcParameterBuilder[] parameterBuilders = methodBuilder.GetParameters();
            _parameters = new JsonRpcParameter[parameterBuilders.Length];
            int paramIndex = 0;

            foreach (JsonRpcParameterBuilder parameterBuilder in parameterBuilders)
                _parameters[paramIndex++] = new JsonRpcParameter(parameterBuilder, this);
        }
        internal JsonRpcMethod(Builder methodBuilder, JsonRpcServiceClass clazz)
        {
            Debug.Assert(methodBuilder != null);
            Debug.Assert(clazz != null);
            
            _name = methodBuilder.Name;
            _internalName = Mask.EmptyString(methodBuilder.InternalName, methodBuilder.Name);
            _resultType = methodBuilder.ResultType;
            _isObsolete = methodBuilder.IsObsolete;
            _obsoletionMessage = methodBuilder.IsObsolete ? methodBuilder.ObsoletionMessage : string.Empty;
            _description = methodBuilder.Description;
            _dispatcher = methodBuilder.Dispatcher;
            _class = clazz;
            
            JsonRpcParameter.Builder[] parameterBuilders = methodBuilder.GetParameterBuilders();
            _parameters = new JsonRpcParameter[parameterBuilders.Length];
            int paramIndex = 0;

            foreach (JsonRpcParameter.Builder parameterBuilder in parameterBuilders)
                _parameters[paramIndex++] = new JsonRpcParameter(parameterBuilder, this);
        }
        internal JsonRpcMethod(JsonRpcMethodBuilder methodBuilder, JsonRpcServiceClass 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;
            _dispatcher = methodBuilder.Dispatcher;
            _attributes = DeepCopy(methodBuilder.GetCustomAttributes());
            _class = clazz;
            
            //
            // Set up parameters and their names.
            //
            
            ICollection parameterBuilders = methodBuilder.Parameters;
            _parameters = new JsonRpcParameter[parameterBuilders.Count];
            _parameterNames = new string[parameterBuilders.Count];

            foreach (JsonRpcParameterBuilder parameterBuilder in parameterBuilders)
            {
                JsonRpcParameter parameter = new JsonRpcParameter(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 = (JsonRpcParameter[]) _parameters.Clone();
            Array.Sort(_parameterNames, _sortedParameters, Comparer.DefaultInvariant);
        }
 void IServiceClassReflector.Build(JsonRpcServiceClass.Builder builder, Type type)
 {
     builder.Description = Text;
 }
 internal Builder(JsonRpcServiceClass.Builder serviceClass)
 {
     Debug.Assert(serviceClass != null);
     _serviceClass = serviceClass;
 }
 void IServiceClassReflector.Build(JsonRpcServiceClass.Builder builder, Type type)
 {
     builder.Name = Name;
 }