protected string CreateMapFor(Type t) { var type = new TypeNameResolver().GetTypeNameFor(t); var writer = new TypeMappingWriter(t, type); return(writer.MapFromAttributes()); }
public override VisualElement Build() { var typeField = Assets.LoadVisualTreeAsset(nameof(TypeInspector <T>)).CloneTree(); var label = typeField.Q <Label>("label"); label.text = DisplayName; var input = typeField.Q <VisualElement>("input"); input.RegisterCallback <MouseUpEvent>(mouseUpEvent => { var database = TypeSearcherDatabase.Populate <T>(TypeFilter, TypeNameResolver, TypeCategoryResolver); var searcher = new Searcher(database, new AddTypeSearcherAdapter(SearcherTitle)); var position = input.worldBound.min + Vector2.up * (input.worldBound.height + 19f); var alignment = new SearcherWindow.Alignment(SearcherWindow.Alignment.Vertical.Top, SearcherWindow.Alignment.Horizontal.Left); SearcherWindow.Show(EditorWindow.focusedWindow, searcher, OnTypeSelected, position, null); }); var type = Target?.GetType(); if (type != null) { m_Text = typeField.Q <TextElement>("text"); m_Text.text = TypeNameResolver?.Invoke(type) ?? type.Name; } return(typeField); }
public override void Update() { var type = Target?.GetType(); if (type != null) { var text = TypeNameResolver?.Invoke(type) ?? type.Name; if (m_Text.text != text) { m_Text.text = TypeNameResolver?.Invoke(type) ?? type.Name; NotifyChanged(); } } if ((m_Message.text ?? string.Empty) != (ErrorMessage ?? string.Empty)) { if (!string.IsNullOrEmpty(ErrorMessage)) { m_HelpBox.style.display = DisplayStyle.Flex; m_Message.text = ErrorMessage; } else { m_HelpBox.style.display = DisplayStyle.None; m_Message.text = string.Empty; } } }
protected string CreateMapFor(Type t) { var type = new TypeNameResolver().GetTypeNameFor(t); var writer = new TypeMappingWriter(t, type, TestElasticClient.Settings, 10); return(writer.MapFromAttributes()); }
[U] public void TypeNameFromElasticsearchTypeAttribute() { var settings = new ConnectionSettings(); var resolver = new TypeNameResolver(settings); var type = resolver.Resolve <AttributedProject>(); type.Should().Be("attributed_project"); }
/** * ==== TypeName default * Type names are resolved by lowercasing the type name */ [U] public void DefaultTypeNameIsLowercase() { var settings = new ConnectionSettings(); var resolver = new TypeNameResolver(settings); var index = resolver.Resolve <Project>(); index.Should().Be("project"); }
public DictionaryTypeReader() { Version = 0; Name = $"Microsoft.Xna.Framework.Content.DictionaryReader`2[[{TypeNameResolver.ResolveAssemblyQualifiedName<TKeyType>()}],[{TypeNameResolver.ResolveAssemblyQualifiedName<TValueType>()}]]"; var k = typeof(TKeyType); var v = typeof(TValueType); }
[U] public void TypeNameFromDataContractAttribute() { var settings = new ConnectionSettings(); var resolver = new TypeNameResolver(settings); var type = resolver.Resolve <DataContractProject>(); type.Should().Be("data_contract_project"); }
/** * [[default-type-name]] * ==== Default type name * With Elasticsearch 6.x, you can only have a single type per index and in the long run types will be * phased out entirely. * The need to tag types is no longer necessary, so in many cases it makes sense to use a single fixed type, * like `doc` */ [U] public void DefaultTypeName() { var settings = new ConnectionSettings().DefaultTypeName("doc"); var resolver = new TypeNameResolver(settings); var type = resolver.Resolve <Project>(); type.Should().Be("doc"); }
/** * [[pluralize-type-names]] * ==== Pluralize type names * The default behaviour in older versions of NEST was to pluralize typenames * * You can still opt in to this old behaviour as followed: */ [U] public void PluralizeTypeNames() { var settings = new ConnectionSettings() .PluralizeTypeNames(); var resolver = new TypeNameResolver(settings); var index = resolver.Resolve <Project>(); index.Should().Be("projects"); }
/** * With such a setting in place, all CLR types will resolve to `doc` as the type name to use in Elasticsearch. */ /** * [[type-name-inferrer]] * ==== Override type name inferrer * You can provide a delegate to override the default type name inferrer for types */ [U] public void OverridingDefaultTypeNameInferrer() { var settings = new ConnectionSettings() .DefaultTypeNameInferrer(t => t.Name.ToLower() + "-suffix"); var resolver = new TypeNameResolver(settings); var type = resolver.Resolve <Project>(); type.Should().Be("project-suffix"); }
public void ConvertType_TypeIsNotEntityOrDTO_ReturnsType() { // Arrange Type type = typeof(Bird); Type expectedType = typeof(Bird); // Act Type outType = TypeNameResolver.ConvertType(type); // Assert Assert.AreEqual(expectedType, outType, $"{expectedType} does not match {outType}"); }
public void ToDTO_DTOExists_ReturnsDTO() { // Arrange Type entityType = typeof(Pigeon); Type expectedDTOType = typeof(PigeonDTO); // Act Type dtoType = TypeNameResolver.ToDTO(entityType); // Assert Assert.AreEqual(expectedDTOType, dtoType, $"{expectedDTOType} does not match {dtoType}"); }
public void FromDTO_EntityExists_ReturnsEntity() { // Arrange Type dtoType = typeof(PigeonDTO); Type expectedEntityType = typeof(Pigeon); // Act Type entityType = TypeNameResolver.FromDTO(dtoType); // Assert Assert.AreEqual(expectedEntityType, entityType, $"{expectedEntityType} does not match {entityType}"); }
public static void ReadExpectation(ApiTypeReader typeReader, Type type, CompilationUnitExpectation expectation) { var typeNameResolver = new TypeNameResolver { SimplifyNamespaces = true, }; // Act var compilationUnit = typeReader.ReadCompilationUnit(type, typeNameResolver); // Assert AssertCompilationUnit(expectation, compilationUnit); }
internal void WriteProperties(JsonWriter jsonWriter) { var properties = this._type.GetProperties(); foreach (var p in properties) { var att = this._propertyNameResolver.GetElasticProperty(p); if (att != null && att.OptOut) { continue; } var propertyName = new PropertyNameResolver().Resolve(p); var type = GetElasticSearchType(att, p); if (type == null) //could not get type from attribute or infer from CLR type. { continue; } jsonWriter.WritePropertyName(propertyName); jsonWriter.WriteStartObject(); { if (att == null) //properties that follow can not be inferred from the CLR. { jsonWriter.WritePropertyName("type"); jsonWriter.WriteValue(type); //jsonWriter.WriteEnd(); } if (att != null) { this.WritePropertiesFromAttribute(jsonWriter, att, propertyName, type); } if (type == "object" || type == "nested") { var deepType = p.PropertyType; var deepTypeName = new TypeNameResolver().GetTypeNameFor(deepType).Resolve(this._connectionSettings); var seenTypes = new ConcurrentDictionary <Type, int>(this.SeenTypes); seenTypes.AddOrUpdate(deepType, 0, (t, i) => ++ i); var newTypeMappingWriter = new TypeMappingWriter(deepType, deepTypeName, this._connectionSettings, MaxRecursion, seenTypes); var nestedProperties = newTypeMappingWriter.MapPropertiesFromAttributes(); jsonWriter.WritePropertyName("properties"); nestedProperties.WriteTo(jsonWriter); } } jsonWriter.WriteEnd(); } }
public override VisualElement Build() { var typeField = Assets.LoadVisualTreeAsset(nameof(TypeInspector <T>)).CloneTree(); typeField.AddStyleSheetAndVariant(nameof(TypeInspector <T>)); var label = typeField.Q <Label>("label"); label.text = DisplayName; var input = typeField.Q <VisualElement>("input"); input.RegisterCallback <MouseUpEvent>(mouseUpEvent => { var database = TypeSearcherDatabase.Populate <T>(TypeFilter, TypeNameResolver, TypeCategoryResolver); var searcher = new Searcher(database, new AddTypeSearcherAdapter(SearcherTitle)); var position = input.worldBound.min + Vector2.up * (input.worldBound.height + 19f); var alignment = new SearcherWindow.Alignment(SearcherWindow.Alignment.Vertical.Top, SearcherWindow.Alignment.Horizontal.Left); SearcherWindow.Show(EditorWindow.focusedWindow, searcher, OnTypeSelected, position, null); }); m_HelpBox = typeField.Q <VisualElement>("helpbox"); var icon = m_HelpBox.Q <Image>("icon"); icon.image = EditorGUIUtility.IconContent("d_console.erroricon.sml").image; icon.scaleMode = ScaleMode.ScaleToFit; m_Message = m_HelpBox.Q <Label>("message"); if (!string.IsNullOrEmpty(ErrorMessage)) { m_HelpBox.style.display = DisplayStyle.Flex; m_Message.text = ErrorMessage; } else { m_HelpBox.style.display = DisplayStyle.None; m_Message.text = string.Empty; } var type = Target?.GetType(); if (type != null) { m_Text = typeField.Q <TextElement>("text"); m_Text.text = TypeNameResolver?.Invoke(type) ?? type.Name; } return(typeField); }
public override void Update() { var type = Target?.GetType(); if (type != null) { var text = TypeNameResolver?.Invoke(type) ?? type.Name; if (m_Text.text != text) { m_Text.text = TypeNameResolver?.Invoke(type) ?? type.Name; NotifyChanged(); } } }
public static DocumentInfo <TEntity> Mapping <TEntity>(this IElasticClient client, Func <DocumentInfo <TEntity>, DocumentInfo <TEntity> > documentInfo) where TEntity : class { var doc = documentInfo(new DocumentInfo <TEntity>()); if (string.IsNullOrEmpty(doc.Index)) { doc.SetIndex(client.ConnectionSettings.DefaultIndex); } if (string.IsNullOrEmpty(doc.Type)) { var resolver = new TypeNameResolver(client.ConnectionSettings); doc.SetType(resolver.Resolve <TEntity>()); } MapTypeSearch.AddMap <TEntity>(doc); return(doc); }
bool GetAttributeType(XPathNodeIterator iterator, string attributeFullName, out TypeDefinition attributeType) { string assemblyName = GetAttribute(iterator.Current, "assembly"); if (string.IsNullOrEmpty(assemblyName)) { attributeType = Context.GetType(attributeFullName); } else { AssemblyDefinition assembly; try { assembly = GetAssembly(Context, AssemblyNameReference.Parse(assemblyName)); if (assembly == null) { Context.LogWarning($"Could not resolve assembly '{assemblyName}' for attribute '{attributeFullName}'", 2030, _xmlDocumentLocation); attributeType = default; return(false); } } catch (Exception) { Context.LogWarning($"Could not resolve assembly '{assemblyName}' for attribute '{attributeFullName}'", 2030, _xmlDocumentLocation); attributeType = default; return(false); } attributeType = TypeNameResolver.ResolveTypeName(assembly, attributeFullName)?.Resolve(); } if (attributeType == null) { Context.LogWarning($"Attribute type '{attributeFullName}' could not be found", 2031, _xmlDocumentLocation); return(false); } return(true); }
internal void WriteProperties(JsonWriter jsonWriter) { var properties = this._type.GetProperties(); foreach (var p in properties) { var att = this._propertyNameResolver.GetElasticProperty(p); if (att != null && att.OptOut) continue; var propertyName = new PropertyNameResolver().Resolve(p); var type = GetElasticSearchType(att, p); if (type == null) //could not get type from attribute or infer from CLR type. continue; jsonWriter.WritePropertyName(propertyName); jsonWriter.WriteStartObject(); { if (att == null) //properties that follow can not be inferred from the CLR. { jsonWriter.WritePropertyName("type"); jsonWriter.WriteValue(type); //jsonWriter.WriteEnd(); } if (att != null) this.WritePropertiesFromAttribute(jsonWriter, att, propertyName, type); if (type == "object" || type == "nested") { var deepType = p.PropertyType; var deepTypeName = new TypeNameResolver().GetTypeNameFor(deepType).Resolve(this._connectionSettings); var seenTypes = new ConcurrentDictionary<Type, int>(this.SeenTypes); seenTypes.AddOrUpdate(deepType, 0, (t, i) => ++i); var newTypeMappingWriter = new TypeMappingWriter(deepType, deepTypeName, this._connectionSettings, MaxRecursion, seenTypes); var nestedProperties = newTypeMappingWriter.MapPropertiesFromAttributes(); jsonWriter.WritePropertyName("properties"); nestedProperties.WriteTo(jsonWriter); } } jsonWriter.WriteEnd(); } }
public void BindToName(Type serializedType, out string assemblyName, out string typeName) { assemblyName = AssemblyNameResolver?.Invoke(serializedType); typeName = TypeNameResolver?.Invoke(serializedType); }
public DataStoreConfiguration() { TypeNameResolver = new TypeNameResolver { TypeBinding = GetTypes }; }