Exemplo n.º 1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public OutputMapper mapper(Class userClass) throws org.neo4j.internal.kernel.api.exceptions.ProcedureException
        public virtual OutputMapper Mapper(Type userClass)
        {
            AssertIsValidRecordClass(userClass);

            IList <System.Reflection.FieldInfo> fields = InstanceFields(userClass);

            FieldSignature[] signature    = new FieldSignature[fields.Count];
            FieldMapper[]    fieldMappers = new FieldMapper[fields.Count];

            for (int i = 0; i < fields.Count; i++)
            {
                System.Reflection.FieldInfo field = fields[i];
                if (!isPublic(field.Modifiers))
                {
                    throw new ProcedureException(Org.Neo4j.Kernel.Api.Exceptions.Status_Procedure.TypeError, "Field `%s` in record `%s` cannot be accessed. Please ensure the field is marked as `public`.", field.Name, userClass.Name);
                }

                try
                {
                    TypeMappers.TypeChecker checker     = _typeMappers.checkerFor(field.GenericType);
                    MethodHandle            getter      = _lookup.unreflectGetter(field);
                    FieldMapper             fieldMapper = new FieldMapper(getter, checker);

                    fieldMappers[i] = fieldMapper;
                    signature[i]    = FieldSignature.outputField(field.Name, checker.Type(), field.isAnnotationPresent(typeof(Deprecated)));
                }
                catch (ProcedureException e)
                {
                    throw new ProcedureException(e.Status(), e, "Field `%s` in record `%s` cannot be converted to a Neo4j type: %s", field.Name, userClass.Name, e.Message);
                }
                catch (IllegalAccessException e)
                {
                    throw new ProcedureException(Org.Neo4j.Kernel.Api.Exceptions.Status_Procedure.TypeError, e, "Field `%s` in record `%s` cannot be accessed: %s", field.Name, userClass.Name, e.Message);
                }
            }

            return(new OutputMapper(signature, fieldMappers));
        }
Exemplo n.º 2
0
 internal FieldMapper(MethodHandle getter, TypeMappers.TypeChecker checker)
 {
     this.Getter  = getter;
     this.Checker = checker;
 }