小编Kei*_*h K的帖子

如何在Visual Studio书签或行中添加注释?

当我处于调试阶段时,我经常会找到多个可以改进(或修复)的区域,我喜欢将它们标记在一起,以便我可以稍后再回来并进行改进.

目前我在线上添加了一个书签,但这不能包含任何可用于提醒我书签为何的注释(您可以更改书签的名称,但这还不够).我想我真的希望能够在代码运行时向代码添加TODO但是虽然启用了编辑和继续,但它在ASP.NET WebForms(3.5)项目中不可用.

是否有任何Visual Studio功能或扩展可以实现此功能?

visual-studio visual-studio-2012

30
推荐指数
2
解决办法
1万
查看次数

使用反射动态地将属性转换为其实际类型

我需要动态地将属性转换为其实际类型.我如何/可以使用反射做到这一点?

解释我正在努力的真实场景.我试图在Entity Framework属性上调用"First"扩展方法.要在Framework上下文对象上调用的特定属性作为字符串传递给方法(以及要检索的记录的id).所以我需要对象的实际类型才能调用First方法.

我不能在对象上使用"Where"方法,因为lambda或delegate方法仍然需要对象的实际类型才能访问属性.

此外,由于对象是由实体框架生成的,因此我无法将类型转换为接口并对其进行操作.

这是场景代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Reflection;

namespace NmSpc
{

    public class ClassA
    {
        public int IntProperty { get; set; }
    }

    public class ClassB
    {
        public ClassA MyProperty { get; set; }
    }

