public void FormattedTypeNamesAreRecoverable() { var types = new[] { typeof(NameValueCollection), typeof(int), typeof(int[]), typeof(int *[]), typeof(List <>), typeof(List <int>), typeof(List <int *[]>), typeof(Inner <int[, , ]> .InnerInner <string, List <int> > .Bottom[, ]), typeof(Inner <> .InnerInner <,> .Bottom), typeof(RuntimeTypeNameFormatterTests), typeof(TestGrainInterfaces.CircularStateTestState), typeof(int).MakeByRefType(), typeof(Inner <int[]> .InnerInner <string, List <int> > .Bottom[, ]) .MakePointerType() .MakePointerType() .MakeArrayType(10) .MakeByRefType(), typeof(NameValueCollection) }; foreach (var type in types) { var formatted = RuntimeTypeNameFormatter.Format(type); this.output.WriteLine($"Full Name: {type.FullName}"); this.output.WriteLine($"Formatted: {formatted}"); var isRecoverable = new CachedTypeResolver().TryResolveType(formatted, out var resolved) && resolved == type; Assert.True(isRecoverable, $"Type.GetType(\"{formatted}\") must be equal to the original type."); } }
public void LoadClassByName() { string className = typeof(MockStorageProvider).FullName; Type classType = new CachedTypeResolver().ResolveType(className); Assert.NotNull(classType); // Type Assert.True(typeof(IGrainStorage).IsAssignableFrom(classType), $"Is an IStorageProvider : {classType.FullName}"); }
public void FormattedTypeNamesAreRecoverable() { foreach (var type in types) { var formatted = RuntimeTypeNameFormatter.Format(type); this.output.WriteLine($"Full Name: {type.FullName}"); this.output.WriteLine($"Formatted: {formatted}"); var isRecoverable = new CachedTypeResolver().TryResolveType(formatted, out var resolved) && resolved == type; Assert.True(isRecoverable, $"Type.GetType(\"{formatted}\") must be equal to the original type."); } }
internal void ValidateConfiguration(ILogger logger) { if (this.AreDefaults) { return; } Type type = null; try { type = new CachedTypeResolver().ResolveType(this.FullTypeName); } catch (Exception exception) { string errStr = string.Format("Unable to find grain class type {0} specified in configuration; Failing silo startup.", this.FullTypeName); logger.Error(ErrorCode.Loader_TypeLoadError, errStr, exception); throw new OrleansException(errStr, exception); } if (type == null) { string errStr = string.Format("Unable to find grain class type {0} specified in configuration; Failing silo startup.", this.FullTypeName); logger.Error(ErrorCode.Loader_TypeLoadError_2, errStr); throw new OrleansException(errStr); } var typeInfo = type.GetTypeInfo(); // postcondition: returned type must implement IGrain. if (!typeof(IGrain).IsAssignableFrom(type)) { string errStr = string.Format("Type {0} must implement IGrain to be used Application configuration context.", type.FullName); logger.Error(ErrorCode.Loader_TypeLoadError_3, errStr); throw new OrleansException(errStr); } // postcondition: returned type must either be an interface or a class. if (!typeInfo.IsInterface && !typeInfo.IsClass) { string errStr = string.Format("Type {0} must either be an interface or class used Application configuration context.", type.FullName); logger.Error(ErrorCode.Loader_TypeLoadError_4, errStr); throw new OrleansException(errStr); } }
public void RegisterType(string name, Type type) { CachedTypeResolver.RegisterType(name, type); }