public void Dispose() { var toDispose = BeginDispose(); if (toDispose != null) { for (var i = toDispose.Count - 1; i >= 0; i--) { if (toDispose[i] is IDisposable disposable) { disposable.Dispose(); } else { throw new InvalidOperationException(Resources.FormatAsyncDisposableServiceDispose(TypeNameHelper.GetTypeDisplayName(toDispose[i]))); } } } }
public ISortInputTypeDescriptor <T> DependsOn(Type schemaType) { TypeNameHelper.AddNameFunction( _descriptor, _createName, schemaType); return(_descriptor); }
public void Can_pretty_print_open_generics(Type type, bool fullName, string expected) { Assert.Equal(expected, TypeNameHelper.GetTypeDisplayName(type, fullName)); }
public void Can_pretty_print_CLR_name(Type type, string expected) { Assert.Equal(expected, TypeNameHelper.GetTypeDisplayName(type, false)); }
internal static object GetDroppedObjectInstance(DependencyObject dropTarget, EditingContext context, Type type, IDataObject dataObject) { if (type != null) { //check if type is generic if (type.IsGenericTypeDefinition) { type = ResolveGenericParameters(dropTarget, context, type); } } object droppedObject = null; if (null != type) { try { droppedObject = Activator.CreateInstance(type); if (type.IsActivityTemplateFactory() && type.IsClass) { //find parent WorkflowViewElement - in case of mouse drop, current drop target most likely is ISourceContainer if (!(dropTarget is WorkflowViewElement)) { dropTarget = VisualTreeUtils.FindVisualAncestor <WorkflowViewElement>(dropTarget); } Type templateFactoryInterface2 = type.GetInterface(typeof(IActivityTemplateFactory <>).FullName); if (templateFactoryInterface2 != null) { droppedObject = templateFactoryInterface2.InvokeMember("Create", BindingFlags.InvokeMethod, null, droppedObject, new object[] { dropTarget, dataObject }, CultureInfo.InvariantCulture); } else if (droppedObject is IActivityTemplateFactory) { droppedObject = ((IActivityTemplateFactory)droppedObject).Create(dropTarget); } } // SQM: Log activity usage count ActivityUsageCounter.ReportUsage(context.Services.GetService <IVSSqmService>(), type); } catch (Exception ex) { if (Fx.IsFatal(ex)) { throw; } string details = ex.Message; if (ex is TargetInvocationException && ex.InnerException != null) { details = ex.InnerException.Message; } ErrorReporting.ShowErrorMessage(string.Format(CultureInfo.CurrentUICulture, SR.CannotCreateInstance, TypeNameHelper.GetDisplayName(type, false)), details); } } return(droppedObject); }
public void Returns_common_name_for_built_in_types(Type type, string expected) { Assert.Equal(expected, TypeNameHelper.GetTypeDisplayName(type)); }
internal static MethodDisplayInfo GetMethodDisplayString(MethodBase method) { // Special case: no method available if (method == null) { return(null); } var methodDisplayInfo = new MethodDisplayInfo(); // Type name var type = method.DeclaringType; if (type != null) { methodDisplayInfo.DeclaringTypeName = TypeNameHelper.GetTypeDisplayName(type); } // Method name methodDisplayInfo.Name = method.Name; if (method.IsGenericMethod) { var genericArguments = string.Join(", ", method.GetGenericArguments() .Select(arg => TypeNameHelper.GetTypeDisplayName(arg, fullName: false))); methodDisplayInfo.GenericArguments += "<" + genericArguments + ">"; } // Method parameters methodDisplayInfo.Parameters = method.GetParameters().Select(parameter => { var parameterType = parameter.ParameterType; var prefix = string.Empty; if (parameter.IsOut) { prefix = "out"; } else if (parameterType != null && parameterType.IsByRef) { prefix = "ref"; } var parameterTypeString = "?"; if (parameterType != null) { if (parameterType.IsByRef) { parameterType = parameterType.GetElementType(); } parameterTypeString = TypeNameHelper.GetTypeDisplayName(parameterType, fullName: false); } return(new ParameterDisplayInfo { Prefix = prefix, Name = parameter.Name, Type = parameterTypeString, }); }); return(methodDisplayInfo); }
// Pretty print the type name private string S(Type type) => TypeNameHelper.GetTypeDisplayName(type);
public ICache CreateCache <T>(string suffix = "") { return(CreateCache(TypeNameHelper.GetTypeDisplayName(typeof(T), fullName: true) + suffix)); }
public void Dispose() { List <object> toDispose = BeginDispose(); if (toDispose != null) { for (int i = toDispose.Count - 1; i >= 0; i--) { if (toDispose[i] is IDisposable disposable) { disposable.Dispose(); } else { throw new InvalidOperationException(SR.Format(SR.AsyncDisposableServiceDispose, TypeNameHelper.GetTypeDisplayName(toDispose[i]))); } } } ClearState(); }
private string CreateCircularDependencyExceptionMessage(Type type) { var messageBuilder = new StringBuilder(); messageBuilder.AppendFormat($"A circular dependency was detected for the service of type '{TypeNameHelper.GetTypeDisplayName(type)}'."); messageBuilder.AppendLine(); AppendResolutionPath(messageBuilder, type); return(messageBuilder.ToString()); }
public async Task <bool> PerformTest() { try { var metadata = await _retriever.LoadMetadata(); var t = new[] { "Resources", "Descriptors" }; foreach (var key in metadata.Keys.Where(k => t.Contains(k))) { var doc = metadata[key]; _swaggerDocuments[key] = doc; var uniqueSchemaNames = doc.paths.Keys .Select(GetSchemaNameFromPath) .Distinct() .ToList(); foreach (var path in doc.paths) { if (_resources.ContainsKey(path.Key)) { continue; } _resources[path.Key] = new Resource { Name = GetResoucePath(path.Key, path.Value), BasePath = doc.basePath, Path = path.Value, Schema = GetSchemaNameFromPath(path.Key), Definition = doc .definitions .FirstOrDefault( d => TypeNameHelper.CompareTypeNames(path.Key, d.Key, "_", uniqueSchemaNames)) .Value }; } foreach (var definition in doc.definitions) { if (_entities.ContainsKey(definition.Key)) { continue; } string[] nameParts = definition.Key.Split('_'); _entities[definition.Key] = new Entity { Name = definition.Key.Replace("_", string.Empty), Schema = nameParts[0], Definition = definition.Value }; } foreach (var schemaName in uniqueSchemaNames) { if (!_schemaNames.Contains(schemaName)) { _schemaNames.Add(schemaName); } } Log.Info("Success"); } return(true); } catch (Exception ex) { Log.Error(ex); throw; } }
internal static MethodDisplayInfo?GetMethodDisplayString(MethodBase?method) { // Special case: no method available if (method == null) { return(null); } // Type name var type = method.DeclaringType; var methodName = method.Name; string?subMethod = null; if (type != null && type.IsDefined(typeof(CompilerGeneratedAttribute)) && (typeof(IAsyncStateMachine).IsAssignableFrom(type) || typeof(IEnumerator).IsAssignableFrom(type))) { // Convert StateMachine methods to correct overload +MoveNext() if (TryResolveStateMachineMethod(ref method, out type)) { subMethod = methodName; } } string?declaringTypeName = null; // ResolveStateMachineMethod may have set declaringType to null if (type != null) { declaringTypeName = TypeNameHelper.GetTypeDisplayName(type, includeGenericParameterNames: true); } string?genericArguments = null; if (method.IsGenericMethod) { genericArguments = "<" + string.Join(", ", method.GetGenericArguments() .Select(arg => TypeNameHelper.GetTypeDisplayName(arg, fullName: false, includeGenericParameterNames: true))) + ">"; } // Method parameters var parameters = method.GetParameters().Select(parameter => { var parameterType = parameter.ParameterType; var prefix = string.Empty; if (parameter.IsOut) { prefix = "out"; } else if (parameterType != null && parameterType.IsByRef) { prefix = "ref"; } var parameterTypeString = "?"; if (parameterType != null) { if (parameterType.IsByRef) { parameterType = parameterType.GetElementType(); } parameterTypeString = TypeNameHelper.GetTypeDisplayName(parameterType !, fullName: false, includeGenericParameterNames: true); } return(new ParameterDisplayInfo { Prefix = prefix, Name = parameter.Name, Type = parameterTypeString, }); }); var methodDisplayInfo = new MethodDisplayInfo(declaringTypeName, method.Name, genericArguments, subMethod, parameters); return(methodDisplayInfo); }
public static ILogger CreateChildLogger(this ILoggerFactory loggerFactory, string name, Type parentType) { return(loggerFactory.CreateLogger($"{TypeNameHelper.GetTypeDisplayName(parentType)}.{name}")); }
internal ClassNode(FileSourceInfo source, bool isInnerClass, string name, IDataType baseType, TypeNameHelper generatedClassName, Vector <float> clearColor, bool autoCtor, bool simulate, bool isTest, IEnumerable <RawProperty> rawProperties) : base(source, name, generatedClassName, baseType, clearColor, InstanceType.None, rawProperties) { IsInnerClass = isInnerClass; AutoCtor = autoCtor; Simulate = simulate; IsTest = isTest; BaseType = baseType; }
private void OnHandlerChanged() { if (!this.isSetInternally) { if (this.Handler == null) { this.ActivityDelegate = null; } else { if (this.Factory != null && this.EditingContext != null) { try { ActivityDelegate instance = this.Factory.Create(); Fx.Assert(instance != null, "Factory should not return null"); ModelItem modelItem = this.EditingContext.Services.GetService <ModelTreeManager>().WrapAsModelItem(instance); modelItem.Properties["Handler"].SetValue(this.Handler); this.ActivityDelegate = modelItem; } catch (Exception ex) { if (Fx.IsFatal(ex)) { throw; } string details = ex.Message; if (ex is TargetInvocationException && ex.InnerException != null) { details = ex.InnerException.Message; } this.ReportError(string.Format(CultureInfo.CurrentUICulture, SR.CannotCreateInstance, TypeNameHelper.GetDisplayName(this.Factory.DelegateType, false)), details); this.isSetInternally = true; this.Handler = null; this.isSetInternally = false; } } } } }
public DuplicateTypeRegistrationException(Type serviceType) : base($"A service of type '{TypeNameHelper.GetTypeDisplayName(serviceType)}' has already been registered.") { ServiceType = serviceType; }
public MissingTypeRegistrationException(Type serviceType) : base($"找不到类型的任何注册服务 '{TypeNameHelper.GetTypeDisplayName(serviceType)}'.") { ServiceType = serviceType; }
public IUnionTypeDescriptor DependsOn(Type schemaType) { TypeNameHelper.AddNameFunction( _descriptor, _createName, schemaType); return(_descriptor); }