Ejemplo n.º 1
0
 public static bool? DontInitializeAutoQueryCollections(MetadataType type)
 {
     return type.Inherits != null
         && (type.Inherits.Name == "QueryBase`1" || type.Inherits.Name == "QueryDb`1" || type.Inherits.Name == "QueryData`1")
             ? false
             : (bool?)null;
 }
Ejemplo n.º 2
0
 internal static bool ShouldInitializeCollections(this NativeTypesFeature feature, MetadataType type, bool defaultValue)
 {
     return feature.InitializeCollectionsForType != null
         ? feature.InitializeCollectionsForType(type).GetValueOrDefault(defaultValue)
         : defaultValue;
 }
Ejemplo n.º 3
0
 public static List <MetadataRoute> GetRoutes(this List <MetadataOperationType> operations, MetadataType type) =>
 operations.FirstOrDefault(x => ReferenceEquals(x.Request, type))?.Routes ?? operations.GetRoutes(type.Name);
Ejemplo n.º 4
0
 public static bool ImplementsAny(this MetadataType type, params string[] typeNames) =>
 type.Implements != null && type.Implements.Any(i => typeNames.Contains(i.Name));
Ejemplo n.º 5
0
 public static bool InheritsAny(this MetadataType type, params string[] typeNames) =>
 type.Inherits != null && typeNames.Contains(type.Inherits.Name);
Ejemplo n.º 6
0
        public static MetadataType ToType(this Type type)
        {
            if (type == null)
            {
                return(null);
            }

            var metaType = new MetadataType
            {
                Name        = type.Name,
                Namespace   = type.Namespace,
                GenericArgs = type.IsGenericType
                    ? type.GetGenericArguments().Select(x => x.Name).ToArray()
                    : null,
                Attributes = type.ToAttributes(),
                Properties = type.ToProperties(),
            };

            if (type.BaseType != null && type.BaseType != typeof(object))
            {
                metaType.Inherits            = type.BaseType.Name;
                metaType.InheritsGenericArgs = type.BaseType.IsGenericType
                    ? type.BaseType.GetGenericArguments().Select(x => x.Name).ToArray()
                    : null;
            }

            if (type.GetTypeWithInterfaceOf(typeof(IReturnVoid)) != null)
            {
                metaType.ReturnVoidMarker = true;
            }
            else
            {
                var genericMarker = type.GetTypeWithGenericTypeDefinitionOf(typeof(IReturn <>));
                if (genericMarker != null)
                {
                    metaType.ReturnMarkerGenericArgs = genericMarker.GetGenericArguments().Select(x => x.Name).ToArray();
                }
            }

            var typeAttrs  = TypeDescriptor.GetAttributes(type);
            var routeAttrs = typeAttrs.OfType <RouteAttribute>().ToList();

            if (routeAttrs.Count > 0)
            {
                metaType.Routes = routeAttrs.ConvertAll(x =>
                                                        new MetadataRoute
                {
                    Path    = x.Path,
                    Notes   = x.Notes,
                    Summary = x.Summary,
                    Verbs   = x.Verbs,
                });
            }

            var descAttr = typeAttrs.OfType <DescriptionAttribute>().FirstOrDefault();

            if (descAttr != null)
            {
                metaType.Description = descAttr.Description;
            }

            var dcAttr = type.GetDataContract();

            if (dcAttr != null)
            {
                metaType.DataContract = new MetadataDataContract
                {
                    Name      = dcAttr.Name,
                    Namespace = dcAttr.Namespace,
                };
            }

            return(metaType);
        }