草庐IT

INDEX_CONTENT_TYPE

全部标签

c# - 如何从根 url 重定向到/swagger/ui/index?

我有一个安装了Swashbuckle的WebApi项目。在默认设置中,我必须在浏览器中打开http://localhost:56131/swagger/ui/index以查看我的操作描述和测试页面。我希望它可以从站点的根目录访问:http://localhost:56131/。我怎样才能做到这一点? 最佳答案 受thisanswertosimilarquestion影响,稍作修改的代码:publicclassWebApiConfig{publicstaticvoidConfigure(IAppBuilderapp){varhttpC

C# 泛型 : cast generic type to value type

我有一个泛型类,它保存指定类型T的值。该值可以是int、uint、double或float。现在我想获取值的字节以将其编码为特定协议(protocol)。因此我想使用方法BitConverter.GetBytes()但不幸的是Bitconverter不支持泛型类型或undefinedobject。这就是为什么我要转换值并调用GetBytes()的特定重载。我的问题:如何将通用值转换为int、double或float?这不起作用:publicclassGenericClasswhereT:struct{T_value;publicvoidSetValue(Tvalue){this._va

c# - 为什么不能将 Type 用作常量值?

引用MSDN-const(C#reference):Aconstantexpressionisanexpressionthatcanbefullyevaluatedatcompiletime.Therefore,theonlypossiblevaluesforconstantsofreferencetypesarestringandanullreference.根据:typeof(T)vs.Object.GetType()performance,typeof(T)是一个编译时表达式。那么为什么Type不能是常量值呢?以下代码不会编译:publicconstTypeINT_TYPE=ty

c# - .NETStandard 1.0/.NET Core 中 Type.GetGenericArguments() 的等价物是什么?

.NETStandard1.0中“缺少”方法System.Type.GetGenericArguments(),我认为TypeInfo.GenericTypeArguments是的替代品GetGenericArguments(),但不幸的是,当提供开放泛型类型时,它们的行为会有所不同。以下面的代码为例:Typetype=typeof(ICommandHandler);type.GetGenericArguments();//return{TCommand}type.GetTypeInfo().GenericTypeArguments;//returnsemptyarray虽然GetGe

c# - Dapper 抛出 "Invalid type owner for DynamicMethod."

所以我正在尝试使用Dapper.net,而且我很喜欢它。我不喜欢的是当我尝试批量插入实体时抛出以下错误:DynamicMethod的类型所有者无效。atSystem.Reflection.Emit.DynamicMethod.Init(Stringname,MethodAttributesattributes,CallingConventionscallingConvention,TypereturnType,Type[]signature,Typeowner,Modulem,BooleanskipVisibility,BooleantransparentMethod,StackCra

c# - 如何从基类中获取子类的 `Type`

我有一个抽象基类,我想在其中实现一个方法来检索继承类的特性属性。像这样的……publicabstractclassMongoEntityBase:IMongoEntity{publicvirtualobjectGetAttributeValue(stringpropertyName)whereT:Attribute{varattribute=(T)typeof(this).GetCustomAttribute(typeof(T));returnattribute!=null?attribute.GetType().GetProperty(propertyName).GetValue(a

c# - XML 序列化错误 : 2 types both use the XML type name, 'Relationship',来自命名空间 ''

我在通过XML进行序列化时遇到问题,因为2个类使用一个类(尽管类不同!)称为关系。我尝试使用XML属性用另一个名称装饰其中的一个类,但它仍然给我以下错误:{"Types'SiteServer.Relationship'and'LocalServer.Relationship'bothusetheXMLtypename,'Relationship',fromnamespace''.UseXMLattributestospecifyauniqueXMLnameand/ornamespaceforthetype."}这是我的2个类(class),有人知道为什么吗??我使用了错误的属性吗?它似

c# - 保留一个 Dictionary<Type, MyClass<T>> ,其中元素可以按类型引用

我有一个名为EntityTypeTransform的抽象类,它有一个抽象方法,用于保存将IDataRecord转换为T实例的Func委托(delegate)。publicabstractclassEntityTypeTransformwhereTEntityType:class{publicabstractFuncGetDataTransform();}该类的实现可能看起来像(看起来像):publicclassTaskParameterEntityTypeTransform:EntityTypeTransform{publicoverrideFuncGetDataTransform()

c# - ASP.NET MVC : Programmatically set HTTP headers on static content

我有一个ASP.NET应用程序,它在RegisterGlobalFilters中连接了一个过滤器,它执行以下操作:publicclassXFrameOptionsAttribute:ActionFilterAttribute{publicoverridevoidOnResultExecuting(System.Web.Mvc.ResultExecutingContextfilterContext){filterContext.HttpContext.Response.AddHeader("X-FRAME-OPTIONS","SAMEORIGIN");}}在Fiddler中,我可以看到从

c# - 编译转换 : The type 'Object' is defined in an assembly that is not referenced

我正在对一个asp.NetMVC5网络应用程序进行一些更改,我在其中使用了typelite从C#类创建.ts定义(非常方便)。出于某种原因,现在我在执行T4时遇到了这个错误:Compilingtransformation:Thetype'Object'isdefinedinanassemblythatisnotreferenced.Youmustaddareferencetoassembly'mscorlib,Version=2.0.5.0,Culture=neutral,PublicKeyToken=7cec85d7bea7798e,Retargetable=Yes'.和这个警告:C