Esempio n. 1
0
        public void IntializeExplicitFieldWithImplicitResolver()
        {
            // arrange
            ServiceManager     services = new ServiceManager();
            List <SchemaError> errors   = new List <SchemaError>();
            SchemaContext      context  = new SchemaContext(services);

            // act
            ObjectType <Foo> fooType = new ObjectType <Foo>(
                d => d.Field(f => f.Description).Name("a"));

            ((INeedsInitialization)fooType).RegisterDependencies(
                context, e => errors.Add(e));
            context.CompleteTypes();

            // assert
            Assert.Empty(errors);
            Assert.NotNull(fooType.Fields.Values.First().Resolver);
        }
Esempio n. 2
0
        protected virtual XamlValueConverter <TypeConverter> LookupTypeConverter()
        {
            XamlValueConverter <TypeConverter> result = null;

            if (AreAttributesAvailable)
            {
                Type converterType = _reflector.GetAttributeType(typeof(TypeConverterAttribute));
                if (converterType != null)
                {
                    result = SchemaContext.GetValueConverter <TypeConverter>(converterType, null);
                }
            }
            if (result == null && this.Type != null)
            {
                result = this.Type.TypeConverter;
            }

            return(result);
        }
        private DirectiveType CreateDirective <T>(T directiveType)
            where T : DirectiveType
        {
            var schemaContext = new SchemaContext();

            schemaContext.Types.RegisterType(new StringType());
            schemaContext.Directives.RegisterDirectiveType(directiveType);

            var schemaConfiguration = new SchemaConfiguration(
                sp => { },
                schemaContext.Types,
                schemaContext.Directives);

            var typeFinalizer = new TypeFinalizer(schemaConfiguration);

            typeFinalizer.FinalizeTypes(schemaContext, null);

            return(schemaContext.Directives.GetDirectiveTypes().Single());
        }
Esempio n. 4
0
        public void NestedGenericObjectTypes()
        {
            // arrange
            var errors        = new List <SchemaError>();
            var schemaContext = new SchemaContext();

            // act
            var genericType           = new ObjectType <GenericFoo <GenericFoo <string> > >();
            INeedsInitialization init = genericType;

            var initializationContext = new TypeInitializationContext(
                schemaContext, a => errors.Add(a), genericType, false);

            init.RegisterDependencies(initializationContext);
            schemaContext.CompleteTypes();

            // assert
            Assert.Equal("GenericFooOfGenericFooOfString", genericType.Name);
        }
Esempio n. 5
0
        public void EnsureObjectTypeKindIsCorret()
        {
            // arrange
            ServiceManager     services = new ServiceManager();
            List <SchemaError> errors   = new List <SchemaError>();
            SchemaContext      context  = new SchemaContext(services);

            ObjectType <Foo> someObject = new ObjectType <Foo>(
                d => d.Field(f => f.Description).Name("a"));

            ((INeedsInitialization)someObject).RegisterDependencies(
                context, e => errors.Add(e));
            context.CompleteTypes();

            // act
            TypeKind kind = someObject.Kind;

            // assert
            Assert.Equal(TypeKind.Object, kind);
        }
Esempio n. 6
0
        string LookupPreferredXamlNamespace()
        {
            var ns = SchemaContext.GetXamlNamespace(type.Namespace);

            if (ns != null)
            {
                return(ns);
            }

            var    assembly     = type.GetTypeInfo().Assembly;
            var    forwarded    = assembly.GetCustomAttributes <TypeForwardedToAttribute>();
            var    forwarded2   = assembly.GetCustomAttributes <TypeForwardedFromAttribute>();
            string assemblyName = assembly.GetName().Name;

            if (mscorlib_assemblies.Contains(assemblyName))
            {
                assemblyName = "mscorlib";
            }
            return($"clr-namespace:{type.Namespace};assembly={assemblyName}");
        }
        public void IntializeImpicitFieldWithImplicitResolver()
        {
            // arrange
            var errors        = new List <SchemaError>();
            var schemaContext = new SchemaContext();

            // act
            var fooType = new ObjectType <Foo>();
            INeedsInitialization init = fooType;

            var initializationContext = new TypeInitializationContext(
                schemaContext, a => errors.Add(a), fooType, false);

            init.RegisterDependencies(initializationContext);
            schemaContext.CompleteTypes();

            // assert
            Assert.Empty(errors);
            Assert.NotNull(fooType.Fields.First().Resolver);
        }
