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;
3
5{
9 [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = true, Inherited = true)]
10 public class FullTextSearchAttribute : Attribute
11 {
12 private readonly string indexCollection;
13 private readonly PropertyDefinition[] properties;
14 private readonly bool hasPropertyDefinitions;
15 private readonly bool isPropertyReference;
16
21 public FullTextSearchAttribute(string IndexCollection)
22 : this(IndexCollection, new PropertyDefinition[0])
23 {
24 }
25
34 public FullTextSearchAttribute(string IndexCollection, params string[] Properties)
35 : this(IndexCollection, PropertyDefinition.ToArray(Properties))
36 {
37 }
38
47 public FullTextSearchAttribute(string IndexCollection, params PropertyDefinition[] Properties)
48 {
49 this.indexCollection = IndexCollection;
50 this.properties = Properties;
51 this.hasPropertyDefinitions = (Properties?.Length ?? 0) > 0;
52 this.isPropertyReference = false;
53 }
54
65 public FullTextSearchAttribute(string IndexCollection, bool PropertyReference)
66 {
67 this.indexCollection = IndexCollection;
68 this.properties = new PropertyDefinition[0];
69 this.hasPropertyDefinitions = (this.Properties?.Length ?? 0) > 0;
70 this.isPropertyReference = PropertyReference;
71 }
72
76 public bool DynamicIndexCollection => this.isPropertyReference;
77
81 public string GetIndexCollection(object Reference)
82 {
83 if (this.isPropertyReference)
84 {
85 Type T = Reference.GetType();
86 PropertyInfo PI = T.GetRuntimeProperty(this.indexCollection)
87 ?? throw new ArgumentException("Object lacks a property named " + this.indexCollection, nameof(Reference));
88
89 object Obj = PI.GetValue(Reference);
90
91 if (Obj is string s)
92 return s;
93 else
94 throw new ArgumentException("Object property " + this.indexCollection + " does not return a string.", nameof(Reference));
95 }
96 else
97 return this.indexCollection;
98 }
99
103 public PropertyDefinition[] Properties => this.properties;
104
109 public bool HasPropertyDefinitions => this.hasPropertyDefinitions;
110 }
111}
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(object Reference)
Name of full-text-search index collection.