Example #1
0
        public static void ConfigureResourceManager(this ResourceTypeSettings settings, string manifestResourceBaseName, string resourceSetType = null)
        {
            resourceSetType = resourceSetType ?? typeof(BinaryResourceSet).FullName;

            settings.ResourceNamingStrategy = ResourceNamingStrategy.Default;

            settings.ResourceManagerType        = Code.Type <ResourceManager> ( );
            settings.ResourceManagerInitializer = ConstructResourceManager(settings.ClassName, manifestResourceBaseName, resourceSetType);

            settings.LocalizerType        = Code.Type <ResourceManagerLocalizer> ( );
            settings.LocalizerInitializer = ConstructLocalizer(settings.ResourceNamingStrategyInitializer);
        }
Example #2
0
        public static void ConfigureFileBasedResourceManager(this ResourceTypeSettings settings, string baseName, string path, string resourceSetType = null)
        {
            resourceSetType = resourceSetType ?? AutoDetect.ResourceSetType(path).FullName;

            settings.ResourceNamingStrategy = ResourceNamingStrategy.Default;

            var pathFormat      = AutoDetect.PathFormat(path, out var neutralCultureName);
            var resourceManager = Code.Type <FileBasedResourceManager> ( );

            settings.ResourceManagerType        = resourceManager;
            settings.ResourceManagerInitializer = resourceManager.Construct(Code.Constant(baseName),
                                                                            Code.Constant(pathFormat),
                                                                            Code.Constant(neutralCultureName),
                                                                            Code.TypeOf(Code.Type(resourceSetType)));

            settings.LocalizerType        = Code.Type <ResourceManagerLocalizer> ( );
            settings.LocalizerInitializer = ConstructLocalizer(settings.ResourceNamingStrategyInitializer);
        }
Example #3
0
        public virtual CodeCompileUnit Build( )
        {
            settings = Settings.Validate(CodeDomProvider);

            var code       = GenerateCodeCompileUnit( );
            var @namespace = code.Namespaces.Add(settings.Namespace, "System");
            var @class     = GenerateClass(@namespace);

            GenerateClassMembers(@class);

            mapper = new ResourceMapper(CodeDomProvider, settings.ResourceNamingStrategy);

            var map = mapper.Map(@class, ResourceSet);

            foreach (var mapping in map)
            {
                GenerateProperty(mapping).AddTo(@class);
            }

            foreach (var mapping in map)
            {
                if (!IsNullOrEmpty(mapping.FormatMethod))
                {
                    GenerateFormatMethod(mapping).AddTo(@class);
                }
            }

            var extension = TypedLocalizeExtensionBuilder.Build(settings.Extension,
                                                                settings.ClassName,
                                                                settings.AccessModifiers & ~MemberAttributes.Static,
                                                                map);

            if (extension != null)
            {
                extension.AddTo(@class);
            }

            CodeGenerator.ValidateIdentifiers(code);

            return(code);
        }
Example #4
0
 public ResourceTypeBuilder(CodeDomProvider codeDomProvider, IList <IResource> resourceSet, ResourceTypeSettings settings)
 {
     CodeDomProvider = codeDomProvider ?? throw new ArgumentNullException(nameof(codeDomProvider));
     ResourceSet     = resourceSet ?? throw new ArgumentNullException(nameof(resourceSet));
     Settings        = settings ?? throw new ArgumentNullException(nameof(settings));
 }
Example #5
0
 public static void ConfigureWithoutLocalizer(this ResourceTypeSettings settings, string manifestResourceBaseName, string resourceSetType = null)
 {
     settings.ResourceManagerType        = Code.Type <ResourceManager> ( );
     settings.ResourceManagerInitializer = ConstructResourceManager(settings.ClassName, manifestResourceBaseName, resourceSetType);
 }