Esempio n. 8
0
        public static Schema Create(
            Action <ISchemaConfiguration> configure,
            bool strict,
            IServiceProvider services)
        {
            if (configure == null)
            {
                throw new ArgumentNullException(nameof(configure));
            }

            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            SchemaContext context = CreateSchemaContext();

            return(CreateSchema(services, context,
                                default(SchemaNames), configure, strict));
        }
        public static void PopulateManagedProperties(Dictionary <string, string> propertyLookup)
        {
            SPSecurity.RunWithElevatedPrivileges(
                delegate
            {
                var ssaProxy = (SearchServiceApplicationProxy)SearchServiceApplicationProxy.GetProxy(SPServiceContext.Current);
                if (ssaProxy.FASTAdminProxy != null)
                {
                    var fastProxy = ssaProxy.FASTAdminProxy;
                    SchemaContext schemaContext = fastProxy.SchemaContext;

                    foreach (ManagedProperty property in
                             schemaContext.Schema.AllManagedProperties.Where(property => property.Queryable))
                    {
                        propertyLookup.Add(property.Name.ToLower(), GetFqlType(property.Type));
                    }
                }
            }
                );
        }
Esempio n. 10
0
        internal static TypeResult <T> CreateType <T>(
            Func <ISchemaContext, T> factory)
            where T : class, INamedType, INeedsInitialization
        {
            var errors        = new List <SchemaError>();
            var schemaContext = new SchemaContext();

            var type = factory(schemaContext);

            schemaContext.Types.RegisterType(type);

            var initializationContext = new TypeInitializationContext(
                schemaContext, a => errors.Add(a), type, false);

            type.RegisterDependencies(initializationContext);

            schemaContext.CompleteTypes();

            return(new TypeResult <T>(type, errors));
        }
Esempio n. 11
0
        IEnumerable <XamlMember> DoLookupAllMembers()
        {
            // This is a hack that is likely required due to internal implementation difference in System.Uri. Our Uri has two readonly collection properties
            if (ReferenceEquals(this, XamlLanguage.Uri))
            {
                yield break;
            }

            //var bf = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;

            foreach (var pi in UnderlyingType.GetRuntimeProperties())
            {
                if (pi.GetPrivateGetMethod()?.IsStatic ?? pi.GetPrivateSetMethod()?.IsStatic ?? false)
                {
                    continue;
                }
                if (pi.Name.Contains("."))                 // exclude explicit interface implementations.
                {
                    continue;
                }
                if (                /*pi.CanRead &&*/
                    (
                        pi.CanWrite ||
                        IsCollectionType(pi.PropertyType)
#if NETSTANDARD1_0
                        || (ReflectionHelpers.IXmlSerializableType?.GetTypeInfo().IsAssignableFrom(pi.PropertyType.GetTypeInfo()) ?? false)
#else
                        || typeof(IXmlSerializable).GetTypeInfo().IsAssignableFrom(pi.PropertyType.GetTypeInfo())
#endif
                        || pi.GetCustomAttribute <ConstructorArgumentAttribute>() != null
                    ) &&
                    pi.GetIndexParameters().Length == 0)
                {
                    yield return(SchemaContext.GetProperty(pi));
                }
            }
            foreach (var ei in UnderlyingType.GetRuntimeEvents())
            {
                yield return(SchemaContext.GetEvent(ei));
            }
        }
