反思我自己的装配 [英] Reflection on my own assmbly
问题描述
我已在我的程序集中定义了一个公共枚举,我试图通过反射访问
:
键入theType = Type.GetType (MyAssemblyName.ParameterTypeEnum);
但我收到此错误:
对象引用未设置为对象的实例。
为什么我举起例如Syste.Reflection.Assembly?而不是
MyAssemblyName.ParameterTypeEnum,它可以工作,但它适用于我的工作。
" ParameterTypeEnum"
可以在我的代码中访问,但是当我尝试提取其类型时,它显示
错误。
提前感谢
I have defined a public enum in my assembly and I am trying to have access
to it through reflection:
Type theType = Type.GetType("MyAssemblyName.ParameterTypeEnum");
but I get this error:
Object reference not set to an instance of an object.
Why if I put for instance ,"Syste.Reflection.Assembly" instead of
"MyAssemblyName.ParameterTypeEnum",it works but it dosent work for mine.the
"ParameterTypeEnum"
is accessible in my code but when I try to extract its type,it shows that
error.
Thanks in advance
推荐答案
ALI-R< ne **** @ microsoft.com>写道:
ALI-R <ne****@microsoft.com> wrote:
我已经在我的程序集中定义了一个公共枚举,我试图通过反射访问它:
键入theType = Type.GetType( MyAssemblyName.ParameterTypeEnum;;
但我收到此错误:
对象引用未设置为对象的实例。
为什么例如,如果我提出Syste.Reflection.Assembly,而不是
MyAssemblyName.ParameterTypeEnum,它可以工作,但它适用于我的工作。
ParameterTypeEnum
可以在我的代码中访问但是当我尝试提取时它的类型,它表明
错误。
I have defined a public enum in my assembly and I am trying to have access
to it through reflection:
Type theType = Type.GetType("MyAssemblyName.ParameterTypeEnum");
but I get this error:
Object reference not set to an instance of an object.
Why if I put for instance ,"Syste.Reflection.Assembly" instead of
"MyAssemblyName.ParameterTypeEnum",it works but it dosent work for mine.the
"ParameterTypeEnum"
is accessible in my code but when I try to extract its type,it shows that
error.
你不应该指定程序集名称 - 只需完全
限定(带名称空间)类型名称。程序集和命名空间是不同的概念。
你能发一个简短但完整的程序来演示
问题吗? />
请参阅 http:// www.pobox.com/~skeet/csharp/complete.html 了解详情
我的意思是什么。
-
Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet
如果回复小组,请不要给我发邮件
You shouldn''t be specifying the assembly name - just the fully
qualified (with namespace) type name. Assemblies and namespaces are
different concepts.
Could you post a short but complete program which demonstrates the
problem?
See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
对不起,按程序集名称我的意思是完全限定(带命名空间)
类型名称。该类型在我的业务逻辑层中(这是一个
assembmly,ofcource)这就是我说大会的原因。
输入类型=
Type.GetType(" MyCompanyName.MyAppName.BLL.Paramete rTypeEnum");
b ool test = theType.IsEnum; < ----------------我在这里得到错误,似乎
类型根本没有创建。
感谢你的帮助
" Jon Skeet [C#MVP]" < SK *** @ pobox.com>在消息中写道
新闻:MP ************************ @ msnews.microsoft.c om ...
Sorry ,by assembly name I meant just the fully qualified (with namespace)
type name.that type is in my Business logic layer (which is an
assebmly,ofcource) that''s why I said Assembly.
Type theType =
Type.GetType("MyCompanyName.MyAppName.BLL.Paramete rTypeEnum");
bool test= theType.IsEnum; <----------------I get the error here,seems that
the type hasn''t been created at all.
thanks for your help
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
ALI-R< ne **** @ microsoft.com>写道:
ALI-R <ne****@microsoft.com> wrote:
我已经在我的程序集中定义了一个公共枚举,我试图通过反射让
访问它:
输入类型= Type.GetType( MyAssemblyName.ParameterTypeEnum;;
但我收到此错误:
对象引用未设置为对象的实例。
为什么例如,如果我提出Syste.Reflection.Assembly,而不是
MyAssemblyName.ParameterTypeEnum,它可以工作,但它适用于
mine.theParameterTypeEnum
可以在我的代码中访问但是当我尝试提取时它的类型,它显示
那个错误。
I have defined a public enum in my assembly and I am trying to have access to it through reflection:
Type theType = Type.GetType("MyAssemblyName.ParameterTypeEnum");
but I get this error:
Object reference not set to an instance of an object.
Why if I put for instance ,"Syste.Reflection.Assembly" instead of
"MyAssemblyName.ParameterTypeEnum",it works but it dosent work for mine.the "ParameterTypeEnum"
is accessible in my code but when I try to extract its type,it shows that error.
你不应该指定程序集名称 - 只是完全
限定(带名称空间)类型名称。程序集和命名空间是不同的概念。
你能发布一个简短而完整的程序来演示
问题吗?
参见 http://www.pobox.com/~skeet/csharp/complete.html 详细了解我的意思。
-
Jon Skeet - < sk *** @ pobox.com>
如果回复小组,请不要给我发邮件
You shouldn''t be specifying the assembly name - just the fully
qualified (with namespace) type name. Assemblies and namespaces are
different concepts.
Could you post a short but complete program which demonstrates the
problem?
See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
宾果,我想我已经解决了这个问题:
我必须用过在我的BLL的
上下文中键入theType = Type.GetType(" ParameterTypeEnum"),因为它正是反射的意思,我做了
反射一个在BLL之外输入,在PL中输入,当然它不是可能的b $ b。我做的是创建一个返回的属性
我的PL的Type.GetType(ParameterTypeEnum)现在工作正常。
感谢您的帮助
ALi
" Jon Skeet [C#MVP]" < SK *** @ pobox.com>在消息中写道
新闻:MP ************************ @ msnews.microsoft.c om ...
Bingo,,I think I have solved the problem:
I must have used Type theType = Type.GetType("ParameterTypeEnum") in the
context of my BLL ,because it is exactly what reflection is for,,I did
reflection on a type outside of BLL and in PL ,,and ofcourse it is not
possible .what I did was to create a property which returns
Type.GetType("ParameterTypeEnum") to my PL and it is working fine now.
Thanks for your help
ALi
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
ALI-R< ne **** @ microsoft.com>写道:
ALI-R <ne****@microsoft.com> wrote:
我已经在我的程序集中定义了一个公共枚举,我试图通过反射让
访问它:
输入类型= Type.GetType( MyAssemblyName.ParameterTypeEnum;;
但我收到此错误:
对象引用未设置为对象的实例。
为什么例如,如果我提出Syste.Reflection.Assembly,而不是
MyAssemblyName.ParameterTypeEnum,它可以工作,但它适用于
mine.theParameterTypeEnum
可以在我的代码中访问但是当我尝试提取时它的类型,它显示
那个错误。
I have defined a public enum in my assembly and I am trying to have access to it through reflection:
Type theType = Type.GetType("MyAssemblyName.ParameterTypeEnum");
but I get this error:
Object reference not set to an instance of an object.
Why if I put for instance ,"Syste.Reflection.Assembly" instead of
"MyAssemblyName.ParameterTypeEnum",it works but it dosent work for mine.the "ParameterTypeEnum"
is accessible in my code but when I try to extract its type,it shows that error.
你不应该指定程序集名称 - 只是完全
限定(带名称空间)类型名称。程序集和命名空间是不同的概念。
你能发布一个简短而完整的程序来演示
问题吗?
参见 http://www.pobox.com/~skeet/csharp/complete.html 详细了解我的意思。
-
Jon Skeet - < sk *** @ pobox.com>
如果回复小组,请不要给我发邮件
You shouldn''t be specifying the assembly name - just the fully
qualified (with namespace) type name. Assemblies and namespaces are
different concepts.
Could you post a short but complete program which demonstrates the
problem?
See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
这篇关于反思我自己的装配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!