public DefinitionAssemblyData()
        {
            DefinitionsToTypeMapping = new Dictionary <DefinitionsEnum, DefinitionUseRule>();
            TypeToEnumMapping        = new Dictionary <Type, DefinitionsEnum>();
            var mappedTypes =
                Assembly
                .GetAssembly(typeof(DefinitionAssemblyData))
                .GetTypes()
                .Where(x => x.GetCustomAttributes(typeof(DestinyDefinitionAttribute), true).Length > 0);

            foreach (var type in mappedTypes)
            {
                var definitionAttribute =
                    type.GetCustomAttribute(
                        typeof(DestinyDefinitionAttribute),
                        true)
                    as DestinyDefinitionAttribute;
                var enumValue = definitionAttribute.DefinitionEnumType;
                var useRule   = new DefinitionUseRule
                {
                    DefinitionType = type,
                    AttributeData  = definitionAttribute
                };
                DefinitionsToTypeMapping.Add(enumValue, useRule);
                TypeToEnumMapping.Add(useRule.DefinitionType, enumValue);
            }
        }
예제 #2
0
    public DefinitionAssemblyData()
    {
        var tempDefinitionsToTypeMapping = new Dictionary <DefinitionsEnum, DefinitionUseRule>();
        var tempTypeToEnumMapping        = new Dictionary <Type, DefinitionsEnum>();
        var mappedTypes =
            Assembly
            .GetAssembly(typeof(DefinitionAssemblyData))
            !.GetTypes()
            .Where(x => x.GetCustomAttributes <DestinyDefinitionAttribute>().Any());

        foreach (var type in mappedTypes)
        {
            var definitionAttribute = type.GetCustomAttribute <DestinyDefinitionAttribute>();
            var enumValue           = definitionAttribute !.DefinitionEnumType;
            var useRule             = new DefinitionUseRule
            {
                DefinitionType = type,
                AttributeData  = definitionAttribute
            };
            tempDefinitionsToTypeMapping.Add(enumValue, useRule);
            tempTypeToEnumMapping.Add(useRule.DefinitionType, enumValue);
        }

        DefinitionsToTypeMapping =
            new ReadOnlyDictionary <DefinitionsEnum, DefinitionUseRule>(tempDefinitionsToTypeMapping);
        TypeToEnumMapping = new ReadOnlyDictionary <Type, DefinitionsEnum>(tempTypeToEnumMapping);
    }
        public DefinitionAssemblyData()
        {
            DefinitionsToTypeMapping = new Dictionary <DefinitionsEnum, DefinitionUseRule>();
            TypeToEnumMapping        = new Dictionary <Type, DefinitionsEnum>();
            var mappedTypes =
                Assembly
                .GetAssembly(typeof(DefinitionAssemblyData))
                .GetTypes()
                .Where(x =>
            {
                var attrs = x.GetCustomAttributes(typeof(DestinyDefinitionAttribute), true);
                return(attrs != null && attrs.Length > 0);
            });

            foreach (var type in mappedTypes)
            {
                var definitionAttribute =
                    type.GetCustomAttribute(
                        attributeType: typeof(DestinyDefinitionAttribute),
                        inherit: true)
                    as DestinyDefinitionAttribute;
                var enumValue = definitionAttribute.DefinitionEnumType;
                var useRule   = new DefinitionUseRule()
                {
                    DefinitionStringName  = enumValue.ToString(),
                    DefinitionType        = type,
                    AttributeData         = definitionAttribute,
                    UserOverrideLoadValue = null
                };
                DefinitionsToTypeMapping.Add(enumValue, useRule);
                TypeToEnumMapping.Add(useRule.DefinitionType, enumValue);
            }
            NameToEnumMapping = new Dictionary <string, DefinitionsEnum>();
            EnumToNameMapping = new Dictionary <DefinitionsEnum, string>();
            var enumValues = Enum.GetValues(typeof(DefinitionsEnum)).Cast <DefinitionsEnum>();

            foreach (var enumValue in enumValues)
            {
                var stringEnumValue = enumValue.ToString();
                NameToEnumMapping.Add(stringEnumValue, enumValue);
                EnumToNameMapping.Add(enumValue, stringEnumValue);
            }
        }