示例#1
0
        public Type TranslateType(Type type)
        {
            Type translatedType;

            if (type.IsArray)
            {
                Type elementType = TranslateType(type.GetElementType());
                return(elementType.MakeArrayType());
            }

            if (type.Namespace == FromNamespace)
            {
                ITypeTranslator translator = type.GetCustomTranslator() ?? TypeTranslator;
                translator.TargetNamespace = ToNamespace;
                translator.Verifier        = StructureVerifier;

                translatedType = translator.Translate(type);
            }
            else
            {
                translatedType = type;
            }

            if (type.IsGenericType)
            {
                // TODO add validation so that TypeArguments must match
                Type[] typeArguments = type.GetGenericArguments().Select(TranslateType).ToArray();
                return(translatedType.GetGenericTypeDefinition().MakeGenericType(typeArguments));
            }
            return(translatedType);
        }
 public ValidationASTVisitor(IGraphQLSchema schema)
 {
     this.Schema          = schema;
     this.parentTypeStack = new Stack <GraphQLObjectType>();
     this.typeStack       = new Stack <GraphQLObjectType>();
     this.fieldStack      = new Stack <string>();
     this.argumentTypes   = new Dictionary <string, GraphQLScalarType>();
     this.translator      = schema.TypeTranslator;
 }
示例#3
0
 public SocketListener(ITypeTranslator translator, IModuleHandler[] modules, IAppContext context, IConnTimeoutHandler timeout)
 {
     _modules = modules.ToList();
     _translator = translator;
     _context = context;
     _timeouthandler = timeout;
     System.Timers.Timer _timer = new System.Timers.Timer();
     Timer time = new Timer();
     TimerCallback.
 }
示例#4
0
        public void SetUp()
        {
            this.typeTranslator = Substitute.For <ITypeTranslator>();
            this.schemaObserver = Substitute.For <ISchemaObserver>();
            this.typeTranslator.GetInputType(typeof(int?)).Returns(new GraphQLInt());
            this.typeTranslator.GetType(typeof(int?)).Returns(new GraphQLInt());

            this.complicatedObjectTypeObserver = new ObjectTypeTranslator(new ComplicatedObjectType(), this.typeTranslator, this.schemaObserver);
            this.complicatedArgsObserver       = new ObjectTypeTranslator(new ComplicatedArgs(), this.typeTranslator, this.schemaObserver);
        }
示例#5
0
        public void SetUp()
        {
            dynamic variables = new ExpandoObject();

            variables.scalarIntVariable = "1";

            this.intNamedType     = GetIntNamedType();
            this.typeTranslator   = Substitute.For <ITypeTranslator>();
            this.variableResolver = new VariableResolver(variables, this.typeTranslator, this.GetVariableDefinitions());
        }
示例#6
0
        public void TranslateTypeDoesNotUseTypeTranslatorIfCustomTranslatorIsDefinedOnType()
        {
            ITypeTranslator  translator = Substitute.For <ITypeTranslator>();
            StructureService service    = new StructureService("TestTools_Tests.Structure", "TestTools_Tests.Structure")
            {
                TypeTranslator = translator
            };

            service.TranslateType(typeof(TestTypeWithCustomTranslator));

            translator.DidNotReceive().Translate(typeof(TestTypeWithCustomTranslator));
        }
示例#7
0
        public void TranslateTypeDoesNotUseTypeTranslatorIfTypeIsNotInFromNamespace()
        {
            ITypeTranslator  translator = Substitute.For <ITypeTranslator>();
            StructureService service    = new StructureService("TestTools_Tests.Structure", "TestTools_Tests.Structure")
            {
                TypeTranslator = translator
            };

            service.TranslateType(typeof(object));

            translator.DidNotReceive().Translate(typeof(object));
        }
示例#8
0
        public FieldScope(
            ITypeTranslator typeTranslator,
            IValueResolver valueResolver,
            IFieldCollector fieldCollector,
            GraphQLObjectType type,
            object parent)
        {
            this.type      = type;
            this.parent    = parent;
            this.arguments = new List <GraphQLArgument>();

            this.fieldCollector = fieldCollector;
            this.typeTranslator = typeTranslator;
            this.valueResolver  = valueResolver;
        }
