Ejemplo n.º 1
0
Archivo: Dex.cs Proyecto: oujunke/Dexer
 internal TypeReference Import(TypeReference tref, bool add)
 {
     foreach (var item in TypeReferences)
     {
         if (tref.Equals(item))
         {
             return(item);
         }
     }
     if (add)
     {
         // if !add see TypeDescriptor comment
         TypeReferences.Add(tref);
     }
     return(tref);
 }
Ejemplo n.º 2
0
        internal static void RegisterType(Type type)
        {
            if (AllowReferences)
            {
                PropertyInfo[] props = type.GetPropertiesCached()
                                       .Union(type.GetProperties(BindingFlags.NonPublic | BindingFlags.Instance))
                                       .ToArray();
                foreach (PropertyInfo prop in props)
                {
                    UnifiedIMReference reff = prop.GetCustomAttribute <UnifiedIMReference>();
                    UnifiedIMIndex     indx = prop.GetCustomAttribute <UnifiedIMIndex>();
                    bool alreadyIndexed     = false;

                    if (reff != null)
                    {
                        if (reff.HostPropertyType == null)
                        {
                            reff.HostPropertyType = props.FirstOrDefault(x => x.Name == reff.HostProperty)?.PropertyType;
                        }
                        if (reff.HostType == null)
                        {
                            reff.HostType = prop.DeclaringType;
                        }
                        reff.SetProperty     = prop.Name;
                        reff.SetPropertyType = prop.PropertyType;
                        if (reff.SetPropertyType == null)
                        {
                            throw new ArgumentException("Set Property does not exist");
                        }
                        References.Add(reff);
                        if (!HostReferences.ContainsKey(type))
                        {
                            HostReferences.Add(type, new List <UnifiedIMReference>());
                        }
                        HostReferences[type].Add(reff);
                        if (!TargetReferences.ContainsKey(reff.TargetType))
                        {
                            TargetReferences.Add(reff.TargetType, new List <UnifiedIMReference>());
                        }
                        TargetReferences[reff.TargetType].Add(reff);
                        if (!TypeReferences.ContainsKey(reff.HostType))
                        {
                            TypeReferences.Add(reff.HostType, new List <UnifiedIMReference>());
                        }
                        if (!TypeReferences.ContainsKey(reff.TargetType))
                        {
                            TypeReferences.Add(reff.TargetType, new List <UnifiedIMReference>());
                        }
                        TypeReferences[reff.TargetType].Add(reff);
                        TypeReferences[reff.HostType].Add(reff);
                        if (AllowIndexes && CreateReferenceIndexes)
                        {
                            if (reff.TargetProperty != "ObjectID" && !HasIndex(reff.TargetType, reff.TargetProperty))
                            {
                                AddIndex(reff.TargetType, reff.TargetProperty);
                            }
                            if (reff.HostProperty != "ObjectID" && !HasIndex(reff.HostType, reff.HostProperty))
                            {
                                AddIndex(reff.HostType, reff.HostProperty);
                            }

                            if (reff.TargetType == type || reff.HostType == type)
                            {
                                alreadyIndexed = true;
                            }
                        }
                    }

                    if (!alreadyIndexed && prop.Name != "ObjectID" && indx != null)
                    {
                        AddIndex(type, prop.Name);
                    }
                }
            }

            if (!_databaseGetters.ContainsKey(type))
            {
                _databaseGetters.Add(type, ((IUnifiedIMObject)Activator.CreateInstance(type)).DatabaseBase);
            }
        }