草庐IT

行名称

全部标签

c# - 找不到类型或命名空间名称 'Column'

我确定我在这里遗漏了一些简单的东西。我正在尝试遵循CodeFirstEntityFramework教程,该教程告诉我使用一些数据注释。usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.ComponentModel.DataAnnotations;namespaceModel{publicclassDestination{publicintDestinationId{get;set;}[Required]

c# - 在 WPF 中获取 "<Property Name> was already registered by "<控件名称>"错误

我在WPF中有一个用户控件,它绑定(bind)到一个依赖属性。当我尝试编译应用程序时,出现“属性名称”已由“控件名称”注册的错误,设计器显示“无法创建“用户控件”的实例”错误。这是我的简单控件的样子:ExampleUserControl.xaml:ExampleUserControl.xaml.cs:publicpartialclassExampleUserControl:UserControl{publicDependencyPropertySomeStringValueProperty=DependencyProperty.Register("SomeStringValue",ty

c# - 从国家名称或 RegionInfo 对象获取 CultureInfo 对象

给定一个特定的国家代码,例如“CH”,如何获得CultureInfo对象?特定国家/地区代码是动态的(在运行时更改)。我只有国家代码,我想知道是否可以仅国家代码创建CultureInfo对象。我得到的确切文化(fr-CH/de-CH)并不重要。我正在尝试做这样的事情:CultureInfoc=CultureInfo.CreateSpecificCulture("CH");是否可以从RegionInfo对象创建文化?然后它看起来像这样:RegionInfor=newRegionInfo("CH");CultureInfoc=CultureInfo.CreateSpecificCultur

c# - 为什么类成员的名称不能与其嵌套类之一相同?

或者为什么以下是不可能的:classMaterial{classKeys{...}Material.KeysKeys{get;set;}//Illegal}我没有看到任何可能的歧义。当被实例访问时,返回属性。静态访问时,返回类。还是我遗漏了什么?我不是在要求“修复”(我知道我可以将其命名为不同的名称,例如MaterialKeys等),但更多的是此限制背后的技术原因。 最佳答案 但是想象一下你有这个:classMaterial{classKeys{...}staticMaterial.KeysKeys=newKeys();}现在两者都

c# - 如何使用反射或其他准确方法获取 Controller 内部的当前 ASP.NET 核心 Controller 方法名称

我想获取我的ASP.NETCoreController的当前方法名称我试过通过反射获取方法名:[HttpGet]publicasyncTaskCreateProcess(intcatId){stringmethodName=System.Reflection.MethodBase.GetCurrentMethod().Name;但这给了我MoveNext而不是CreateProcess的值注意我不想使用ViewContextstringmethodName=ActionContext.RouteData.Values["action"].ToString();因为我通过启动设置将我的u

c# - 命名空间 'Hosting' 中不存在类型或命名空间名称 'Microsoft.AspNetCore.Razor'

我使用VisualStudio.NETCore2.1SDK+React模板创建了一个项目。我在运行项目时遇到了以下错误:Oneormorecompilationreferencesaremissing.Ensurethatyourprojectisreferencing'Microsoft.NET.Sdk.Web'andthe'PreserveCompilationContext'propertyisnotsettofalse.Thetypeornamespacename'Hosting'doesnotexistinthenamespace'Microsoft.AspNetCore.R

c# - 如何在 C# 中获得 RGB 值的同时获取颜色名称?

我正在创建一个应用程序来查找图像中最常用的颜色,我正在获取颜色的RGB值,但是如何获取颜色名称,请帮助。 最佳答案 如评论中所述,KnownColor枚举可用于简化此操作:usingSystem;usingSystem.Collections.Generic;usingSystem.Drawing;usingSystem.Linq;usingSystem.Reflection;classTest{staticvoidMain(){Colorcolor=Color.FromArgb(255,0,0);Console.WriteLine

c# - 如何从绑定(bind)到 List<T> 或匿名类型的绑定(bind)源中获取正确的映射名称以用于 DataGridTableStyle?

我正在尝试创建一个DataGridTableStyle对象,以便我可以控制DataGrid的列宽。我创建了一个绑定(bind)到列表的BindingSource对象。实际上,它绑定(bind)到通过Linq以下列方式创建的匿名类型列表(为了清楚我正在做的事情而更改了变量名称):ListmyList=newList(someCapacity);....populatethelistwithqueryfromdatabase....varquery=fromiinmyListselectnew{i.FieldA,i.FieldB,i.FieldC};myBindingSource.Data

c# - 如何使用 SqlCommand 以参数化数据库名称创建数据库?

简而言之。我有两个简单的助手:privateSqlCommandCreateCommand(stringtext){SqlCommandcmd=newSqlCommand();cmd.Connection=connection;cmd.CommandType=CommandType.Text;cmd.CommandText=text;returncmd;}voidSetParameter(SqlCommandcmd,stringp,stringdbName){cmd.Parameters.Add(p,SqlDbType.NVarChar);cmd.Parameters[p].Value

c# - Action 名称的 Web API 路由

我需要一个Controller来返回JSON以供JavaScript使用,因此我继承了ApiController类,但它的行为并不像我预期的那样。Apress书籍ProASP.NETMVC4和我找到的大多数在线示例都提供了如下示例:publicclassServicesController:ApiController{publicstring[]MethodFruit(){returnnewstring[]{"Apple","Orange","Banana"};}通过URL访问:http://mysite/services/methodfruit但这永远行不通-找不到资源。我可以开始工