通用对象池(Generic object pool)
是否有可能创建一个通用对象池,在其中创建新的对象? 另外如果这个对象创建可以接收参数将会很好。
public interface IPoolable { void Dispose(); } public class ObjectPool<T> where T : IPoolable { private List<T> pool; public T Get() { if(pool.count > 0) { return pool.Pop(); } else { return new T(); // <- How to do this properly? } } } public class SomeClass : IPoolable { int id; public SomeClass(int id) { this.id = id; } public void Dispose() { } } public class OtherClass : IPoolable { string name; int id; public OtherClass(string name, int id) { this.name = name; this.id = id; } public void Dispose() { } }
如果它可以接收参数,它可以像这样使用。
SomeClass a = myPool.Get(2); OtherClass b = myOtherPool.Get("foo", 4);
或者如果参数不可行,这也可以。
SomeClass a = myPool.Get(); a.id = 2; OtherClass b = myOtherPool.Get(); b.name = "foo"; b.id = 4;
Is it possible to create a generic object pool that creates new objects inside it? Plus it would be nice if this object creation could receive parameters.
public interface IPoolable { void Dispose(); } public class ObjectPool<T> where T : IPoolable { private List<T> pool; public T Get() { if(pool.count > 0) { return pool.Pop(); } else { return new T(); // <- How to do this properly? } } } public class SomeClass : IPoolable { int id; public SomeClass(int id) { this.id = id; } public void Dispose() { } } public class OtherClass : IPoolable { string name; int id; public OtherClass(string name, int id) { this.name = name; this.id = id; } public void Dispose() { } }
In a way that it can be used like this if it could receive parameters.
SomeClass a = myPool.Get(2); OtherClass b = myOtherPool.Get("foo", 4);
Or this would also be fine if parameters were not possible.
SomeClass a = myPool.Get(); a.id = 2; OtherClass b = myOtherPool.Get(); b.name = "foo"; b.id = 4;
原文:https://stackoverflow.com/questions/37976875
最满意答案
node-neat的
includePaths
属性返回一个包含Bourbon和Neat路径的数组,因为需要Bourbon。 我会像这样连接数组:options: { includePaths: require('node-neat').includePaths.concat('/assets/bower_components/_normalize.scss') },
node-neat's
includePaths
property returns an array with both Bourbon and Neat's paths since Bourbon will be required. I would just concat the array like this:options: { includePaths: require('node-neat').includePaths.concat('/assets/bower_components/_normalize.scss') },
相关问答
更多-
在nodejs中使用node-sass时找不到libsass绑定(libsass bindings not found when using node-sass in nodejs)[2023-05-19]
您可能尝试在使用时重新安装node-sass npm install node-sass 要么 npm uninstall node-sass npm install node-sass 但是node-sass是Sass的C版本。 你必须使用npm重建 : npm rebuild node-sass You’ve probably tried to reinstall node-sass while using npm install node-sass or npm uninstall node- ... -
你如何在深度嵌套的目录结构上使用node-sass?(How do you use node-sass on a deeply nested directory structure?)[2022-06-12]
到目前为止,我发现的最好方式是有点呆滞。 你用find来递归地找到所有正确的文件,然后得到输出给cat ,它将所有这些放在一起,然后最终到node-sass并输出到最终文件。 find src/apps/section -name '*.scss' -print0 | xargs -0 cat | node-sass > ./dist/css/section.css 理想情况下,node-sass应该接受一个glob并对其结果进行操作,但它还不够成熟,或者团队没有专注于创建此功能。 国际海事组织,任何类型 ... -
回答我自己的问题,万一这可以帮助其他人: 我发现解决这个问题的唯一方法是通过grunt使用node-sass CLI。 要实现这一点,请安装令人惊讶的grunt-exec任务并将其设置为使用--watch选项运行命令。 示例用法(支持多个includePath目录): exec: { nodeSass: { cmd: function() { // Include path option string built from the gruntConfig.cssFiles ...
-
检出outFile的node-sass文档 : 指定输出文件的预期位置。 在输出源地图时强烈建议,以便他们可以正确引用他们想要的文件。 注意启用此选项不会将文件写入磁盘,仅供内部参考(例如生成地图)。 所以你需要手动将输出写入磁盘: sass.render({ ... outFile: yourPathTotheFile, }, function(error, result) { // node-style callback from v3.0.0 onwards if(!err ...
-
node-sass没有可用的本机监视任务,但您可以一起使用grunt-contrib-watch和grunt-sass来实现所需的效果。 There is no native watch task available with node-sass, but you can use grunt-contrib-watch and grunt-sass together to achieve the desired effect.
-
您需要在命令行中添加include-path选项的波本风格样式,如下所示(为了便于阅读,多行代码需要位于package.json单行): node-sass --include-path node_modules/bourbon/app/assets/stylesheets/ --output-style compressed -o build/css/ scss/ You need to add bourbon stylesheets with the include-path option in ...
-
也许这覆盖了你的问题: 如何编译或转换sass / scss与节点萨斯(不Ruby)的CSS? 如果它是你的选择,我建议使用grunt,它会使事情变得更简单,更快。 这个grunt插件可能是最好的选择: https : //www.npmjs.com/package/grunt-contrib-sass //更新 我遵循你发送的教程,这非常简单。 您可以在名为“package.json”的根文件夹中创建一个包含以下内容的文件: { "watches": { "sass": "sass/**" ...
-
这实际上工作正常,后续进程打破了它。 这是一个获得的问题 postcss -u autoprefixer 跳过css地图。 This is actually working fine, and it is the subsequent process that breaks it. This is an issue of getting postcss -u autoprefixer to skip the css map.
-
在node-sass grunt任务中包含node-neat +其他文件(Including node-neat + other files in node-sass grunt task)[2022-05-21]
node-neat的includePaths属性返回一个包含Bourbon和Neat路径的数组,因为需要Bourbon。 我会像这样连接数组: options: { includePaths: require('node-neat').includePaths.concat('/assets/bower_components/_normalize.scss') }, node-neat's includePaths property returns an array with both Bourbon ... -
如果将导入放在引号中,node-sass --watch可以工作。 问题出现在sass-graph中,对于缩进的sass语法不起作用。 链接到git问题: https : //github.com/sass/node-sass/issues/1179 /* * ************************** * file: ./style/bootstrap/bootstrap-sass * ************************** */ @import './style/boo ...