private static void BuildClass(ServiceClassBuilder builder, Type type)
        {
            //
            // Build...
            //

            IServiceClassReflector reflector = (IServiceClassReflector) FindCustomAttribute(type, typeof(IServiceClassReflector), true);

            if (reflector == null)
            {
                reflector = new JsonRpcServiceAttribute();
                TrySetAttachment(reflector, type);
            }

            reflector.Build(builder);

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

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

            //
            // Modify...
            //

            object[] modifiers = GetCustomAttributes(type, typeof(IServiceClassModifier), true);
            foreach (IServiceClassModifier modifier in modifiers)
                modifier.Modify(builder);
        }
        private static void BuildClass(ServiceClassBuilder 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 void FirstParameterOfStaticMethodDoesNotAppearInTheReflectedModel()
 {
     ServiceClassBuilder scb = new ServiceClassBuilder();
     MethodInfo method = typeof(ServiceWithStaticMethod).GetMethod("StaticMethod");
     JsonRpcMethodAttribute attribute = new JsonRpcMethodAttribute();
     IAttributeAttachment attachment = attribute;
     attachment.SetAttachment(method);
     IMethodReflector reflector = attribute;
     MethodBuilder mb = scb.DefineMethod();
     reflector.Build(mb);
     Assert.AreEqual(0, mb.Parameters.Count);
 }
        void IServiceClassReflector.Build(ServiceClassBuilder builder, Type type)
        {
            builder.Name = 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 (JsonRpcServiceReflector.ShouldBuild(method))
                    JsonRpcServiceReflector.BuildMethod(builder.DefineMethod(), method);
            }
        }
Beispiel #5
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);
        }
Beispiel #6
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);
        }
Beispiel #7
0
 internal MethodBuilder(ServiceClassBuilder serviceClass)
 {
     Debug.Assert(serviceClass != null);
     _serviceClass = serviceClass;
     _attributes = ZeroAttributes;
 }
 void IServiceClassModifier.Modify(ServiceClassBuilder builder)
 {
     builder.Description = Text;
 }
Beispiel #9
0
 void IServiceClassReflector.Build(ServiceClassBuilder builder, Type type)
 {
     builder.Description = Text;
 }
 private static ServiceClass BuildFromType(Type type)
 {
     ServiceClassBuilder builder = new ServiceClassBuilder();
     BuildClass(builder, type);
     return builder.CreateClass();
 }
Beispiel #11
0
 public void Init()
 {
     _classBuilder = new ServiceClassBuilder();
     _builder      = _classBuilder.DefineMethod();
 }
 internal MethodBuilder(ServiceClassBuilder serviceClass)
 {
     Debug.Assert(serviceClass != null);
     _serviceClass = serviceClass;
 }
 void IServiceClassReflector.Build(ServiceClassBuilder builder, Type type)
 {
     builder.Name = Name;
 }
Beispiel #14
0
 public void Init()
 {
     _classBuilder = new ServiceClassBuilder();
     _builder = _classBuilder.DefineMethod();
 }
 public void Init()
 {
     _builder = new ServiceClassBuilder();
 }
 public void Init()
 {
     _builder = new ServiceClassBuilder();
 }
Beispiel #17
0
 internal MethodBuilder(ServiceClassBuilder serviceClass)
 {
     Debug.Assert(serviceClass != null);
     _serviceClass = serviceClass;
     _attributes   = ZeroAttributes;
 }