热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

使用HashTable映射对象引用-MapanobjectreferencewithHashTable

IdliketomapareferencetoanobjectinsteadoftheobjectvaluewithanHashTable我想用HashTable映

I'd like to map a reference to an object instead of the object value with an HashTable

我想用HashTable映射对象的引用而不是对象值

configMapping.Add("HEADERS_PATH", Me.headers_path)

that way when I'm going to retrieve the value of "HEADERS_PATH" I'll be able to assign a value to Me.headers_path

那样当我要检索“HEADERS_PATH”的值时,我将能够为Me.headers_path分配一个值。

something like the " & " operator in C

像C中的“&”运算符

4 个解决方案

#1


3  

I am assuming that Me.headers_path is a System.String. Because System.String are immutable what you want cannot be achieved. But you can add an extra level of indirection to achieve a similar behavior.

我假设Me.headers_path是一个System.String。因为System.String是不可变的,你想要的是无法实现的。但是您可以添加额外的间接级别来实现类似的行为。

All problems in computer science can be solved by another level of indirection. Butler Lampson

计算机科学中的所有问题都可以通过另一层次的间接解决。巴特勒兰普森

Sample in C# (Please be kind to edit to VB and remove this comment later):

C#中的示例(请善意编辑VB并稍后删除此评论):

public class Holder {
    public T Value { get; set; }
}

...

Holder headerPath = new Holder() { Value = "this is a test" };
configMapping.Add("HEADERS_PATH", headerPath);

...

((Holder)configMapping["HEADERS_PATH"]).Value = "this is a new test";

// headerPath.Value == "this is a new test"

#2


1  

make headers_path be a propriety (with set)

make headers_path是一个合适的(带有set)

#3


1  

This would appear to be a dictionary, which in .Net 2.0 you could define as Dictionary if the references you want to update are always strings, or Dictionary (not recommended) if you want to get an arbitrary reference.

这似乎是一个字典,在.Net 2.0中,如果要更新的引用总是字符串,则可以定义为Dictionary;如果要获取任意引用,则可以定义为Dictionary(不推荐)。

If you need to replace the values in the dictionary you could define your own class and provide some helper methods to make this easier.

如果您需要替换字典中的值,您可以定义自己的类并提供一些帮助方法以使其更容易。

#4


1  

I am not entirely sure what you want to do. Assuming that smink is correct then here is the VB translation of his code. Sorry I can't edit it, I don't think I have enough rep yet.

我不完全确定你想做什么。假设smink是正确的,那么这里是他的代码的VB转换。抱歉,我无法编辑它,我认为我还没有足够的代表。

public class Holder(Of T)
    public Value as T 
end class
...
Dim headerPath as new Holder(Of String)
headerPath.Value = "this is a test"
configMapping.Add("HEADERS_PATH", headerPath)
...
Directcast(configMapping["HEADERS_PATH"]),Holder(Of String)).Value = "this is a new test"

'headerPath.Value now equals "this is a new test"

@marcj - you need to escape the angled brackets in your answer, so use for a >. Again sorry I couldn't just edit your post for you.

@marcj - 您需要在答案中转义有角度的括号,因此请使用<对于 <和>为了> 。再说抱歉,我不能为你编辑你的帖子。


推荐阅读
  • http:my.oschina.netleejun2005blog136820刚看到群里又有同学在说HTTP协议下的Get请求参数长度是有大小限制的,最大不能超过XX ... [详细]
  • 在Android开发中,使用Picasso库可以实现对网络图片的等比例缩放。本文介绍了使用Picasso库进行图片缩放的方法,并提供了具体的代码实现。通过获取图片的宽高,计算目标宽度和高度,并创建新图实现等比例缩放。 ... [详细]
  • Linux服务器密码过期策略、登录次数限制、私钥登录等配置方法
    本文介绍了在Linux服务器上进行密码过期策略、登录次数限制、私钥登录等配置的方法。通过修改配置文件中的参数,可以设置密码的有效期、最小间隔时间、最小长度,并在密码过期前进行提示。同时还介绍了如何进行公钥登录和修改默认账户用户名的操作。详细步骤和注意事项可参考本文内容。 ... [详细]
  • 标题: ... [详细]
  • C++字符字符串处理及字符集编码方案
    本文介绍了C++中字符字符串处理的问题,并详细解释了字符集编码方案,包括UNICODE、Windows apps采用的UTF-16编码、ASCII、SBCS和DBCS编码方案。同时说明了ANSI C标准和Windows中的字符/字符串数据类型实现。文章还提到了在编译时需要定义UNICODE宏以支持unicode编码,否则将使用windows code page编译。最后,给出了相关的头文件和数据类型定义。 ... [详细]
  • 摘要: 在测试数据中,生成中文姓名是一个常见的需求。本文介绍了使用C#编写的随机生成中文姓名的方法,并分享了相关代码。作者欢迎读者提出意见和建议。 ... [详细]
  • 本文介绍了在CentOS上安装Python2.7.2的详细步骤,包括下载、解压、编译和安装等操作。同时提供了一些注意事项,以及测试安装是否成功的方法。 ... [详细]
  • IjustinheritedsomewebpageswhichusesMooTools.IneverusedMooTools.NowIneedtoaddsomef ... [详细]
  • Windows7 64位系统安装PLSQL Developer的步骤和注意事项
    本文介绍了在Windows7 64位系统上安装PLSQL Developer的步骤和注意事项。首先下载并安装PLSQL Developer,注意不要安装在默认目录下。然后下载Windows 32位的oracle instant client,并解压到指定路径。最后,按照自己的喜好对解压后的文件进行命名和压缩。 ... [详细]
  • This article discusses the efficiency of using char str[] and char *str and whether there is any reason to prefer one over the other. It explains the difference between the two and provides an example to illustrate their usage. ... [详细]
  • 本文介绍了OpenStack的逻辑概念以及其构成简介,包括了软件开源项目、基础设施资源管理平台、三大核心组件等内容。同时还介绍了Horizon(UI模块)等相关信息。 ... [详细]
  • MPLS VP恩 后门链路shamlink实验及配置步骤
    本文介绍了MPLS VP恩 后门链路shamlink的实验步骤及配置过程,包括拓扑、CE1、PE1、P1、P2、PE2和CE2的配置。详细讲解了shamlink实验的目的和操作步骤,帮助读者理解和实践该技术。 ... [详细]
  • 本文讨论了如何使用Web.Config进行自定义配置节的配置转换。作者提到,他将msbuild设置为详细模式,但转换却忽略了带有替换转换的自定义部分的存在。 ... [详细]
  • 纠正网上的错误:自定义一个类叫java.lang.System/String的方法
    本文纠正了网上关于自定义一个类叫java.lang.System/String的错误答案,并详细解释了为什么这种方法是错误的。作者指出,虽然双亲委托机制确实可以阻止自定义的System类被加载,但通过自定义一个特殊的类加载器,可以绕过双亲委托机制,达到自定义System类的目的。作者呼吁读者对网上的内容持怀疑态度,并带着问题来阅读文章。 ... [详细]
  • 本文介绍了Oracle存储过程的基本语法和写法示例,同时还介绍了已命名的系统异常的产生原因。 ... [详细]
author-avatar
龙叔君_541
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有