草庐IT

base_classes

全部标签

c# - MVC 5 : Should I inherit my User from IdentityUser class?

我正在尝试学习Asp.NetIdentity和在这个tutorial,在Models\AppModels,cs部分创建EntityFramework代码优先ToDo模型MyUser类(class)继承自IdentityUser类和MyDbContext继承自IdentityDbContext类(class)。这是为什么?假设我有一个User包含我的Web应用程序用户的所有信息的类,该类是否应该继承自IdentityUser,我的DbContext是否应该继承?继承自IdentityDbContext?此外,从IdentityDbContext继承dbcontext类的优点是什么?平原D

c# - 为什么在 Windows 服务停止时调用 base.OnStop()?

我正在创建一个C#.NetWindows服务,我想知道您是否总是需要在服务的OnStop()方法中调用base.OnStop();并且为什么?protectedoverridevoidOnStop(){threadRunning=false;this.ExitCode=0;base.OnStop();} 最佳答案 来自ServiceBase.OnStop上的文档:OnStopisexpectedtobeoverriddeninthederivedclass.Fortheservicetobeuseful,OnStartandOnSt

c# - "Class of <T> where T : Enum"不工作

这个问题在这里已经有了答案:关闭11年前。PossibleDuplicate:CreateGenericmethodconstrainingTtoanEnum为什么我们不能在C#中执行此操作?而且,如果可能的话,我怎样才能做类似的事情!我想要什么:publicclassATagwhereT:enum{[Somecode..]}publicclassclassBasewhereT:enum{publicIDictionarytags{get;set;}}因此,当需要调用它时,我很确定只会获得我的枚举值之一。publicclassAClassUsingTag:classBase{publi

c# - C#中base()的使用

我一直在学习C#并想查看一些开源项目以查看一些编写好的代码。我在sourceforge上找到了一个名为Todomoo的项目,其中有一部分让我感到困惑:publicclassCategory{//Notepropertiesprivateintid=0;privatestringname="";privateColorcolour=Color.Gray;//////Createanewcategory.///publicCategory(){}//////Loadacategoryfromthedatabase.//////IDofthecategorypublicCategory(in

c# - 简易喷油器 : Registering a type with constructor argument that's based on its parent

我目前正在从我的项目中删除Ninject,并转而使用SimpleInjector,但有一件事我无法正常工作。对于我的日志记录,在注册服务时,我以前能够将参数传递到我的日志记录类中_kernel.Bind().To().WithConstructorArgument("name",x=>x.Request.ParentContext.Request.Service.FullName);我正在寻找一种在SimpleInjector中重新创建它的方法。到目前为止,除了这个,我还有其他所有工作。通过执行以下操作,我可以使日志记录正常工作,尽管没有显示正确的记录器名称:_container.Re

c# - "Possible multiple enumeration of IEnumerable"与 "Parameter can be declared with base type"

在Resharper5中,以下代码导致list出现警告“Parametercanbedeclaredwithbasetype”:publicvoidDoSomething(Listlist){if(list.Any()){//...}foreach(variteminlist){//...}}在Resharper6中,情况并非如此。但是,如果我将方法更改为以下内容,我仍然会收到该警告:publicvoidDoSomething(Listlist){foreach(variteminlist){//...}}原因是,在这个版本中,list只枚举一次,所以改成IEnumerable不会自动

c# - 使用 RegEx 验证字符串是否为 base64 格式?

我一直在寻找如何验证base64字符串并遇到了这个问题。^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$我需要一些帮助来让它允许“==”和“=”。谢谢 最佳答案 这应该表现得非常好。privatestaticreadonlyHashSet_base64Characters=newHashSet(){'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T'

c# - 错误 "A template containing a class feature must end with a class feature"

我在VisualStudio2010下开发C#T4预处理模板时遇到以下编译错误:Atemplatecontainingaclassfeaturemustendwithaclassfeature 最佳答案 错误是由最后一个#>后的不可见空格引起的同样重要的是要记住,不可见的空格可能会导致其他难以理解的编译错误。如果您想查看更大的图片,请查看以下链接:AgoodexampleAgoodexplanaton,通过RyanPugh既然您已经意识到处理文本模板时不可见空间的危害有多大,我的建议是:让它们可见。如果您不知道如何操作,请参阅Jee

c# - 单击选择性粘贴时如何在 visual studio 2012 中显示 "paste Json class"?

我正在尝试使用vs2012中过去的特殊功能,以便为我的Json数据生成c#类。我从Nuget从NewtonSoft下载了Json.New,然后添加了一个新的.cs类,将我的json数据复制到剪贴板,但是当我转到“编辑”->“选择性粘贴”->我只能看到:“将XML粘贴为类”仅粘贴JsonasClasses功能未显示。有什么建议么?提前谢谢你这就是我得到的,请注意我已经安装了Newtonsoft.Json:(来源:indevcogroup.com) 最佳答案 我创建了一个新项目,安装了Newtonsoft.Json并添加了一个类。如果您

c# - 这个和base的区别

我很想知道C#中this和base对象之间的区别。使用它们时的最佳做法是什么? 最佳答案 thisbase表示当前类实例parent。使用示例:publicclassParent{publicvirtualvoidFoo(){}}publicclassChild:Parent{//callconstructorinthecurrenttypepublicChild():this("abc"){}publicChild(stringid){}publicoverridevoidFoo(){//callparentmethodbase.