草庐IT

activity-element

全部标签

c# - 我可以将 Activator.CreateInstance 与接口(interface)一起使用吗?

我有一个例子:Assemblyasm=Assembly.Load("ClassLibrary1");Typeob=asm.GetType("ClassLibrary1.UserControl1");UserControluc=(UserControl)Activator.CreateInstance(ob);grd.Children.Add(uc);我正在创建类的实例,但是如何创建实现某个接口(interface)的类的实例?即UserControl1实现了ILoad接口(interface)。U:我可以稍后将对象转换为接口(interface),但我不知道程序集中的哪个类型实现了该接

c# - 具有私有(private)密封类的 Activator.CreateInstance

我正在尝试新建一个LocalCommand实例,它是System.Data.SqlClient.SqlCommandSet的私有(private)类。我似乎能够很好地获取类型信息:AssemblysysData=Assembly.Load("System.Data,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089");localCmdType=sysData.GetType("System.Data.SqlClient.SqlCommandSet+LocalCommand");但是当我尝试实例化Activat

c# - Visual Studio 2013 创建 Web API 项目时出错 : The element <#text> beneath element <Project> is unrecognized

我的VisualStudio安装有问题。为了重现它,我创建了一个新的空白解决方案,然后:添加新项目..ASP.NET网络应用程序网络应用程序接口(interface)创建项目VisualStudio无法创建它,我收到此消息:Theelementbeneathelementisunrecognized.有什么解决办法吗? 最佳答案 如果csproj包含无效的XML,您将得到这样的错误。我不小心删除了时遇到了这个错误在csproj文件中并留下-->: 关于c#-VisualStudio201

c# - 在 SelectSingleNode : Retrieving individual element from XML if it's present 中使用 XPath

我的XML看起来像:onetwothree.....maybemoreItemshere.一些单独的Item可能存在也可能不存在。假设我想检索元素两个如果它存在。我尝试了以下XPath(在C#中)。XMLNodenode=myXMLdoc.SelectSingleNode("/itemSet[Item='two']")---如果Itemtwo存在,则它只返回第一个元素one。也许这个查询只是指向itemSet中的第一个元素,如果它在某个地方有一个值为2的Item作为子元素。这种解释正确吗?所以我尝试了:XMLNodenode=myXMLdoc.SelectSingleNode("/it

C#/WPF : Binding Combobox ItemSource in Datagrid to element outside of the DataContext

我想做以下事情:publicListPreLoadedUserList{get;set;}publicListSomeDataRowList{get;set;}publicclassUsers{publicintAge{get;set;}publicstringName{get;set;}}publicclassSomeDataRowList{publicintUserAge{get;set;}现在我的(WPF工具包)DataGrid看起来像这样:现在我的问题是,PreLoadedUserList在ItemSource(SomeDataRowList)之外,我不知道如何绑定(bind)

c# - 如何使用 Principal Context 连接到 Active Directory?

我在这方面已经有一段时间了,而且我总是得到:System.DirectoryServices.AccountManagement.PrincipalServerDownException我认为这意味着我的连接设置(连接字符串)是错误的。当我在ActiveDirectory所在的计算机上的cmd上写入“dsqueryserver”时,我得到:"CN=DCESTAGIO,CN=SERVERS,CN=Default-First-Site-Name,CN=Sites,CN=Configuration,DC=estagioit,DC=local"我已尝试通过以下方式进行以下连接:1:Princi

C# 列出 : How to copy elements from one list to another, 但仅列出某些属性

所以我有一个具有许多属性的对象列表。这些属性包括name和id。我们称这个对象为ExtendedObject。我还声明了一个新的不同对象列表,这些对象仅name和id属性。我们称此对象为BasicObject。我想做的是将ExtendedObject对象列表转换或复制(因为缺少更好的词)到BasicObject对象列表。我知道C#列表有很多有用的有趣方法,所以我想知道是否有一种简单的方法可以表达以下效果:basicObjectList=extendedObjectList.SomeListMethod(someconditionhere);但我意识到它可能最终看起来不像那样。我还意识到

c# - 如何使用 Active Directory 通用身份验证打开 System.Data.SQLClient.SQLConnection

我使用以下代码连接到使用ActiveDirectory集成身份验证的SQLAzure数据库。privatestringGenerateConnectionString(stringdatabaseName,stringserverName){SqlConnectionStringBuilderconnBuilder=newSqlConnectionStringBuilder();sqlConnectionBuilder.DataSource=string.Format("tcp:{0}.database.windows.net",serverName);connBuilder.Init

c# - 给定 "where T : new()", "new T()"是否在内部使用 Activator.CreateInstance?

如果我有一个类型参数约束new():voidFoo()whereT:new(){vart=newT();}newT()是否会在内部使用Activator.CreateInstance方法(即反射)? 最佳答案 是的,这是真的。编辑2:这里很好地解释了方法和原因。http://www.simple-talk.com/community/blogs/simonc/archive/2010/11/17/95700.aspx为了验证我编译了如下方法:publicstaticTCreate()whereT:new(){returnnewT()

c# - 使用 C# 获取 Active Directory 中用户的父 OU

我想检查用户是否在特定的父OU中。我该怎么做?检查下面的代码,清楚地了解我在寻找什么。usingSystem.DirectoryServices.AccountManagement;publicboolIsUserInOU(stringsamAccountName,stringOUName){using(varcontext=newPrincipalContext(ContextType.Domain)){using(varuser=UserPrincipal.FindByIdentity(context,IdentityType.SamAccountName,samAccountNa