简体   繁体   English

'objType'没有定义......实际上,它是,所以为什么会发生这种情况?

[英]'objType' is not defined… Actually, it is, so why is this happening?

As you seen in this picture below, for some reason my DirectCast wont except ANYTHING for the second argument. 正如您在下面的图片中看到的那样,出于某种原因,我的DirectCast除了ANYTHING之外不会出现第二个参数。 It says it requires a type, but, it won't take any object at all! 它说它需要一种类型,但它根本不需要任何对象!

在此输入图像描述

Thanks for any help! 谢谢你的帮助! I'm using VB.net so all .net answers are acceptable :) 我正在使用VB.net所以所有的.net答案都可以接受:)

EDIT 编辑

Ok, so apparently I'm not giving it the right kind of type . 好吧,显然我没有给它正确的type Could somebody please clarify this? 有人可以澄清一下吗? Assuming the type it needs to cast to is gridElement , what should I replace objType with? 假设它需要转换为gridElement的类型,我应该用什么替换objType?

DirectCast requires an object prototype (ie just giving it the intended class name) rather than a System.Type descriptor object. DirectCast需要一个对象原型(即只是给它预期的类名)而不是System.Type描述符对象。 To cast an object using a System.Type , you will want to utilize CTypeDynamic() : 要使用System.Type对象,您需要使用CTypeDynamic()

Return CTypeDynamic(createElementByIdAndLayer.MemberwiseClone(), objType)

The error is essentially telling you a class with the type name "objType" does not exist. 该错误基本上告诉您类型名称为“objType”的类不存在。

Its expecting a "Type", not a "Type Object". 它期待“类型”,而不是“类型对象”。

What is the return value of the function? 该函数的返回值是多少?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM