.Net System.Collections.Generic.List


#1

How I can create List collection with Maxscript.

I tried this way, but no luck.


dotnetObject "System.Collections.Generic.List<string>"


#2

Generics have a funky syntax.

One method I found that works is to append a backtick followed by the number of generic types required for the definition, followed by the list of argument types in square brackets.

slist = dotnetobject “System.Collections.Generic.List`1[System.String]”

slist.add “zero”
slist.add “one”
slist.add “two”
slist.add “three”

print slist.item[0]
print slist.item[1]
print slist.item[2]
print slist.item[3]

sdict = dotnetobject “System.Collections.Generic.Dictionary`2[System.String,System.Char]”

sdict.add “eh” “a”
sdict.add “bee” “b”
sdict.add “sea” “c”

print sdict.item[“eh”]
print sdict.item[“bee”]
print sdict.item[“sea”]

Hope this helps,

.biddle


#3

Thanks.

I end up to use runtime .NET compiler and create ListCollections with C#. It worked fine in this case, but thanks for your replay I am sure than it will be useful.

Here’s code for compiler what I founded somewhere here at CGTalk.


fn createAssembly src =
(
	csharpProvider = dotnetobject "Microsoft.CSharp.CSharpCodeProvider"
	compilerParams = dotnetobject "System.CodeDom.Compiler.CompilerParameters"
	compilerParams.CompilerOptions = "/t:library"
	compilerParams.GenerateInMemory = true
	compilerResults = csharpProvider.CompileAssemblyFromSource compilerParams #(src)
	
	if (compilerResults.Errors.Count > 0 ) then
	(
		errs = stringstream ""
		for i = 0 to (compilerResults.Errors.Count-1) do
		(
			err = compilerResults.Errors.Item[i]
			format "Error:% Line:% Column:% %
" err.ErrorNumber err.Line \											  
												 err.Column err.ErrorText to:errs 
		)
		MessageBox (errs as string) title: "Errors encountered while compiling C# code"
		return undefined
	)
	
	a = compilerResults.CompiledAssembly
)

Now you can read .cs file and pass code to createAssembly function. Compiling take’s couple seconds in my case, but I guess than more complex program can take a lot longer.


#4

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.