Esempio n. 12
0
        public async Task FieldMiddlewareIsIntegrated()
        {
            // arrange
            var resolverContext = new Mock <IMiddlewareContext>();

            resolverContext.SetupAllProperties();

            var errors        = new List <SchemaError>();
            var schemaContext = new SchemaContext();
            var stringType    = new StringType();

            schemaContext.Types.RegisterType(stringType);
            schemaContext.Resolvers.RegisterMiddleware(next => async context =>
            {
                await next(context);

                if (context.Result is string s)
                {
                    context.Result = s.ToUpperInvariant();
                }
            });

            // act
            var fooType = new ObjectType(c =>
                                         c.Name("Foo").Field("bar").Resolver(() => "baz"));

            // assert
            schemaContext.Types.RegisterType(fooType);
            var initializationContext = new TypeInitializationContext(
                schemaContext, a => errors.Add(a), fooType, false);

            ((INeedsInitialization)fooType)
            .RegisterDependencies(initializationContext);
            schemaContext.CompleteTypes();

            Assert.Empty(errors);

            await fooType.Fields["bar"].Middleware(resolverContext.Object);

            Assert.Equal("BAZ", resolverContext.Object.Result);
        }
        public void CreateCostDirective()
        {
            // arrange
            SchemaContext schemaContext = SchemaContextFactory.Create();

            var schemaConfiguration = new SchemaConfiguration(
                sp => { },
                schemaContext.Types,
                schemaContext.Resolvers,
                schemaContext.Directives);

            var typeFinalizer = new TypeFinalizer(schemaConfiguration);

            typeFinalizer.FinalizeTypes(schemaContext, null);

            // assert
            DirectiveType directive = schemaContext.Directives
                                      .GetDirectiveTypes()
                                      .FirstOrDefault(t => t.Name == "cost");

            // assert
            Assert.NotNull(directive);
            Assert.IsType <CostDirectiveType>(directive);
            Assert.Equal("cost", directive.Name);
            Assert.Collection(directive.Arguments,
                              t =>
            {
                Assert.Equal("complexity", t.Name);
                Assert.IsType <IntType>(
                    Assert.IsType <NonNullType>(t.Type).Type);
            },
                              t =>
            {
                Assert.Equal("multipliers", t.Name);
                Assert.IsType <MultiplierPathType>(
                    Assert.IsType <NonNullType>(
                        Assert.IsType <ListType>(t.Type).ElementType).Type);
            });
            Assert.Collection(directive.Locations,
                              t => Assert.Equal(DirectiveLocation.FieldDefinition, t));
        }
Esempio n. 14
0
        public void IgnoreFieldsFromClrInterface()
        {
            // arrange
            var errors        = new List <SchemaError>();
            var schemaContext = new SchemaContext();

            schemaContext.Types.RegisterType(new BooleanType());
            schemaContext.Types.RegisterType(new StringType());
            schemaContext.Types.RegisterType(new IntType());

            // act
            var fooType = new InterfaceType <IFoo>(t => t.Ignore(p => p.Bar));

            schemaContext.Types.RegisterType(fooType);

            INeedsInitialization init = fooType;
            var initializationContext = new TypeInitializationContext(
                schemaContext, a => errors.Add(a), fooType, false);

            init.RegisterDependencies(initializationContext);

            schemaContext.CompleteTypes();

            // assert
            Assert.Empty(errors);
            Assert.Collection(
                fooType.Fields.Where(t => !t.IsIntrospectionField),
                t =>
            {
                Assert.Equal("baz", t.Name);
                Assert.IsType <StringType>(t.Type);
            },
                t =>
            {
                Assert.Equal("qux", t.Name);
                Assert.IsType <IntType>(
                    Assert.IsType <NonNullType>(t.Type).Type);
                Assert.Collection(t.Arguments,
                                  a => Assert.Equal("a", a.Name));
            });
        }
