小编Dom*_*ang的帖子

我应该使用HttpRuntime.Cache吗?

我是asp.net的初学者,并且有一些关于Cache的问题:

  1. HttpRuntime.Cache只提供了几个方法,我想我可以自己用Dictionary实现这些方法.
  2. 如果HttpRuntime.Cache比Dictionary好多了,为什么有些人想要实现自己的缓存框架.
  3. MS Enterprise Cache Block怎么样?

c# caching httpruntime.cache

31
推荐指数
1
解决办法
3万
查看次数

为什么AppDomain.CurrentDomain.BaseDirectory在asp.net应用程序中不包含"bin"?

我有一个像以下网站项目:

namespace Web
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            lbResult.Text = PathTest.GetBasePath();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

该方法PathTest.GetBasePath()在另一个项目中定义,如:

namespace TestProject
{
    public class PathTest
    {
        public static string GetBasePath() 
        {
            return AppDomain.CurrentDomain.BaseDirectory;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

为什么...\Web\在将TestProject程序集编译到bin文件夹时显示它(换句话说,它应该显示...\Web\bin在我的想法中).

如果我修改了方法,我现在遇到了麻烦:

namespace TestProject
{
    public class FileReader
    {
        private const string m_filePath = @"\File.config";
        public static string Read() 
        {
            FileStream fs = null;
            fs = new FileStream(AppDomain.CurrentDomain.BaseDirectory + m_filePath,FileMode.Open, …
Run Code Online (Sandbox Code Playgroud)

c# asp.net .net-assembly

25
推荐指数
3
解决办法
5万
查看次数

为什么我要把try/catch块放在循环之外?

以下是Practice&Patterns团队的CodeReview指南.http://msdn.microsoft.com/zh-cn/library/ms998574#scalenetchapt13_topic7(该链接自动导航到"异常"部分.)

他们说当你处理异常时你应该把try/catch块放在循环之外,我想知道为什么?

c#

12
推荐指数
2
解决办法
7078
查看次数

Gson中的DateFormat模式"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"

我有两个字段如下(注意第一个字段有毫秒部分):

{
  "updateTime":"2011-11-02T02:50:12.208Z",
  "deliverTime"?"1899-12-31T16:00:00Z"
}
Run Code Online (Sandbox Code Playgroud)

我想用Json将Json字符串反序列化为一个对象,所以我得到一个Gson实例:

GsonBuilder gb = new GsonBuilder();
gb.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
gson = gb.create();
Run Code Online (Sandbox Code Playgroud)

第一个字段被反序列化为Java日期类型:2011-11-02 02:50:12.208(看起来像忽略了时区部分-'Z',这是我所期望的).但是,第二个字段被反序列化为1900-01-01 00:00:00(我住在中国,这里是+ 8 GMT),似乎时区部分-'Z'在反序列化中起作用.

为什么第二个字段使用时区部分?这不是我的预期.

java timezone gson

11
推荐指数
1
解决办法
6万
查看次数

如何通过| = C#中的运算符将负数转换为正数?

我们都知道Int32的最高位定义了它的符号.1表明它是负面的0,它是正面的(可能是逆转的).我可以通过更改其最高位将负数转换为正数吗?

我尝试使用以下代码执行此操作:

i |= Int32.MaxValue;
Run Code Online (Sandbox Code Playgroud)

但它不起作用.

c#

9
推荐指数
2
解决办法
5万
查看次数

Assembly.LoadFrom()抛出异常

public Assembly LoadAssembly(string assemblyName) //@"D://MyAssembly.dll"

{
    m_assembly = Assembly.LoadFrom(assemblyName);
    return m_assembly;
}
Run Code Online (Sandbox Code Playgroud)

如果我将"MyAssembly.dll"放在D:中并将其副本放在"bin"目录中,则该方法将成功执行.但是,我删除其中任何一个,它会抛出异常.消息如下:

无法加载文件或程序集"MyAssembly,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null"或其依赖项之一.该系统找不到指定的文件.

我想加载D:中存在的组件.为什么我需要同时将其副本放到"bin"目录?

c# reflection

1
推荐指数
1
解决办法
4219
查看次数

C#中'this'的含义是什么?

在'CLR via C#'的第170页:


public sealed class Program {
    public Int32 GetFive() { return 5; }
    public static void Main() {
       Program p = null;
       Int32 x = p.GetFive(); // In C#, NullReferenceException is thrown
    }
}
Run Code Online (Sandbox Code Playgroud)

从理论上讲,上面的代码很好.当然,变量p是null,但是当调用非虚方法(GetFive)时,CLR只需要知道p的数据类型,即Program.如果GetFive确实被调用,则此参数的值将为null.由于参数未在GetFive方法中使用,因此不会抛出NullReferenceException.


原谅我的愚蠢.我记得CLR通过'this'找到了真正的方法代码,它始终隐含在方法delcare的第一个参数中,为什么它说'当调用非虚方法(GetFive)时,CLR需要只知道p'的数据类型?

c# clr

1
推荐指数
1
解决办法
261
查看次数

solr如何使用autowarm?

在solrconfig.xml中,filterCache(或queryResultCache等)的'autowarmCount'表示当新的搜索者到来时将复制多少缓存实体.但是,如果我在solr中添加或删除doc,则旧搜索器中可能存在无效的缓存实体.我认为将缓存实体复制到新搜索者并不是一个好主意,对吗?

solr

1
推荐指数
1
解决办法
1834
查看次数

如何在xml-schema中声明一个类型?

我有一个类似下面的架构,color元素defaultinstance相同restriction(red/ green/ blue).我想将限制移到更高级别并color使用它设置所有元素(就像在Java/C#中声明类型或枚举一样)

我该怎么做?

<xs:element name="something">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="instance" maxOccurs="unbounded">
                <xs:complexType>
                    <xs:attribute name="name" type="xs:string" use="required"/>
                    <xs:attribute name="color" use="required">
                        <xs:simpleType>
                            <xs:restriction base="xs:string">
                                <xs:enumeration value="red"/>
                                <xs:enumeration value="green"/>
                                <xs:enumeration value="blue"/>
                            </xs:restriction>
                        </xs:simpleType>
                    </xs:attribute>
                </xs:complexType>
            </xs:element>
            <xs:element name="default">
                <xs:complexType>
                    <xs:attribute name="color" use="required">
                        <xs:simpleType>
                            <xs:restriction base="xs:string">
                                <xs:enumeration value="red"/>
                                <xs:enumeration value="green"/>
                                <xs:enumeration value="blue"/>
                            </xs:restriction>
                        </xs:simpleType>
                    </xs:attribute>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:element>
Run Code Online (Sandbox Code Playgroud)

xsd

0
推荐指数
1
解决办法
273
查看次数

标签 统计

c# ×6

.net-assembly ×1

asp.net ×1

caching ×1

clr ×1

gson ×1

httpruntime.cache ×1

java ×1

reflection ×1

solr ×1

timezone ×1

xsd ×1