Esempio n. 1
0
        public ReferenceAliasManager()
        {
            if (!typeof(T).IsEnum)
            {
                throw new InvalidOperationException("T must be an enumerated type");
            }

            // Load all default ReferenceAlias
            foreach (T alias in Enum.GetValues(typeof(T)))
            {
                ReferenceAlias <T> referenceAlias = ReferenceAliasAttribute.Get <T>(alias);
                if (referenceAlias == null)
                {
                    continue;
                }

                _referenceAliases.Add(alias, referenceAlias);
            }

            // Execute enum custom initialization if defined
            ReferenceAliasInitAttribute attr = typeof(T).GetCustomAttributes(typeof(ReferenceAliasInitAttribute), true).FirstOrDefault() as ReferenceAliasInitAttribute;

            if (attr != null)
            {
                attr.Invoke(typeof(T), this);
            }
        }
Esempio n. 2
0
        internal static ReferenceAlias <T> FromAttribute(ReferenceAliasAttribute attr)
        {
            if (attr.Type != null)
            {
                return(FromType(attr.Type, attr.PublicReference));
            }

            if (!string.IsNullOrEmpty(attr.Name) && !string.IsNullOrEmpty(attr.Version))
            {
                return(FromNuget(attr.Name, attr.Version));
            }

            return(FromPaths(attr.Paths));
        }
Esempio n. 3
0
        public static ReferenceAlias <T> Get <T>(object enumValue) where T : struct, IConvertible
        {
            if (enumValue == null)
            {
                return(null);
            }

            MemberInfo[] mi = typeof(T).GetMember(enumValue.ToString());
            if (mi.Length <= 0)
            {
                return(null);
            }

            ReferenceAliasAttribute attr = Attribute.GetCustomAttribute(mi[0], typeof(ReferenceAliasAttribute)) as ReferenceAliasAttribute;

            if (attr == null)
            {
                return(null);
            }

            return(ReferenceAlias <T> .FromAttribute(attr));
        }