Esempio n. 15
0
        private void CompleteType(
            INamedType namedType,
            Action <SchemaContext> configure = null)
        {
            var schemaContext = new SchemaContext();

            schemaContext.Types.RegisterType(new StringType());
            schemaContext.Types.RegisterType(namedType);

            if (configure != null)
            {
                configure(schemaContext);
            }

            var initializationContext = new TypeInitializationContext(
                schemaContext, error => { }, namedType, false);

            ((INeedsInitialization)namedType)
            .RegisterDependencies(initializationContext);
            schemaContext.CompleteTypes();
        }
Esempio n. 16
0
        private static SchemaContext CreateSchemaContext()
        {
            // create context with system types
            SchemaContext context = new SchemaContext();

            context.Types.RegisterType(typeof(StringType));
            context.Types.RegisterType(typeof(BooleanType));
            context.Types.RegisterType(typeof(IntType));

            // register introspection types
            context.Types.RegisterType(typeof(__Directive));
            context.Types.RegisterType(typeof(__DirectiveLocation));
            context.Types.RegisterType(typeof(__EnumValue));
            context.Types.RegisterType(typeof(__Field));
            context.Types.RegisterType(typeof(__InputValue));
            context.Types.RegisterType(typeof(__Schema));
            context.Types.RegisterType(typeof(__Type));
            context.Types.RegisterType(typeof(__TypeKind));

            return(context);
        }
Esempio n. 17
0
        private void ProcessOneOfKeyword(JsonPointer path, OneOfKeyword keyword, SchemaContext context)
        {
            // A oneOf keyword with only one subschema which isn't null makes it required
            if (KeywordHasSingleNonNullSchema(keyword))
            {
                AddRequiredProperties(context.Id, new List <string>()
                {
                    context.Name
                });
            }

            int subSchemaIndex = 0;

            foreach (var subSchema in keyword.GetSubschemas())
            {
                var subSchemaPath = path.Combine(JsonPointer.Parse($"/[{subSchemaIndex}]"));
                ProcessSubSchema(subSchemaPath, subSchema, context);

                subSchemaIndex++;
            }
        }
Esempio n. 18
0
        protected virtual IList <XamlType> LookupContentWrappers()
        {
            if (GetCustomAttributeProvider() == null)
            {
                return(null);
            }

            var arr = GetCustomAttributeProvider().GetCustomAttributes(typeof(ContentWrapperAttribute), false);

            if (arr == null || arr.Length == 0)
            {
                return(null);
            }
            var l = new XamlType [arr.Length];

            for (int i = 0; i < l.Length; i++)
            {
                l [i] = SchemaContext.GetXamlType(((ContentWrapperAttribute)arr [i]).ContentWrapper);
            }
            return(l);
        }
Esempio n. 19
0
        /// <summary>
        /// Построить схему корневого DPC-контента и набор ссылок на повторяющиеся контенты
        /// </summary>
        private ProductSchema GetProductSchema(ContentSchema contentSchema, SchemaContext context)
        {
            context.DefinitionNamesBySchema = context.RepeatedSchemas
                                              .GroupBy(schema => String.IsNullOrEmpty(schema.ContentName)
                    ? $"Content{schema.ContentId}"
                    : schema.ContentName)
                                              .SelectMany(group => group.Select((schema, i) => new
            {
                Key   = schema,
                Value = $"{group.Key}{(i == 0 ? "" : i.ToString())}",
            }))
                                              .ToDictionary(pair => pair.Key, pair => pair.Value);

            return(new ProductSchema
            {
                Content = DeduplicateContentSchema(contentSchema, context, new HashSet <ContentSchema>()),

                Definitions = context.DefinitionNamesBySchema
                              .ToDictionary(pair => pair.Value, pair => pair.Key),
            });
        }