示例#9
0
        public void TranslateMemberUsesMemberTranslatorIfNoCustomTranslatorIsDefinedOnMember()
        {
            Type      typeToTranslate  = typeof(TestTypeWithoutCustomTranslator);
            FieldInfo fieldToTranslate = typeToTranslate.GetField("FieldWithoutCustomTranslator");

            ITypeTranslator typeTranslator = Substitute.For <ITypeTranslator>();

            typeTranslator.Translate(typeToTranslate).Returns(typeToTranslate);
            IMemberTranslator memberTranslator = Substitute.For <IMemberTranslator>();
            StructureService  service          = new StructureService("TestTools_Tests.Structure", "TestTools_Tests.Structure")
            {
                TypeTranslator   = typeTranslator,
                MemberTranslator = memberTranslator
            };

            service.TranslateMember(fieldToTranslate);

            memberTranslator.Received().Translate(fieldToTranslate);
        }
示例#10
0
            private void ObjectMappingInternal(IObjectBuilderContext builderContext, object instance)
            {
                var dict = builderContext.Items[typeof(IObjectMapper)];

                if (dict == null || (!(dict is IDataRecord) && !(dict is IDictionary)))
                {
                    return;
                }

                if (instance is IEntityInitialize)
                {
                    ((IEntityInitialize)instance).InitValues(dict is IDataRecord ? ((IDataRecord)dict).ToDictionary() : (IDictionary)dict);
                    return;
                }

                var setting    = builderContext.ObjectSetting.ConfigSetting;
                var mapSetting = (IObjectMapSetting)setting.ToCachedSetting <ObjectMapSetting>("objectMap");

                if (mapSetting == null)
                {
                    return;
                }

                IEqualityComparer <string> comparer = null;

                if (mapSetting.IgnoreCase)
                {
                    comparer = StringComparer.InvariantCultureIgnoreCase;
                }
                var dictionary = dict is IDataRecord ? ((IDataRecord)dict).ToDictionary(comparer) : ((IDictionary)dict).ToDictionary(comparer);

                var excludeProperties = new List <string>();
                var excludeString     = mapSetting.ExcludeProperties;

                if (excludeString != null)
                {
                    excludeProperties.AddRange(excludeString.Split(','));
                }
                var includeProperties = new List <string>();
                var includeString     = mapSetting.IncludeProperties;

                includeProperties.AddRange(includeString.Split(','));

                var properties = mapSetting.Properties;

                if (properties != null && properties.Length > 0)
                {
                    var             translatorName = mapSetting.TypeTranslatorName;
                    ITypeTranslator translator     = null;
                    if (!string.IsNullOrEmpty(translatorName))
                    {
                        translator = this.ObjectService.GetOrCreateObject <ITypeTranslator>(translatorName);
                    }
                    var propertyInitilize = instance as IPropertyInitialize;
                    foreach (var property in properties)
                    {
                        var columnName = property.ColumnName;
                        if (!dictionary.ContainsKey(columnName))
                        {
                            continue;
                        }
                        var value = dictionary[columnName];
                        if (propertyInitilize != null)
                        {
                            propertyInitilize.SetValue(property.PropertyName, value);
                        }
                        else if (value != null)
                        {
                            if (translator != null)
                            {
                                ReflectionHelper.SetPropertyValue(instance, property.PropertyName, (x, p) => translator.Translate(value, p.MemberType, null));
                            }
                            else
                            {
                                ReflectionHelper.SetPropertyValue(instance, property.PropertyName, value);
                            }
                        }
                        excludeProperties.Add(columnName);
                        includeProperties.Remove(columnName);
                    }
                }
                if (includeProperties.Count > 0)
                {
                    ObjectMapper.RefectionMapping(instance, dictionary, excludeProperties, includeProperties);
                }
            }
示例#11
0
 public Introspector(ITypeTranslator typeTranslator)
 {
     this.typeTranslator = typeTranslator;
 }
示例#12
0
 public void SetUp()
 {
     this.variableResolver = Substitute.For <IVariableResolver>();
     this.typeTranslator   = Substitute.For <ITypeTranslator>();
     this.valueResolver    = new ValueResolver(this.variableResolver, this.typeTranslator);
 }
 public VariableResolver(dynamic variables, ITypeTranslator typeTranslator, IEnumerable <GraphQLVariableDefinition> variableDefinitions)
 {
     this.variables           = ((ExpandoObject)variables).ToDictionary(e => e.Key, e => e.Value);
     this.variableDefinitions = variableDefinitions;
     this.typeTranslator      = typeTranslator;
 }
示例#14
0
 public ValueResolver(IVariableResolver variableResolver, ITypeTranslator typeTranslator)
 {
     this.variableResolver = variableResolver;
     this.typeTranslator   = typeTranslator;
 }
示例#15
0
 public ObjectTypeTranslator(GraphQLNullableType objectType, ITypeTranslator typeTranslator, ISchemaObserver schemaObserver)
 {
     this.objectType     = objectType;
     this.typeTranslator = typeTranslator;
     this.schemaObserver = schemaObserver;
 }