void IMethodReflector.Build(MethodBuilder builder, MethodInfo method)
        {
            builder.Name = Name;
            builder.Idempotent = Idempotent;

            //
            // Build the method parameters.
            //

            ParameterInfo[] parameters = method.GetParameters();

            if (WarpedParameters)
            {
                if (parameters.Length != 1)
                {
                    // TODO: Use a more specific exception type
                    throw new Exception(string.Format(
                        "Methods used warped parameters must accept a single argument of the warped type only whereas method {1} on {0} accepts {2}.",
                        method.DeclaringType.FullName, method.Name, parameters.Length.ToString()));
                }

                PropertyDescriptorCollection args = GetProperties(parameters[0].ParameterType);
                foreach (PropertyDescriptor arg in args)
                {
                    ParameterBuilder parameter = builder.DefineParameter();
                    parameter.Name = arg.Name;
                    parameter.ParameterType = arg.PropertyType;
                }

                PropertyDescriptor result = null;

                if (method.ReturnType != typeof(void))
                {
                    PropertyDescriptorCollection results = GetProperties(method.ReturnType);
                    if (results.Count > 0)
                    {
                        result = results[0];
                        builder.ResultType = result.PropertyType;
                    }
                }

                builder.Handler = new WarpedMethodImpl(builder.Handler, 
                    parameters[0].ParameterType, 
                    args, result);
            }
            else
            {
                foreach (ParameterInfo parameter in parameters)
                    JsonRpcServiceReflector.BuildParameter(builder.DefineParameter(), parameter);
            }
        }
        internal static void BuildMethod(MethodBuilder builder, MethodInfo method)
        {
            Debug.Assert(method != null);
            Debug.Assert(builder != null);

            builder.InternalName = method.Name;
            builder.ResultType = method.ReturnType;
            builder.Handler = new TypeMethodImpl(method);

            //
            // Build...
            //

            IMethodReflector reflector = (IMethodReflector) FindCustomAttribute(method, typeof(IMethodReflector), true);

            if (reflector == null)
            {
                reflector = new JsonRpcMethodAttribute();
                TrySetAttachment(reflector,  method);
            }

            reflector.Build(builder);

            //
            // Fault in the method name if still without name.
            //

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

            builder.CustomAttributes = method;

            //
            // Modify...
            //

            IMethodModifier[] modifiers = (IMethodModifier[]) GetCustomAttributes(method, typeof(IMethodModifier), true);
            foreach (IMethodModifier modifier in modifiers)
                modifier.Modify(builder);
        }
        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 = DeepCopy(methodBuilder.GetCustomAttributes());
            _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);
        }
 public void Init()
 {
     _methodBuilder = (new ServiceClassBuilder()).DefineMethod();
     _builder = _methodBuilder.DefineParameter();
 }
Exemple #5
0
 public void Init()
 {
     _classBuilder = new ServiceClassBuilder();
     _builder = _classBuilder.DefineMethod();
 }
 void IMethodReflector.Build(MethodBuilder builder, MethodInfo method)
 {
     builder.Name = Name;
     builder.Idempotent = Idempotent;
 }
 void IMethodModifier.Modify(MethodBuilder builder)
 {
     builder.Description = Text;
 }
 void IMethodReflector.Build(MethodBuilder builder, MethodInfo method)
 {
     builder.Description = Text;
 }
        private static void BuildMethod(MethodBuilder builder, MethodInfo method)
        {
            Debug.Assert(method != null);
            Debug.Assert(builder != null);

            builder.InternalName = method.Name;
            builder.ResultType = method.ReturnType;
            builder.Handler = new TypeMethodImpl(method);

            //
            // Build via attributes.
            //

            object[] attributes = method.GetCustomAttributes(typeof(Attribute), true);
            foreach (Attribute attribute in attributes)
            {
                IMethodReflector reflector = attribute as IMethodReflector;

                if (reflector != null)
                    reflector.Build(builder, method);
                else
                    builder.AddCustomAttribute(attribute);
            }

            //
            // Fault in the method name if still without name.
            //

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

            //
            // Build the method parameters.
            //

            foreach (ParameterInfo parameter in method.GetParameters())
                BuildParameter(builder.DefineParameter(), parameter);
        }
 internal ParameterBuilder(MethodBuilder method)
 {
     Debug.Assert(method != null);
         
     _method = method;
 }
 void IMethodModifier.Modify(MethodBuilder builder, MethodInfo method)
 {
     builder.Description = Text;
 }
Exemple #12
0
 public MethodBuilder DefineMethod()
 {
     MethodBuilder builder = new MethodBuilder(this);
     MethodList.Add(builder);
     return builder;
 }
 void IMethodModifier.Modify(MethodBuilder builder, MethodInfo method)
 {
     builder.AddCustomAttribute(this);
 }
        internal static void BuildMethod(MethodBuilder builder, MethodInfo method)
        {
            Debug.Assert(method != null);
            Debug.Assert(builder != null);

            builder.InternalName = method.Name;
            builder.ResultType = method.ReturnType;
            builder.Handler = new TypeMethodImpl(method);

            //
            // Build...
            //

            IMethodReflector reflector = (IMethodReflector) FindCustomAttribute(method, typeof(IMethodReflector), true);

            if (reflector == null)
                reflector = new JsonRpcMethodAttribute();

            reflector.Build(builder, method);

            //
            // Fault in the method name if still without name.
            //

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

            //
            // Modify...
            //

            object[] attributes = method.GetCustomAttributes(typeof(Attribute), true);
            foreach (Attribute attribute in attributes)
            {
                IMethodModifier modifier = attribute as IMethodModifier;

                if (modifier != null)
                    modifier.Modify(builder, method);
                else if (!(attribute is IMethodReflector))
                    builder.AddCustomAttribute(attribute);
            }
        }
 void IMethodReflector.Build(MethodBuilder builder, MethodInfo method)
 {
     builder.AddCustomAttribute(this);
 }