Esempio n. 20
0
        protected virtual XamlValueConverter <TypeConverter> LookupTypeConverter()
        {
            var t = UnderlyingType;

            if (t == null)
            {
                return(null);
            }

            // equivalent to TypeExtension.
            // FIXME: not sure if it should be specially handled here.
            if (t == typeof(Type))
            {
                t = typeof(TypeExtension);
            }

            var a  = GetCustomAttributeProvider();
            var ca = a != null?a.GetCustomAttribute <TypeConverterAttribute> (false) : null;

            if (ca != null)
            {
                return(SchemaContext.GetValueConverter <TypeConverter> (Type.GetType(ca.ConverterTypeName), this));
            }

            if (t == typeof(object))              // This is a special case. ConverterType is null.
            {
                return(SchemaContext.GetValueConverter <TypeConverter> (null, this));
            }

            // It's still not decent to check CollectionConverter.
            var tct = t.GetTypeConverter().GetType();

#if MOONLIGHT
            if (tct != typeof(TypeConverter) && tct.Name != "CollectionConverter" && tct.Name != "ReferenceConverter")
#else
            if (tct != typeof(TypeConverter) && tct != typeof(CollectionConverter) && tct != typeof(ReferenceConverter))
#endif
            { return(SchemaContext.GetValueConverter <TypeConverter> (tct, this)); }
            return(null);
        }
        public void Initialize_IgnoreProperty_PropertyIsNotInSchemaType()
        {
            // arrange
            var errors        = new List <SchemaError>();
            var schemaContext = new SchemaContext();

            // act
            var fooType = new InputObjectType <SimpleInput>(
                d => d.Field(f => f.Id).Ignore());
            INeedsInitialization init = fooType;

            // assert
            var initializationContext = new TypeInitializationContext(
                schemaContext, a => errors.Add(a), fooType, false);

            init.RegisterDependencies(initializationContext);
            schemaContext.CompleteTypes();

            Assert.Empty(errors);
            Assert.Collection(fooType.Fields,
                              t => Assert.Equal("name", t.Name));
        }
        protected override IList <XamlType> LookupPositionalParameters(int paramCount)
        {
            if (this.IsMarkupExtension)
            {
                List <XamlType>      xTypes = null;
                Baml6ConstructorInfo info   = Constructors[paramCount];
                if (Constructors.TryGetValue(paramCount, out info))
                {
                    xTypes = new List <XamlType>();
                    foreach (Type type in info.Types)
                    {
                        xTypes.Add(SchemaContext.GetXamlType(type));
                    }
                }

                return(xTypes);
            }
            else
            {
                return(base.LookupPositionalParameters(paramCount));
            }
        }
        private XamlMember CreateXamlProperty(PropertyDescriptor property, bool skipReadOnlyCheck)
        {
            XamlType declaringType = this;

            if (property.IsReadOnly)
            {
                if (!skipReadOnlyCheck && !AllowAsReadOnly(property))
                {
                    return(null);
                }

                // The property might actually be defined on a base type, but not returned by
                // GetInheritedMember because it is read-only.
                // If so, we should set its declaringType to the base type.
                if (skipReadOnlyCheck && property.ComponentType != UnderlyingType &&
                    TypeDescriptor.GetProperties(property.ComponentType)[property.Name] == property)
                {
                    declaringType = SchemaContext.GetXamlType(property.ComponentType);
                }
            }
            return(new PropertyDescriptorXamlMember(property, declaringType));
        }
