in

CodeSmith Community

Your Code. Your Way. Faster!

Problem understanding the template arguments

Last post 03-10-2005 5:41 AM by whertzing56. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 03-08-2005 7:30 PM

    Problem understanding the template arguments

    Having trouble gettin the collection do what I want...
     
    I want a dictionarylist of Account objects (defined in namespace xyz), indexed by the Name property of the Account object. The Name property derives from the string type.
     
    My program's namespace is 'abc'.
     
    Trying these arguments to the  template:
    ClassName : dctAccountsByNameCollection
    Item Type: Account
    ItemValueTYpe: False
    KeyType: string
    KeyValueType:true
    PairType:Name_Account
     
    ImportNamespaces : false
    includeNamespace : true
    itemNamespaces : xyz
    Keynamespace : xyz
    targetnamespace : abc
     
    compiling this gives the error:
     
    C:\My Documents\Visual Studio Projects\abc\dctAccountsByNameCollection.cs(482): The namespace 'abc' already contains a definition for 'IstringCollection'
    I already have another dictionary class from the template, with a string key: dctContactsByNameCollection, which has an item type of 'Contacts'. Eventually, I'd like to have a number of dictionary objects that collect objects, and key them by a string property of the object itself.
     
    Will every collection have to have its own namespace?
     
    I tried to make the key type 'Name' - but that errors with the message "The type or namespace name 'Name' could not be found (are you missing a using directive or an assembly reference?)"
     
    What should the arguments be, to give me lots of different dictionary collections using a string to key them?
     
     
     
    • Post Points: 35
  • 03-09-2005 3:16 PM In reply to

    • cnahr
    • Top 50 Contributor
    • Joined on 06-03-2003
    • Posts 105
    • Points 2,275

    RE: Problem understanding the template arguments

    First of all, an unrelated thing: String is not a value type, so you must use the setting KeyValueType=false for all your string keys.

    Second, in order to use a property called Name as an optional ArrayList indexer you must set KeyName=Name.

    As for the namespaces, if you're reusing any element type in multiple collections (in the same target namespace) you must set the option IncludeInterfaces=false in all collections but one. Then you won't get duplicate IStringCollection interfaces.

    However... you won't get the required interfaces for Account either, so you must generate them manually with the IList.cst template. (Unless you already have defined an AccountCollection).

    Have you looked at the ReadMe.html file in the Collections directory of your CodeSmith installation folder? It's probably a bit impenetrable but it details all this stuff.
    • Post Points: 5
  • 03-10-2005 5:41 AM In reply to

    RE: Problem understanding the template arguments

    Thank you for the pointers - They have cleared up some basic points, and the readme is much easier to follow now. Thanks!
    • Post Points: 5
Page 1 of 1 (3 items)
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems