小编Mas*_*aus的帖子

如何调用base.base.GetHashCode()等二级基类方法

class A
{
    public override int GetHashCode()
    {
        return 1;
    }
}
class B : A
{
    public override int GetHashCode()
    {
        return ((object)this).GetHashCode();
    }
}

new B().GetHashCode()
Run Code Online (Sandbox Code Playgroud)

这会溢出堆栈.我怎么能叫Object.GetHashCode()B.GetHashCode()

编辑:B现在继承自A.

c# inheritance

29
推荐指数
3
解决办法
2万
查看次数

C#.NET Rx- System.Reactive在哪里?

我有一个密集的Java背景,所以请原谅我,如果我忽略了C#中明显的东西,但我的研究让我无处可去.我正在尝试使用反应性Rx .NET库.编译器没有抱怨,IObservable但它是对zip方法的调用.它抛出"......你错过了使用指令或汇编参考吗?"

我一直在浏览命名空间,但我找不到想要的东西.System.Reactive如果使用的话,我找不到哪个也会抛出错误,并且此Windows 8.1应用程序已包含所有引用.有人可以告诉我有什么问题吗?

public sealed class EventEngine
{    
    private static readonly EventEngine singleton = new EventEngine();

    public static EventEngine get()
    {
        return singleton;
    }

    public IObservable<MusicNote> CurrentKey { get; set; }
    public IObservable<Scale> CurrentScale { get; set; }

    public IObservable<AppliedScale> CurrentAppliedScale
    {
        get
        {
            return CurrentScale.zip(CurrentKey,
                (s, k) => AppliedScale.getAppliedScale(k, s));
        } 
    }

    private EventEngine() {}
}
Run Code Online (Sandbox Code Playgroud)

*更新*

这是考虑答案输入后的工作版本.

public sealed class EventEngine
{
    private static readonly EventEngine singleton = new EventEngine();

    public …
Run Code Online (Sandbox Code Playgroud)

.net c# reactive-programming system.reactive

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

无法连接到pc-name\SQLEXPRESS

尝试通过SQL Server Management Studio 2005连接到SQL Server 2005标准版时,出现以下错误:

下面给出了错误的屏幕截图

我全力以赴解决这个问题,但没有解决方案.在给出以下帖子链接的堆栈溢出:

如何连接到SQL Server 2008 Express的本地实例

在这篇文章的一个答案中我找到了这个屏幕截图屏幕拍摄的解决方案

当我看到我的连接到服务器对话框时,我发现差异就像

我的连接到服务器对话框

问题是什么?

此SQL Server在单台计算机上运行,​​而不是在群集或客户端服务器上运行.

sql database sql-server database-design sql-server-2008

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

Java中的等价名称

C#6.0引入了nameof()运算符,它返回一个字符串,表示放在其中的任何类/函数/方法/局部变量/属性标识符的名称.

如果我有这样的课程:

class MyClass
{
    public SomeOtherClass MyProperty { get; set; }

