Ejemplo n.º 1
0
        internal static DocumentTypeReflection GetTypeReflection <T>()
        {
            Type typeFromHandle = typeof(T);

            if (!typeReflections.TryGetValue(typeFromHandle, out var value))
            {
                List <DocumentFieldReflection> list = new List <DocumentFieldReflection>();
                FieldInfo[] fields = typeFromHandle.GetFields();
                foreach (FieldInfo fieldInfo in fields)
                {
                    object[] customAttributes = fieldInfo.GetCustomAttributes(typeof(IndexedAttribute), inherit: true);
                    if (customAttributes.Length > 0)
                    {
                        DocumentFieldReflection item = new DocumentFieldReflection(fieldInfo);
                        list.Add(item);
                    }
                }
                value = new DocumentTypeReflection(list.ToArray());
                typeReflections.Add(typeFromHandle, value);
            }
            return(value);
        }
Ejemplo n.º 2
0
 public FieldIndexes(IndexFactory indexFactory, Aes256Encryptor encryptor)
 {
     typeReflection = DocumentReflectionCache.GetTypeReflection <TDocument>();
     fieldTypes     = new Dictionary <string, Type>();
     fieldIndexes   = new Dictionary <string, object>();
     boolIndexes    = new Dictionary <string, Index <bool> >();
     sbyteIndexes   = new Dictionary <string, Index <sbyte> >();
     byteIndexes    = new Dictionary <string, Index <byte> >();
     shortIndexes   = new Dictionary <string, Index <short> >();
     ushortIndexes  = new Dictionary <string, Index <ushort> >();
     intIndexes     = new Dictionary <string, Index <int> >();
     uintIndexes    = new Dictionary <string, Index <uint> >();
     longIndexes    = new Dictionary <string, Index <long> >();
     ulongIndexes   = new Dictionary <string, Index <ulong> >();
     floatIndexes   = new Dictionary <string, Index <float> >();
     doubleIndexes  = new Dictionary <string, Index <double> >();
     charIndexes    = new Dictionary <string, Index <char> >();
     stringIndexes  = new Dictionary <string, Index <string> >();
     DocumentFieldReflection[] fieldReflections = typeReflection.FieldReflections;
     foreach (DocumentFieldReflection documentFieldReflection in fieldReflections)
     {
         FieldInfo fieldInfo = documentFieldReflection.FieldInfo;
         string    name      = fieldInfo.Name;
         Type      fieldType = fieldInfo.FieldType;
         fieldTypes.Add(name, fieldType);
         if (fieldType == typeof(bool))
         {
             Index <bool> value = indexFactory.Create <bool>(name, encryptor);
             boolIndexes.Add(name, value);
             fieldIndexes.Add(name, value);
             continue;
         }
         if (fieldType == typeof(sbyte))
         {
             Index <sbyte> value2 = indexFactory.Create <sbyte>(name, encryptor);
             sbyteIndexes.Add(name, value2);
             fieldIndexes.Add(name, value2);
             continue;
         }
         if (fieldType == typeof(byte))
         {
             Index <byte> value3 = indexFactory.Create <byte>(name, encryptor);
             byteIndexes.Add(name, value3);
             fieldIndexes.Add(name, value3);
             continue;
         }
         if (fieldType == typeof(short))
         {
             Index <short> value4 = indexFactory.Create <short>(name, encryptor);
             shortIndexes.Add(name, value4);
             fieldIndexes.Add(name, value4);
             continue;
         }
         if (fieldType == typeof(ushort))
         {
             Index <ushort> value5 = indexFactory.Create <ushort>(name, encryptor);
             ushortIndexes.Add(name, value5);
             fieldIndexes.Add(name, value5);
             continue;
         }
         if (fieldType == typeof(int))
         {
             Index <int> value6 = indexFactory.Create <int>(name, encryptor);
             intIndexes.Add(name, value6);
             fieldIndexes.Add(name, value6);
             continue;
         }
         if (fieldType == typeof(uint))
         {
             Index <uint> value7 = indexFactory.Create <uint>(name, encryptor);
             uintIndexes.Add(name, value7);
             fieldIndexes.Add(name, value7);
             continue;
         }
         if (fieldType == typeof(long))
         {
             Index <long> value8 = indexFactory.Create <long>(name, encryptor);
             longIndexes.Add(name, value8);
             fieldIndexes.Add(name, value8);
             continue;
         }
         if (fieldType == typeof(ulong))
         {
             Index <ulong> value9 = indexFactory.Create <ulong>(name, encryptor);
             ulongIndexes.Add(name, value9);
             fieldIndexes.Add(name, value9);
             continue;
         }
         if (fieldType == typeof(float))
         {
             Index <float> value10 = indexFactory.Create <float>(name, encryptor);
             floatIndexes.Add(name, value10);
             fieldIndexes.Add(name, value10);
             continue;
         }
         if (fieldType == typeof(double))
         {
             Index <double> value11 = indexFactory.Create <double>(name, encryptor);
             doubleIndexes.Add(name, value11);
             fieldIndexes.Add(name, value11);
             continue;
         }
         if (fieldType == typeof(char))
         {
             Index <char> value12 = indexFactory.Create <char>(name, encryptor);
             charIndexes.Add(name, value12);
             fieldIndexes.Add(name, value12);
             continue;
         }
         if (fieldType == typeof(string))
         {
             Index <string> value13 = indexFactory.Create <string>(name, encryptor);
             stringIndexes.Add(name, value13);
             fieldIndexes.Add(name, value13);
             continue;
         }
         throw new FormatException("Unhandled field " + name + " with type " + fieldType);
     }
 }