コード例 #1
0
        internal static LinkedList <WeakReference> GetAttributeInterfaces(Type clazz)
        {
            LinkedList <WeakReference> foundInterfaces = knownImplClasses.Get(clazz);

            lock (knownImplClasses)
            {
                if (foundInterfaces == null)
                {
                    // we have the slight chance that another thread may do the same, but who cares?
                    foundInterfaces = new LinkedList <WeakReference>();
                    // find all interfaces that this attribute instance implements
                    // and that extend the Attribute interface
                    Type actClazz = clazz;
                    do
                    {
                        foreach (Type curInterface in actClazz.GetInterfaces())
                        {
                            if (curInterface != typeof(IAttribute) && (typeof(IAttribute)).IsAssignableFrom(curInterface))
                            {
                                foundInterfaces.AddLast(new WeakReference(curInterface));
                            }
                        }
                        actClazz = actClazz.GetTypeInfo().BaseType;
                    } while (actClazz != null);
                    knownImplClasses.Put(clazz, foundInterfaces);
                }
            }
            return(foundInterfaces);
        }
コード例 #2
0
        /// <summary>
        /// Returns the distance from the <c>baseClass</c> in which this method is overridden/implemented
        /// in the inheritance path between <c>baseClass</c> and the given subclass <paramref name="subclazz"/>. </summary>
        /// <returns> 0 if and only if not overridden, else the distance to the base class. </returns>
        public int GetImplementationDistance(Type subclazz)
        {
            int distance = cache.Get(subclazz);

            if (distance == default(int))
            {
                // we have the slight chance that another thread may do the same, but who cares?
                cache.Put(subclazz, distance = Convert.ToInt32(ReflectImplementationDistance(subclazz), CultureInfo.InvariantCulture));
            }
            return((int)distance);
        }
コード例 #3
0
                internal static Type GetClassForInterface <T>() where T : IAttribute
                {
                    var           attClass = typeof(T);
                    WeakReference @ref     = attClassImplMap.Get(attClass);
                    Type          clazz    = (@ref == null) ? null : (Type)@ref.Target;

                    if (clazz == null)
                    {
                        // we have the slight chance that another thread may do the same, but who cares?
                        try
                        {
                            string name = attClass.FullName.Replace(attClass.Name, attClass.Name.Substring(1)) + ", " + attClass.GetTypeInfo().Assembly.FullName;
                            attClassImplMap.Put(attClass, new WeakReference(clazz = Type.GetType(name, true)));
                        }
                        catch (Exception e)
                        {
                            throw new System.ArgumentException("Could not find implementing class for " + attClass.Name, e);
                        }
                    }
                    return(clazz);
                }