private static ISchemaType CacheType <TContextType>(Type propType, MappedSchemaProvider <TContextType> schema) { if (propType.IsEnumerableOrArray()) { propType = propType.GetEnumerableOrArrayType(); } if (!schema.HasType(propType.Name) && !ignoreTypes.Contains(propType.Name)) { var typeInfo = propType.GetTypeInfo(); string description = ""; var d = (DescriptionAttribute)typeInfo.GetCustomAttribute(typeof(DescriptionAttribute), false); if (d != null) { description = d.Description; } if (typeInfo.IsClass || typeInfo.IsInterface) { // add type before we recurse more that may also add the type // dynamcially call generic method // hate this, but want to build the types with the right Genenics so you can extend them later. // this is not the fastest, but only done on schema creation var method = schema.GetType().GetMethod("AddType", new [] { typeof(string), typeof(string) }); method = method.MakeGenericMethod(propType); var t = (ISchemaType)method.Invoke(schema, new object[] { propType.Name, description }); var fields = AddFieldsFromObjectToSchema <TContextType>(propType, schema); t.AddFields(fields); return(t); } else if (typeInfo.IsEnum && !schema.HasType(propType.Name)) { var t = schema.AddEnum(propType.Name, propType, description); return(t); } else if (propType.IsNullableType() && Nullable.GetUnderlyingType(propType).GetTypeInfo().IsEnum&& !schema.HasType(Nullable.GetUnderlyingType(propType).Name)) { Type type = Nullable.GetUnderlyingType(propType); var t = schema.AddEnum(type.Name, type, description); return(t); } } else if (schema.HasType(propType.Name)) { return(schema.Type(propType.Name)); } return(null); }
private static void CacheType <TContextType>(Type propType, MappedSchemaProvider <TContextType> schema) { if (propType.GetTypeInfo().IsGenericType&& propType.IsEnumerable()) { propType = propType.GetGenericArguments()[0]; } if (!schema.HasType(propType.Name) && propType.Name != "String" && (propType.GetTypeInfo().IsClass || propType.GetTypeInfo().IsInterface)) { // add type before we recurse more that may also add the type // dynamcially call generic method var parameters = new List <Expression> { Expression.Constant(propType.Name), Expression.Constant(""), Expression.Constant(null) }; // hate this, but want to build the types with the right Genenics so you can extend them later. // this is not the fastest, but only done on schema creation var method = schema.GetType().GetMethod("AddType", new [] { typeof(string), typeof(string) }); method = method.MakeGenericMethod(propType); var t = (ISchemaType)method.Invoke(schema, new object[] { propType.Name, propType.Name + " description" }); var fields = AddFieldsFromObjectToSchema <TContextType>(propType, schema); t.AddFields(fields); } }