    public void MyMethod()
    {
        var aLocalVariable = 12;
    }
}
Run Code Online (Sandbox Code Playgroud)

我可以像这样使用运算符:

// with class name:
var s = nameof(MyClass); // s == "MyClass"

// with properties:
var s = nameof(MyClass.OneProperty); // s == "OneProperty"

// with methods:
var s = nameof(MyClass.MyMethod); // s == "MyMethod"

// with local variables:
var s = nameof(aLocalVariable); // s == "aLocalVariable".
Run Code Online (Sandbox Code Playgroud)

这很有用,因为在编译时检查了正确的字符串.如果我拼错某些属性/方法/变量的名称,编译器将返回错误.此外,如果我重构,所有字符串都会自动更新.有关实际用例,请参阅此文档.

Java中是否有该运算符的等价物?否则,我怎样才能达到相同的结果(或相似)?

java nameof

24
推荐指数
4
解决办法
6719
查看次数

在Windows 8 RTM上的.NET应用程序中嵌入Powershell v2.0

我在尝试从Windows 7升级之前运行托管的PowerShell脚本时遇到以下错误我从未遇到此错误.

在加载扩展类型数据文件时出现以下错误:Microsoft.PowerShell.Core,C:\ WINDOWS\Syswow64资料\ WindowsPowerShell\V1.0\types.ps1xml(2977):在输入 "System.Security.AccessControl.ObjectSecurity" 错误:异常:getter方法应该是public,non void,static,并且有一个PSObject类型的参数.Microsoft.PowerShell.Core,C:\ Windows\SysWOW64\WindowsPowerShell\v1.0\types.ps1xml(2984):类型"System.Security.AccessControl.ObjectSecurity"出错:异常:getter方法应该是public,非void ,static,并且有一个PSObject类型的参数.Microsoft.PowerShell.Core,C:\ Windows\SysWOW64\WindowsPowerShell\v1.0\types.ps1xml(2991):类型"System.Security.AccessControl.ObjectSecurity"出错:异常:getter方法应该是公共的,非void ,static,并且有一个PSObject类型的参数.Microsoft.PowerShell.Core,C:\ Windows\SysWOW64\WindowsPowerShell\v1.0\types.ps1xml(2998):类型"System.Security.AccessControl.ObjectSecurity"出错:异常:getter方法应该是public,非void ,static,并且有一个PSObject类型的参数.Microsoft.PowerShell.Core,C:\的Windows\Syswow64资料\ WindowsPowerShell\V1.0\types.ps1xml(3005):异常:在类型 "System.Security.AccessControl.ObjectSecurity" 错误该吸气剂的方法应该是公共的,非空隙,static,并且有一个PSObject类型的参数.

我在App.config中应用了以下内容:

<dependentAssembly>
  <assemblyIdentity name="System.Management.Automation" publicKeyToken="31bf3856ad364e35" />
  <publisherPolicy apply="no" />
</dependentAssembly>
Run Code Online (Sandbox Code Playgroud)

问题可能是什么?

.net powershell

23
推荐指数
2
解决办法
6418
查看次数

如何在asp.net-core-2.0中向项目添加'IDesignTimeDbContextFactory <DataContext>'的实现

以下是我安装的软件包列表:已安装的软件包

我正在使用Entityframework核心2.0.我第一次使用实体框架代码成功创建了数据库第一次迁移(add-migration和update-database命令).现在,当我更新我的实体并尝试运行迁移时,它会给我以下错误.

无法创建"DataContext"类型的对象.将"IDesignTimeDbContextFactory"的实现添加到项目中,或者参阅https://go.microsoft.com/fwlink/?linkid=851728以获取在设计时支持的其他模式.

这是我的代码......

Program.cs中

public static void Main(string[] args)
{
    BuildWebHost(args).Run();
}

public static IWebHost BuildWebHost(string[] args) =>
    WebHost.CreateDefaultBuilder(args)
        .UseStartup<Startup>()
        .Build();
Run Code Online (Sandbox Code Playgroud)

Startup.cs

public Startup(IConfiguration configuration)
{
    Configuration = configuration;
}

public IConfiguration Configuration { get; }

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
    // Repositories

