字典对象名称/值对 [英] Dictionary Object name/value pair
问题描述
我正在尝试复制在Commerce Server 3.0中找到
的Commerce.Dictionary对象的行为
通过使用哈希表或创建一个实现IDictionary的自定义类,
你必须使用以下语法添加元素。
DictionaryObject.Add(" key","值");
但是,旧的Commerce Server Dictionary对象使用了以下
语法。
DictionaryObject .Name =" Fred"
在这个例子中,字典对象创建一个名为
" Name"的新元素键。并指定Fred的值对它来说。
关于如何复制这个的任何想法?
I''m trying to replicate the behaviour of the Commerce.Dictionary object that
was found in Commerce Server 3.0
By using a hashtable or creating a custom class that implements IDictionary,
you have to add elements by using the following syntax.
DictionaryObject.Add("key","value");
However, the old Commerce Server Dictionary object used the following
syntax.
DictionaryObject.Name = "Fred"
In this instance, the dictionary object creates a new element key called
"Name" and assigns the value of "Fred" to it.
Any thoughts on how to replicate this?
推荐答案
可能有什么办法要做是创建一个Dictionary对象,然后是一个
字典对象集合,所以更像是
公共类MyDictObj
{
//有会员名称
}
公共类CMyDictObj:CollectionBase
{
//代表MyDictObj的集合
}
HTH
VJ
Dave Young < da *************** @ softwarespectrum.com写信息
新闻:OB ************** @ TK2MSFTNGP02.phx.gbl ...
What are probably looking to do is create a Dictionary Object and then a
Collection of Dictionary Object, so more like
Public class MyDictObj
{
// has member name
}
public class CMyDictObj : CollectionBase
{
// represents collection of MyDictObj
}
HTH
VJ
"Dave Young" <da***************@softwarespectrum.comwrote in message
news:OB**************@TK2MSFTNGP02.phx.gbl...
我正在尝试复制Commerce.Dictionary对象的行为
找到
在Commerce Server 3.0中
通过使用哈希表或创建实现
IDictionary的自定义类,您必须使用以下语法添加元素。 />
DictionaryObject.Add(" key"," value");
但是,旧的Commerce Server Dictionary对象使用以下
语法。
DictionaryObject.Name =" Fred"
在这个例子中,字典对象创建一个新的元素键名为
" Name"并指定Fred的值对它来说。
关于如何复制这个的任何想法?
I''m trying to replicate the behaviour of the Commerce.Dictionary object
that was found in Commerce Server 3.0
By using a hashtable or creating a custom class that implements
IDictionary, you have to add elements by using the following syntax.
DictionaryObject.Add("key","value");
However, the old Commerce Server Dictionary object used the following
syntax.
DictionaryObject.Name = "Fred"
In this instance, the dictionary object creates a new element key called
"Name" and assigns the value of "Fred" to it.
Any thoughts on how to replicate this?
它是'不完美,但你可以使用索引器来减少修改的金额。
private Dictionary< string,stringhash = new Dictionary< string,string> ();
public string this [string key]
{
get
{
返回哈希[key];
}
set
{
hash [ key] = value;
}
}
这意味着代替:
DictionaryObject.Name =" Fred"
你这样做:
DictionaryObject [" Name"] =" Fred" ;
我认为动态创建属性是不可能的,因为C#是一种静态类型语言,如果属性你会得到一个编译器错误
你要求的
不存在。
如果你真的希望它像这样工作,不要关心你可以膨胀
写一个codeGen来创建一个类文件,每个字母组合
组合作为属性创建。
作为A的例子:
公共字符串A
{
get
{
返回哈希[" A"];
}
set
{
hash [" A"] = value;
}
}
但是那个将是一个非常严肃的文件。
HTH
Simon
Dave Young < da *************** @ softwarespectrum.com写信息
新闻:OB ************** @ TK2MSFTNGP02.phx.gbl ...
It''s not perfect, but you could use an indexer to reduce the amount of
modification.
private Dictionary<string, stringhash = new Dictionary<string, string>();
public string this[string key]
{
get
{
return hash[key];
}
set
{
hash[key] = value;
}
}
Which means that instead of:
DictionaryObject.Name = "Fred"
you do:
DictionaryObject["Name"] = "Fred";
I think it''s not possible to dynamically create properties as C# is a
statically typed language and you will get a compiler error if the property
you are asking for does not exist.
If you REALLY want it to work like this and don''t care about bloat you could
write a codeGen to create a class file with every single alphabetical
combination created as a property.
As an example of A:
public string A
{
get
{
return hash["A"];
}
set
{
hash["A"] = value;
}
}
But that would be a seriously LONG file.
HTH
Simon
"Dave Young" <da***************@softwarespectrum.comwrote in message
news:OB**************@TK2MSFTNGP02.phx.gbl...
我正在尝试复制Commerce.Dictionary对象的行为
I''m trying to replicate the behaviour of the Commerce.Dictionary object
that
在Commerce Server 3.0中找到
通过使用哈希表或创建自定义类实现
was found in Commerce Server 3.0
By using a hashtable or creating a custom class that implements
IDictionary,
IDictionary,
你必须使用以下语法添加元素。
DictionaryObject.Add(" key"," value");
但是,旧的Commerce Server Dictionary对象使用了以下内容
语法。
DictionaryObject.Name =" Fred"
在这个例子中,字典对象创建一个新的元素键名为
" Name"并指定Fred的值对它来说。
关于如何复制这个的想法?
you have to add elements by using the following syntax.
DictionaryObject.Add("key","value");
However, the old Commerce Server Dictionary object used the following
syntax.
DictionaryObject.Name = "Fred"
In this instance, the dictionary object creates a new element key called
"Name" and assigns the value of "Fred" to it.
Any thoughts on how to replicate this?
我真的不明白这一点。
你不能只使用数据库吗?
SQL Server是否比这个?
-Todos
3月13日上午11点16分,Dave Young
< dave.young.nos ... @ softwarespectrum.comwrote:
I don''t really understand the point.
Can''t you just use a database?
Is SQL Server more complex than this?
-Todos
On Mar 13, 11:16 am, "Dave Young"
<dave.young.nos...@softwarespectrum.comwrote:
我正在尝试复制Commerce.Dictionary对象的行为
在Commerce Server 3.0中找到
通过使用哈希表或创建实现IDictionary的自定义类,
你必须添加元素使用以下语法。
DictionaryObject.Add(" key"," value");
然而,旧的Commerce Server Dictionary对象使用以下
语法。
DictionaryObject.Name =" Fred"
在这个例子中,字典对象创建一个名为
" Name"的新元素键。并指定Fred的值对它来说。
关于如何复制这个的任何想法?
I''m trying to replicate the behaviour of the Commerce.Dictionary object that
was found in Commerce Server 3.0
By using a hashtable or creating a custom class that implements IDictionary,
you have to add elements by using the following syntax.
DictionaryObject.Add("key","value");
However, the old Commerce Server Dictionary object used the following
syntax.
DictionaryObject.Name = "Fred"
In this instance, the dictionary object creates a new element key called
"Name" and assigns the value of "Fred" to it.
Any thoughts on how to replicate this?
这篇关于字典对象名称/值对的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!