/// <summary> /// Initializes a new instance of the <see cref="ConnectorInfo"/>. /// </summary> /// <param name="adapterType">The type of transaction or market data adapter.</param> public ConnectorInfo(Type adapterType) { if (adapterType == null) throw new ArgumentNullException("adapterType"); if (!typeof(IMessageAdapter).IsAssignableFrom(adapterType)) throw new ArgumentException("adapterType"); AdapterType = adapterType; Name = adapterType.GetDisplayName(); Description = adapterType.GetDescription(); Category = adapterType.GetCategory(LocalizedStrings.Str1559); var targetPlatform = adapterType.GetAttribute<TargetPlatformAttribute>(); if (targetPlatform != null) { PreferLanguage = targetPlatform.PreferLanguage; Platform = targetPlatform.Platform; } else { PreferLanguage = Languages.English; Platform = Platforms.AnyCPU; } }
public DatabaseProviderInfo(Type type) { Description = type.GetDescription(); RequiresConnectionStringBuilding = type.GetCustomAttribute<NoConnectionStringBuilderAttribute>() == null; TypeName = type.FullName; }
public TaskInfo(Type task) { if (task == null) throw new ArgumentNullException(nameof(task)); Task = task; Name = task.GetDisplayName(); Description = task.GetDescription(); Icon = task.GetIcon(); }
protected static void EnsureType(Type implementationType, Type serviceType, bool assertImplementation = true) { if (assertImplementation && (!implementationType.IsClass || implementationType.IsAbstract)) throw new StyletIoCRegistrationException(String.Format("Type {0} is not a concrete class, and so can't be used to implemented service {1}", implementationType.GetDescription(), serviceType.GetDescription())); // Test this first, as it's a bit clearer than hitting 'type doesn't implement service' if (assertImplementation && implementationType.IsGenericTypeDefinition) { if (!serviceType.IsGenericTypeDefinition) throw new StyletIoCRegistrationException(String.Format("You can't use an unbound generic type to implement anything that isn't an unbound generic service. Service: {0}, Type: {1}", serviceType.GetDescription(), implementationType.GetDescription())); // This restriction may change when I figure out how to pass down the correct type argument if (serviceType.GetTypeInfo().GenericTypeParameters.Length != implementationType.GetTypeInfo().GenericTypeParameters.Length) throw new StyletIoCRegistrationException(String.Format("If you're registering an unbound generic type to an unbound generic service, both service and type must have the same number of type parameters. Service: {0}, Type: {1}", serviceType.GetDescription(), implementationType.GetDescription())); } else if (serviceType.IsGenericTypeDefinition) { if (implementationType.GetGenericArguments().Length > 0) throw new StyletIoCRegistrationException(String.Format("You cannot bind the bound generic type {0} to the unbound generic service {1}", implementationType.GetDescription(), serviceType.GetDescription())); else throw new StyletIoCRegistrationException(String.Format("You cannot bind the non-generic type {0} to the unbound generic service {1}", implementationType.GetDescription(), serviceType.GetDescription())); } if (!implementationType.Implements(serviceType)) throw new StyletIoCRegistrationException(String.Format("Type {0} does not implement service {1}", implementationType.GetDescription(), serviceType.GetDescription())); }
protected void CreateRestPaths(List<RestService> apis, Type operationType, String operationName) { var map = EndpointHost.ServiceManager.ServiceController.RestPathMap; var paths = new List<string>(); foreach (var key in map.Keys) { paths.AddRange(map[key].Where(x => x.RequestType == operationType).Select(t => resourcePathCleanerRegex.Match(t.Path).Value)); } if (paths.Count == 0) return; var minPath = paths.Min(); if (string.IsNullOrEmpty(minPath) || minPath == "/") return; apis.Add(new RestService { Path = string.Concat("/resource", minPath), Description = operationType.GetDescription() }); }
protected void CreateRestPaths(List<RestService> apis, Type operationType, String operationName) { var map = EndpointHost.ServiceManager.ServiceController.RestPathMap; var paths = new List<string>(); foreach (var key in map.Keys) { paths.AddRange(map[key].Where(x => x.RequestType == operationType).Select(t => resourcePathCleanerRegex.Match(t.Path).Value)); } if (paths.Count == 0) return; var basePaths = paths.Select(t => string.IsNullOrEmpty(t) ? null : t.Split('/')) .Where(t => t != null && t.Length > 1) .Select(t => t[1]); foreach (var bp in basePaths) { if (string.IsNullOrEmpty(bp)) return; if (apis.All(a => a.Path != string.Concat(RESOURCE_PATH, "/" + bp))) { apis.Add(new RestService { Path = string.Concat(RESOURCE_PATH, "/" + bp), Description = operationType.GetDescription() }); } } }
public MetadataType ToType(Type type) { if (type == null) return null; if (type.IsGenericType()) type = type.GetGenericTypeDefinition(); var metaType = new MetadataType { Name = type.GetOperationName(), Namespace = type.Namespace, GenericArgs = type.IsGenericType() ? GetGenericArgs(type) : null, Implements = ToInterfaces(type), Attributes = ToAttributes(type), Properties = ToProperties(type), IsNested = type.IsNested ? true : (bool?)null, IsEnum = type.IsEnum() ? true : (bool?)null, IsEnumInt = JsConfig.TreatEnumAsInteger || type.IsEnumFlags() ? true : (bool?)null, IsInterface = type.IsInterface() ? true : (bool?)null, IsAbstract = type.IsAbstract() ? true : (bool?)null, }; if (type.BaseType() != null && type.BaseType() != typeof(object) && !type.IsEnum() && !type.HasInterface(typeof(IService))) { metaType.Inherits = ToTypeName(type.BaseType()); } if (type.GetTypeWithInterfaceOf(typeof(IReturnVoid)) != null) { metaType.ReturnVoidMarker = true; } else { var genericMarker = type != typeof(IReturn<>) ? type.GetTypeWithGenericTypeDefinitionOf(typeof(IReturn<>)) : null; if (genericMarker != null) { var returnType = genericMarker.GetGenericArguments().First(); metaType.ReturnMarkerTypeName = ToTypeName(returnType); } } var routeAttrs = HostContext.AppHost.GetRouteAttributes(type).ToList(); if (routeAttrs.Count > 0) { metaType.Routes = routeAttrs.ConvertAll(x => new MetadataRoute { Path = x.Path, Notes = x.Notes, Summary = x.Summary, Verbs = x.Verbs, }); } metaType.Description = type.GetDescription(); var dcAttr = type.GetDataContract(); if (dcAttr != null) { metaType.DataContract = new MetadataDataContract { Name = dcAttr.Name, Namespace = dcAttr.Namespace, }; } if (type.IsEnum()) { metaType.EnumNames = new List<string>(); metaType.EnumValues = new List<string>(); var isDefaultLayout = true; var values = Enum.GetValues(type); for (var i = 0; i < values.Length; i++) { var value = values.GetValue(i); var name = value.ToString(); var enumValue = Convert.ToInt64(value).ToString(); if (enumValue != i.ToString()) isDefaultLayout = false; metaType.EnumNames.Add(name); metaType.EnumValues.Add(enumValue); } if (isDefaultLayout) metaType.EnumValues = null; } var innerTypes = type.GetNestedTypes(BindingFlags.Public | BindingFlags.NonPublic); foreach (var innerType in innerTypes) { if (metaType.InnerTypes == null) metaType.InnerTypes = new List<MetadataTypeName>(); metaType.InnerTypes.Add(new MetadataTypeName { Name = innerType.GetOperationName(), Namespace = innerType.Namespace, GenericArgs = innerType.IsGenericType() ? innerType.GetGenericArguments().Select(x => x.GetOperationName()).ToArray() : null, }); } return metaType; }
public MetadataType ToType(Type type) { if (type == null) return null; var metaType = new MetadataType { Name = type.GetOperationName(), Namespace = type.Namespace, GenericArgs = type.IsGenericType ? type.GetGenericArguments().Select(x => x.GetOperationName()).ToArray() : null, Attributes = ToAttributes(type), Properties = ToProperties(type), }; if (type.BaseType != null && type.BaseType != typeof(object)) { metaType.Inherits = new MetadataTypeName { Name = type.BaseType.GetOperationName(), GenericArgs = type.BaseType.IsGenericType ? type.BaseType.GetGenericArguments().Select(x => x.GetOperationName()).ToArray() : null }; } if (type.GetTypeWithInterfaceOf(typeof(IReturnVoid)) != null) { metaType.ReturnVoidMarker = true; } else { var genericMarker = type.GetTypeWithGenericTypeDefinitionOf(typeof(IReturn<>)); if (genericMarker != null) { metaType.ReturnMarkerTypeName = ToTypeName(genericMarker.GetGenericArguments().First()); } } var routeAttrs = HostContext.AppHost.GetRouteAttributes(type).ToList(); if (routeAttrs.Count > 0) { metaType.Routes = routeAttrs.ConvertAll(x => new MetadataRoute { Path = x.Path, Notes = x.Notes, Summary = x.Summary, Verbs = x.Verbs, }); } metaType.Description = type.GetDescription(); var dcAttr = type.GetDataContract(); if (dcAttr != null) { metaType.DataContract = new MetadataDataContract { Name = dcAttr.Name, Namespace = dcAttr.Namespace, }; } return metaType; }