    services.AddMvc();
    services.AddDbContextPool<DataContext>(
        options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
        //options => options.UseSqlServer(@"Server=LAPTOP-518D8067;Database=Gyanstack;Trusted_Connection=True;MultipleActiveResultSets=true"));

    services.AddCors();
    services.AddScoped<ISectionRepository, SectionRepository>();
    services.AddScoped(typeof(IEntityBaseRepository<>), typeof(EntityBaseRepository<>));
}
Run Code Online (Sandbox Code Playgroud)

DataContext.cs

public …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework-core asp.net-core-2.0

22
推荐指数
2
解决办法
3万
查看次数

如何更改字体打开xml

如何通过OpenXml更改文档的字体系列?我尝试了一些方法但是,当我打开文档时,它总是在Calibri中

按照我的代码,我尝试了.

我认为Header Builder无用于发布

private static void BuildDocument(string fileName, List<string> lista, string tipo)
{                
    using (var w = WordprocessingDocument.Create(fileName, WordprocessingDocumentType.Document))
    {
        var mp = w.AddMainDocumentPart();
        var d = new DocumentFormat.OpenXml.Wordprocessing.Document();
        var b = new Body();
        var p = new DocumentFormat.OpenXml.Wordprocessing.Paragraph();
        var r = new Run();

        // Get and format the text.                                    
        for (int i = 0; i < lista.Count; i++)
        {
            Text t = new Text();                    
            t.Text = lista[i];
            if (t.Text == "          ")
            {
                r.Append(new CarriageReturn());
            }
            else
            { …
Run Code Online (Sandbox Code Playgroud)

c# openxml openxml-sdk

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

Android:如果从Recent Task启动应用程序,则Activity正在使用旧意图

我正在实施GCM.我的应用程序有两个活动,比如说AB.我正在使用此代码B从NotificationBar 启动:

long when = System.currentTimeMillis();
NotificationManager notificationManager =
    (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
String title = context.getString(R.string.app_name);        
Notification notification = new Notification(R.drawable.app_notification_icon, "De Centrale", when);//message
Intent notificationIntent = new Intent(context, B.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); //|Intent.FLAG_ACTIVITY_REORDER_TO_FRONT
PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);
notification.setLatestEventInfo(context, title, msg, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, notification);
Run Code Online (Sandbox Code Playgroud)

NotificationBar打开活动B,意图,说"B-通知意向",然后我打开活动AB使用后退按钮,然后重新启动我BA有一个新的intent(说"BA-意图").我使用下面的代码:

intent = new Intent(this, B.class); 
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);              
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)

然后我获得新数据B(即B刷新的屏幕).但是,如果我按下主页按钮,然后我从最近的应用程序启动应用程序,那么我会 …

notifications flags android android-intent

21
推荐指数
1
解决办法
3266
查看次数

错误:formControlName必须与父formGroup指令一起使用.您需要添加一个formGroup指令 - Angular反应形式

我有以下模板.我正试图掌握反应形式,但我遇到了问题.

<form [formGroup]="guestForm" novalidate>
    <div class="panel-body">
        <form>
            <div class="col-md-12 col-sm-12">
                <div class="form-group col-md-3 col-sm-6">
                    <label>First Name*  </label>
                    <input formControlName="firstname" type="text" class="form-control input-sm">
                </div>
            </div>
        </form>
    </div>
</form>
Run Code Online (Sandbox Code Playgroud)

然后在我的组件中我有:

@Component({
    selector: 'guest-input',
    templateUrl: './guest-input.component.html',
})
export class GuestInputComponent implements OnInit {
    @Input()
    guest: Guest;

    guestForm: FormGroup;

    constructor(private _fb: FormBuilder) { }

    ngOnInit() {
        this.guestForm = this._fb.group({
            firstname: ['test', [Validators.required, Validators.minLength(3)]]
        });
    }
Run Code Online (Sandbox Code Playgroud)

这一切对我来说都很好,但由于某种原因,我得到:

错误:未捕获(在承诺中):错误:formControlName必须与父formGroup指令一起使用.您将要添加formGroup指令并将其传递给现有的FormGroup实例(您可以在类中创建一个).

我以为我已经在我的身上宣布了这一点<form>.

angular2-forms angular

21
推荐指数
2
解决办法
3万
查看次数

C# - 将WPF Image.source转换为System.Drawing.Bitmap

我发现的人转换的负载BitmapSourceBitmap约,但什么ImageSourceBitmap?我正在制作一个成像程序,我需要从Image元素中显示的图像中提取位图.有谁知道如何做到这一点?

编辑1:

这是用于转换功能BitmapImageBitmap.请记住在编译器首选项中设置"unsafe"选项.

public static System.Drawing.Bitmap BitmapSourceToBitmap(BitmapSource srs)
{
    System.Drawing.Bitmap btm = null;

    int width = srs.PixelWidth;

    int height = srs.PixelHeight;

    int stride = width * ((srs.Format.BitsPerPixel + 7) / 8);

    byte[] bits = new byte[height * stride];

    srs.CopyPixels(bits, stride, 0);

    unsafe
    {
        fixed (byte* pB = bits)
        {
            IntPtr ptr = new IntPtr(pB);

            btm = new System.Drawing.Bitmap(width, height, stride, System.Drawing.Imaging.PixelFormat.Format1bppIndexed, ptr);
        }
    }
    return btm; …
Run Code Online (Sandbox Code Playgroud)

c# image bitmap image-processing

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