Esempio n. 24
0
        public virtual IList <string> GetXamlNamespaces()
        {
            // not quite sure if this is correct, but matches documentation to get all namespaces that type exists in
            var list = new List <string>();

            if (!string.IsNullOrEmpty(explicit_ns))
            {
                list.Add(explicit_ns);
            }

            if (type != null)
            {
                // type always exists in clr namespace
                list.Add(string.Format("clr-namespace:{0};assembly={1}", type.Namespace, type.GetTypeInfo().Assembly.GetName().Name));

                // check if it's a built-in type
                if (XamlLanguage.AllTypes.Any(r => r.UnderlyingType == type))
                {
                    list.Add(XamlLanguage.Xaml2006Namespace);
                }

                // check all other registered namespaces (may duplicate for built-in types, such as xaml markup extensions)
                foreach (var ns in SchemaContext.GetAllXamlNamespaces())
                {
                    if (SchemaContext.GetAllXamlTypes(ns).Any(r => r.UnderlyingType == type))
                    {
                        list.Add(ns);
                    }
                }
            }
            if (list.Count == 0)
            {
                return new [] { string.Empty }
            }
            ;

            return(new ReadOnlyCollection <string> (list));
        }
        public XamlObjectReader(object instance, XamlSchemaContext schemaContext, XamlObjectReaderSettings settings)
        {
            if (schemaContext == null)
            {
                throw new ArgumentNullException("schemaContext");
            }
            // FIXME: special case? or can it be generalized? In .NET, For Type instance Instance returns TypeExtension at root StartObject, while for Array it remains to return Array.
            if (instance is Type)
            {
                instance = new TypeExtension((Type)instance);
            }

            // See also Instance property for this weirdness.
            this.root_raw = instance;
            instance      = TypeExtensionMethods.GetExtensionWrapped(instance);
            this.root     = instance;

            sctx          = schemaContext;
            this.settings = settings ?? new XamlObjectReaderSettings();

            // check type validity. Note that some checks also needs done at Read() phase. (it is likely FIXME:)
            if (instance != null)
            {
                var type = new InstanceContext(instance).GetRawValue().GetType();
                if (!type.GetTypeInfo().IsPublic)
                {
                    throw new XamlObjectReaderException(String.Format("instance type '{0}' must be public and non-nested.", type));
                }
                var xt = SchemaContext.GetXamlType(type);
                if (xt.ConstructionRequiresArguments && xt.GetConstructorArguments().Count == 0 && xt.TypeConverter == null)
                {
                    throw new XamlObjectReaderException(String.Format("instance type '{0}' has no default constructor.", type));
                }
            }

            value_serializer_context = new ValueSerializerContext(new PrefixLookup(sctx), sctx, null, null, null, null);
            new XamlObjectNodeIterator(instance, sctx, value_serializer_context, this.settings).PrepareReading();
        }
Esempio n. 26
0
        public override IEnumerable <DynamicPropertyInfo> GetStructuralProperties(String tableName)
        {
            SchemaContext schemaContext = _dbContextPool.Rent();

            foreach (DbColumn column in schemaContext.GetColumns(tableName))
            {
                DatabaseGeneratedOption databaseGenerated;
                if (column.IsIdentity.GetValueOrDefault())
                {
                    databaseGenerated = DatabaseGeneratedOption.Identity;
                }
                else if (column.IsExpression.GetValueOrDefault())
                {
                    databaseGenerated = DatabaseGeneratedOption.Computed;
                }
                else
                {
                    databaseGenerated = DatabaseGeneratedOption.None;
                }
                yield return(new DynamicPropertyInfo(column.ColumnName, column.DataType, databaseGenerated));
            }
            _dbContextPool.Return(schemaContext);
        }
Esempio n. 27
0
        /// <summary>
        /// Заменить повторяющиеся объекты <see cref="ContentSchema"/> на ссылки <see cref="ContentSchemaJsonRef"/>
        /// </summary>
        private IContentSchema DeduplicateContentSchema(
            IContentSchema schema, SchemaContext context, HashSet <ContentSchema> visitedSchemas)
        {
            if (schema is ContentSchema contentSchema)
            {
                if (visitedSchemas.Contains(contentSchema))
                {
                    return(GetSchemaRef(contentSchema, context));
                }

                visitedSchemas.Add(contentSchema);

                foreach (FieldSchema fieldSchema in contentSchema.Fields.Values)
                {
                    if (fieldSchema is RelationFieldSchema relationSchema)
                    {
                        relationSchema.RelatedContent = DeduplicateContentSchema(
                            relationSchema.RelatedContent, context, visitedSchemas);
                    }
                    else if (fieldSchema is ExtensionFieldSchema extensionSchema)
                    {
                        foreach (var pair in extensionSchema.ExtensionContents.ToArray())
                        {
                            extensionSchema.ExtensionContents[pair.Key] = DeduplicateContentSchema(
                                pair.Value, context, visitedSchemas);
                        }
                    }
                }

                if (context.RepeatedSchemas.Contains(contentSchema))
                {
                    return(GetSchemaRef(contentSchema, context));
                }
            }

            return(schema);
        }