    public class ClassC
    {
        static void Main(string[] args)
        {
            ClassB tester = new ClassB();

            PropertyInfo propInfo = typeof(ClassB).GetProperty("MyProperty");
            //get a type unsafe reference to ClassB`s property
            Object property = propInfo.GetValue(tester, null);

            //get the type safe reference to …
Run Code Online (Sandbox Code Playgroud)

c# reflection entity-framework

26
推荐指数
3
解决办法
4万
查看次数

是否有Visual Studio的会话管理器加载项,可以保存已打开的文件列表?

是否有Visual Studio的加载项允许您保存当前在Visual Studio中打开的文件/选项卡列表,例如您内置到Opera的会话管理器?

我不是说如何保存所有当前打开的文件(Ctrl + Shift + S)或者如何在重新打开Visual Studio时将所有打开的文件重新打开.

我的意思是如何为一个问题/错误打开一组文件,然后在另一个更重要的问题/错误出现时保存该列表,然后重新打开我之前打开的已保存文件列表.这样我就不必gp并找到我原来打开的所有文件,或者必须立即打开大量文件.

谢谢

基思

visual-studio-2008 visual-studio

16
推荐指数
2
解决办法
3119
查看次数

如何在ASP.NET WebForms中指定内容类型?

我将我的doctype指定为xhtml strict,但它是作为text/html的内容类型通过网络发送的.我想指定内容类型是application/xhtml + xm,但我无法弄清楚我可以在我的应用程序中配置它的位置

asp.net webforms content-type xhtml-1.0-strict

8
推荐指数
1
解决办法
2万
查看次数

在Windows服务中打开Microsoft Word文档似乎挂起了

我有一个用c#编写的Windows服务,它使用VBA Interop从word文档(doc和docx)中读取文本.但是在某些文档上似乎挂起了对Open方法的调用.似乎问题文档中都有宏.本地安装的word版本已禁用宏,我用来打开文档的代码如下:

using Word = Microsoft.Office.Interop.Word;
using OfficeCore = Microsoft.Office.Core;

Word.Application m_wordApp = new Word.ApplicationClass();
Word.Document m_wordDoc = null;

object TRUE_VALUE = true;
object FALSE_VALUE = false;
object MISSING_VALUE = System.Reflection.Missing.Value;

m_wordApp.DisplayAlerts = Microsoft.Office.Interop.Word.WdAlertLevel.wdAlertsNone; //will still fail with this line removed
m_wordApp.Visible = false; //will still fail with this line removed
m_wordApp.AutomationSecurity = Microsoft.Office.Core.MsoAutomationSecurity.msoAutomationSecurityForceDisable; //will still fail with this line removed
m_wordDoc = m_wordApp.Documents.Open(ref fileNameObject, ref FALSE_VALUE, ref TRUE_VALUE, ref FALSE_VALUE, ref MISSING_VALUE, ref MISSING_VALUE, ref MISSING_VALUE, ref MISSING_VALUE, ref …
Run Code Online (Sandbox Code Playgroud)

c# interop windows-services ms-word

8
推荐指数
2
解决办法
1万
查看次数

Favicon创作

我想创建一个在主浏览器(包括IE7)显示时看起来最好的图标,但文件大小可能最小.什么尺寸和颜色深度最适合每个图像?

我刚刚创建了一个带有以下图像的新图标.
16x16位(8位颜色)
32x32位(8位颜色)

我是否应该为桌面快捷方式,Win7任务栏固定或任何其他使用浏览器或操作系统创建任何其他图像?

注意:这与您可以用来创建favicon的任何软件无关

favicon

6
推荐指数
1
解决办法
1467
查看次数

ASP.NET StateBag和自定义控件

让我假装由于某种原因我想创建一个派生自Control而不是WebControl的自定义控件.让我们假设我需要处理属性(即实现IAttributeAccessor),并且我想通过像WebControl一样使用AttributeCollection来实现.

WebControl实现Attributes属性,如下所示:


public AttributeCollection Attributes
{
    get
    {
        if (this.attrColl == null)
        {
            if (this.attrState == null)
            {
                this.attrState = new StateBag(true);
                if (base.IsTrackingViewState])
                {
                    this.attrState.TrackViewState();
                }
            }
            this.attrColl = new AttributeCollection(this.attrState);
        }
        return this.attrColl;
    }
}

请注意以下事项:

  1. 如果没有给StateBag,就不能创建AttributeCollection.
  2. 我们必须创建一个新的StateBag.重用控件StateBag是不明智的,因为属性可能将名称作为控件存储的值.
  3. 我们不能在StateBag上调用TrackViewState,因为这是一个内部方法.
  4. StateBag是一个密封的类.

因此,据我所知,如果我想使用AttributeCollection,我必须使用一个新的StateBag,它永远不会(不采用像反射这样的技巧)实际正确地管理状态.

我错过了什么吗?

c# asp.net viewstate custom-server-controls

5
推荐指数
1
解决办法
2562
查看次数

WCF中的另一个应用程序使用的端口

尝试使用以下配置运行时,我遇到了WCF自托管应用程序的问题:

  <system.serviceModel>
    <services>
      <service name="statisticsCollectingService">
        <endpoint address="net.tcp://localhost:8200/RadioStatistics/"
                binding="netTcpBinding"
                contract="RadioStatistics.Services.IStatisticsCollectingService" />
        <endpoint address="http://localhost:8100/RadioStatistics/"
                binding="basicHttpBinding"
                contract="RadioStatistics.Services.IStatisticsCollectingService" />
      </service>

      <service name="biDataExportService">
        <endpoint address="net.tcp://localhost:8001/RadioStatistics/" 
                  binding="netTcpBinding" 
                  contract="RadioStatistics.Services.IBIDataExportService" />
      </service>
    </services>
  </system.serviceModel>
Run Code Online (Sandbox Code Playgroud)

例外情况如下:

System.Configuration.ConfigurationErrorsException: Error creating context 'spring.root': The process cannot access the file because it is being used by another process ---> Spring.Objects.Factory.ObjectCreationException: Error creating object with name 'statisticsCollectingServiceHost' defined in 'config [C:\TTL\zer_rel_12_1_main_TTL_C1077\TTL\CommonTools\RadioStatistics\bin\Debug\RadioStatistics.ServerApp.vshost.exe.Config#spring/objects] line 4' : Initialization of object failed : HTTP could not register URL http://+:8000/RadioStatistics/services/ because TCP port 8000 is being used by …
Run Code Online (Sandbox Code Playgroud)

wcf

5
推荐指数
1
解决办法
8512
查看次数

将wsHttpBinding转换为customBinding

如何将以下wsHttpBinding转换为customBinding?我需要这样,所以我可以增加时钟偏差.这是为http.

 <wsHttpBinding>
    <binding name="wsHttpSecurityOptions" maxReceivedMessageSize="10485760" maxBufferPoolSize="524288">
      <security mode="Message">
        <message clientCredentialType="UserName" establishSecurityContext="true" negotiateServiceCredential="true"/>
        <transport clientCredentialType="Certificate" proxyCredentialType="None"/>
      </security>
      <readerQuotas maxStringContentLength="500000"/>
    </binding>
  </wsHttpBinding>
Run Code Online (Sandbox Code Playgroud)

我的尝试(如下所示)失败,并显示错误消息"无法找到与绑定CustomBinding的端点匹配方案https的基址",但我看不出如何配置UserName消息模式安全性.

  <customBinding>
    <binding name="wsHttpSecurityOptions">
      <transactionFlow />
      <security authenticationMode="UserNameForSslNegotiated">
        <secureConversationBootstrap authenticationMode="UserNameForSslNegotiated">
          <localServiceSettings maxClockSkew="00:10:00" />
        </secureConversationBootstrap>
        <localServiceSettings maxClockSkew="00:10:00" />
      </security>
      <textMessageEncoding>
        <readerQuotas maxStringContentLength="500000"/>
      </textMessageEncoding>
      <httpsTransport maxReceivedMessageSize="10485760" maxBufferPoolSize="524288" />
    </binding>
  </customBinding>
Run Code Online (Sandbox Code Playgroud)

wcf wcf-binding

5
推荐指数
1
解决办法
1万
查看次数