コード例 #1
0
        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);
            }
        }
コード例 #2
0
        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);
        }
コード例 #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 = 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);
        }
コード例 #4
0
 public void Init()
 {
     _methodBuilder = (new ServiceClassBuilder()).DefineMethod();
     _builder = _methodBuilder.DefineParameter();
 }
コード例 #5
0
ファイル: TestMethodBuilder.cs プロジェクト: krbvroc1/KeeFox
 public void Init()
 {
     _classBuilder = new ServiceClassBuilder();
     _builder = _classBuilder.DefineMethod();
 }
コード例 #6
0
 void IMethodReflector.Build(MethodBuilder builder, MethodInfo method)
 {
     builder.Name = Name;
     builder.Idempotent = Idempotent;
 }
コード例 #7
0
 void IMethodModifier.Modify(MethodBuilder builder)
 {
     builder.Description = Text;
 }
コード例 #8
0
ファイル: JsonRpcHelpAttribute.cs プロジェクト: bubbafat/Hebo
 void IMethodReflector.Build(MethodBuilder builder, MethodInfo method)
 {
     builder.Description = Text;
 }
コード例 #9
0
        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);
        }
コード例 #10
0
 internal ParameterBuilder(MethodBuilder method)
 {
     Debug.Assert(method != null);
         
     _method = method;
 }
コード例 #11
0
 void IMethodModifier.Modify(MethodBuilder builder, MethodInfo method)
 {
     builder.Description = Text;
 }
コード例 #12
0
ファイル: ServiceClassBuilder.cs プロジェクト: db48x/KeeFox
 public MethodBuilder DefineMethod()
 {
     MethodBuilder builder = new MethodBuilder(this);
     MethodList.Add(builder);
     return builder;
 }
コード例 #13
0
 void IMethodModifier.Modify(MethodBuilder builder, MethodInfo method)
 {
     builder.AddCustomAttribute(this);
 }
コード例 #14
0
        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);
            }
        }
コード例 #15
0
 void IMethodReflector.Build(MethodBuilder builder, MethodInfo method)
 {
     builder.AddCustomAttribute(this);
 }