Esempio n. 28
0
        [Fact] // Issue #931
        public async Task Can_save_and_query_with_schema()
        {
            var serviceProvider
                = new ServiceCollection()
                  .AddEntityFrameworkSqlServer()
                  .BuildServiceProvider();

            using (var testDatabase = await SqlServerTestStore.CreateScratchAsync())
            {
                await testDatabase.ExecuteNonQueryAsync("CREATE SCHEMA Apple");

                await testDatabase.ExecuteNonQueryAsync("CREATE TABLE Apple.Jack (MyKey int)");

                await testDatabase.ExecuteNonQueryAsync("CREATE TABLE Apple.Black (MyKey int)");

                using (var context = new SchemaContext(serviceProvider))
                {
                    context.Connection = testDatabase.Connection;

                    context.Add(new Jack {
                        MyKey = 1
                    });
                    context.Add(new Black {
                        MyKey = 2
                    });
                    context.SaveChanges();
                }

                using (var context = new SchemaContext(serviceProvider))
                {
                    context.Connection = testDatabase.Connection;

                    Assert.Equal(1, context.Jacks.Count());
                    Assert.Equal(1, context.Blacks.Count());
                }
            }
        }
Esempio n. 29
0
        protected virtual IList <XamlType> LookupPositionalParameters(int parameterCount)
        {
            if (UnderlyingType == null /* || !IsMarkupExtension*/)            // see nunit tests...
            {
                return(null);
            }

            // check if there is applicable ConstructorArgumentAttribute.
            // If there is, then return its type.
            if (parameterCount == 1)
            {
                foreach (var xm in GetAllMembers())
                {
                    var ca = xm.GetCustomAttributeProvider().GetCustomAttribute <ConstructorArgumentAttribute> (false);
                    if (ca != null)
                    {
                        return new XamlType [] { xm.Type }
                    }
                    ;
                }
            }

            var methods = (from m in UnderlyingType.GetConstructors(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) where m.GetParameters().Length == parameterCount select m).ToArray();

            if (methods.Length == 1)
            {
                return((from p in methods [0].GetParameters() select SchemaContext.GetXamlType(p.ParameterType)).ToArray());
            }

            if (SchemaContext.SupportMarkupExtensionsWithDuplicateArity)
            {
                throw new NotSupportedException("The default LookupPositionalParameters implementation does not allow duplicate arity of markup extensions");
            }
            return(null);
        }

        BindingFlags flags_get_static = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static;
Esempio n. 30
0
        public void IntializeExplicitFieldWithImplicitResolver()
        {
            // arrange
            var errors        = new List <SchemaError>();
            var schemaContext = new SchemaContext();

            // act
            var nodeInterface = new NodeType();

            // assert
            INeedsInitialization init = nodeInterface;
            var initializationContext = new TypeInitializationContext(
                schemaContext, a => errors.Add(a), nodeInterface, false);

            schemaContext.Types.RegisterType(nodeInterface);
            init.RegisterDependencies(initializationContext);
            schemaContext.CompleteTypes();

            Assert.Empty(errors);

            Assert.Equal(
                "Node",
                nodeInterface.Name);

            Assert.Equal(
                "The node interface is implemented by entities that have " +
                "a gloabl unique identifier.",
                nodeInterface.Description);

            Assert.Collection(nodeInterface.Fields,
                              t =>
            {
                Assert.Equal("id", t.Name);
                Assert.IsType <IdType>(
                    Assert.IsType <NonNullType>(t.Type).Type);
            });
        }