草庐IT

question_type

全部标签

c# - 是否可以将 Type.GetType 与动态加载的程序集一起使用?

假设我有这么一小段代码:publicstaticvoidLoadSomething(Typet){vart1=Type.GetType(t.AssemblyQualifiedName);vart2=t.Assembly.GetTypes().First(ta=>ta.AssemblyQualifiedName==t.AssemblyQualifiedName);}发生的情况是t1为null而t2为notnull。我很困惑,因为如果我这样调用它......LoadSomething(typeof(SomeObject));然后两者都为空,但我实际做的更像是这样(不是真的,这被大大简化了,

c# - 过滤掉 Type.GetMethods() 返回的自动生成的方法(getter/setter/add/remove/.etc)

我使用Type.GetMethods(BindingFlags.Instance|BindingFlags.Static|BindingFlags.Public|BindingFlags.NonPublic)检索给定类型的方法数组。问题是返回的MethodInfo可能包含编译器生成的方法,而我不想要这些方法。例如:propertyboolEnabled{get;将得到boolget_Enabled()事件SomethingChanged会得到add_SomethingChanged(事件处理程序)和remove_SomethingChanged(事件处理程序)我或许可以添加一些过滤逻辑

c# - 如何使用局部变量作为类型?编译器说 "it is a variable but is used like a type"

在运行时,我不知道什么类型的变量v1是。为此,我写了很多ifelse声明:if(v1isShellProperty){v2=(v1asShellProperty).Value;}elseif(v1isShellProperty){v2=(v1asShellProperty).Value;}elseif(v1isShellProperty){v2=(v1asShellProperty).Value;}elseif(v1isShellProperty){v2=(v1asShellProperty).Value;}唯一的区别在于ShellProperty.所以不要用很多ifelse来写这篇文

c# - PropertyInfo 实例上的 SetValue 错误 "Object does not match target type"c#

在以前的项目中的不同地方使用了带有这段代码的Copy方法(处理具有相同命名属性但不派生自公共(public)基类或实现公共(public)接口(interface)的对象)。新的工作地点,新的代码库-现在即使在非常简单的示例中,它也会在SetValue处失败并显示“对象与目标类型不匹配”......并且它在上周工作......publicstaticvoidCopy(objectfromObj,objecttoObj){TypefromObjectType=fromObj.GetType();TypetoObjectType=toObj.GetType();foreach(System

c# - LINQ to Entities Group By 表达式给出 'Anonymous type projection initializer should be simple name or member access expression'

我在这个表达式中遇到了上述错误:varaggregate=fromtinentities.TraceLinesjoinminentities.MethodNames.Where("it.NameLIKE@searchTerm",newObjectParameter("searchTerm",searchTerm))ont.MethodHashequalsm.MethodHashwhere(t.CallTypeId&(int)types)==t.CallTypeId&&t.UserSessionProcessId==m_SessionIdgrouptbym.Nameintodselect

c# - 检查 System.Type 是否是给定类的后代的最佳方法

考虑以下代码:publicclassA{}publicclassB:A{}publicclassC:B{}classD{publicstaticboolIsDescendantOf(thisSystem.TypethisType,System.TypethatType){///???}voidMain(){AcValue=newC();C.GetType().IsDescendantOf(cValue.GetType());}}实现IsDescendantOf的最佳方法是什么? 最佳答案 Type.IsSubclassOf()判断当

c# - T4代码生成: access types in current project

使用T4代码生成,是否可以访问当前项目中定义的类型?例如,如果我有一个接口(interface)并且我想将它的实现委托(delegate)给另一个类,即interfaceIDoSomething{publicvoiddo_something();}classDoSomethingImpl:IDoSomething{publicvoiddo_something(){//implementation...}}classSomeClass:IDoSomething{IDoSomethingm_doSomething=newDoSomethingImpl();//forwardcallstoi

c# - 在 C# 中实现安全的鸭子类型(duck typing)

看了之后如何Go处理接口(interface)并喜欢它,我开始考虑如何在C#中实现类似的duck-typing,如下所示:varmallard=newMallard();//doesn'timplementIDuckbuthastherightmethodsIDuckduck=DuckTyper.Adapt(mallard);DuckTyper.Adapt方法将使用System.Reflection.Emit动态构建适配器。也许有人已经写过这样的东西。我想这与模拟框架已经做的并没有太大不同。但是,如果Mallard实际上没有正确的IDuck方法,这将在运行时抛出异常。为了在编译时尽早发

c# - 嵌入式 RavenDB 出现 "Could not find transactional storage type"错误

我能够根据在以下位置找到的代码成功运行RavenDB的简单测试:http://ravendb.net/tutorials/hello-world接下来我尝试以嵌入式方式运行它,但我不断收到以下错误:Message:Couldnotfindtransactionalstoragetype:Raven.Storage.Esent.TransactionalStorage,Raven.Storage.EsentStackTrace:atRaven.Database.Config.InMemoryRavenConfiguration.CreateTransactionalStorage(Act

c# - Windows7 中的 VS 2010 设计器错误 'Could not find type XYZ'。在 XP 中工作正常

我在VS2010C#.NET中遇到了一个问题。我在WindowsXP上有一个项目,其中包括表单、类和一些我自己的自定义组件。这些组件是内置MS组件的简单扩展(例如DataGridViewEx作为DataGridView的扩展)。在XP中一切正常。我正在尝试将此项目移植到Windows7/x64上的VS2010。我有在Windows7上编译正常的解决方案,但是在设计模式下,当我打开包含自定义控件之一的窗体时,出现错误“找不到类型XYZ.DataGridViewEx”。请确保引用了包含此类型的程序集。'XYZ是我用于这些控件的命名空间,它与使用这些控件的窗体是同一个命名空间。所有都是同一个