Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
FullTextSearchAttribute.cs
1using System;
2using System.Reflection;
4
6{
10 [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = true, Inherited = true)]
11 public class FullTextSearchAttribute : Attribute
12 {
13 private readonly string indexCollection;
14 private readonly PropertyDefinition[] properties;
15 private readonly bool hasPropertyDefinitions;
16 private readonly bool isPropertyReference;
17
22 public FullTextSearchAttribute(string IndexCollection)
23 : this(IndexCollection, Array.Empty<PropertyDefinition>())
24 {
25 }
26
35 public FullTextSearchAttribute(string IndexCollection, params string[] Properties)
36 : this(IndexCollection, PropertyDefinition.ToArray(Properties))
37 {
38 }
39
48 public FullTextSearchAttribute(string IndexCollection, params PropertyDefinition[] Properties)
49 {
50 this.indexCollection = IndexCollection;
51 this.properties = Properties;
52 this.hasPropertyDefinitions = (Properties?.Length ?? 0) > 0;
53 this.isPropertyReference = false;
54 }
55
66 public FullTextSearchAttribute(string IndexCollection, bool PropertyReference)
67 {
68 this.indexCollection = IndexCollection;
69 this.properties = Array.Empty<PropertyDefinition>();
70 this.hasPropertyDefinitions = (this.Properties?.Length ?? 0) > 0;
71 this.isPropertyReference = PropertyReference;
72 }
73
77 public bool DynamicIndexCollection => this.isPropertyReference;
78
82 public string GetIndexCollection(object Reference)
83 {
84 if (this.isPropertyReference)
85 {
86 Type T = Reference.GetType();
87 PropertyInfo PI = T.GetRuntimeProperty(this.indexCollection)
88 ?? throw new ArgumentException("Object lacks a property named " + this.indexCollection, nameof(Reference));
89
90 object Obj = PI.GetValue(Reference);
91
92 if (Obj is string s)
93 return s;
94 else
95 throw new ArgumentException("Object property " + this.indexCollection + " does not return a string.", nameof(Reference));
96 }
97 else
98 return this.indexCollection;
99 }
100
104 public string GetIndexCollection(GenericObject Reference)
105 {
106 if (this.isPropertyReference)
107 {
108 object Obj = Reference[this.indexCollection];
109
110 if (Obj is string s)
111 return s;
112 else
113 throw new ArgumentException("Object property " + this.indexCollection + " does not return a string.", nameof(Reference));
114 }
115 else
116 return this.indexCollection;
117 }
118
122 public PropertyDefinition[] Properties => this.properties;
123
128 public bool HasPropertyDefinitions => this.hasPropertyDefinitions;
129 }
130}
This attribute defines that objects of this type should be indexed in the full-text-search index.
FullTextSearchAttribute(string IndexCollection, params PropertyDefinition[] Properties)
This attribute defines that objects of this type should be indexed in the full-text-search index.
PropertyDefinition[] Properties
Array of property (or field) definitions used to index objects of this type.
FullTextSearchAttribute(string IndexCollection, params string[] Properties)
This attribute defines that objects of this type should be indexed in the full-text-search index.
FullTextSearchAttribute(string IndexCollection)
This attribute defines that objects of this type should be indexed in the full-text-search index.
bool DynamicIndexCollection
If the index collection is dynamic (i.e. depends on object instance).
FullTextSearchAttribute(string IndexCollection, bool PropertyReference)
This attribute defines that objects of this type should be indexed in the full-text-search index.
bool HasPropertyDefinitions
If property names are defined for this class (true), or if objects are to be tokenized using a specia...
string GetIndexCollection(GenericObject Reference)
Name of full-text-search index collection.
string GetIndexCollection(object Reference)
Name of full-text-search index collection.
Generic object. Contains a sequence of properties.