小编Ste*_*ork的帖子

C#转换继承的通用接口

我遇到了一些麻烦,让我开始构建一个我想出的界面.这是C#Windows Forms的MVP设计.我有一个IView类,我在我的表单类上实现.还有一个IPresenter,我将其导入各种特定的演示者.每个Presenter将根据角色以不同方式管理IView,例如打开对话框以使用AddPresenter输入新数据集,而不是使用EditPresenter编辑现有数据,EditPresenter会将数据预加载到表单上.其中每个都继承自IPresenter.我想使用这样的代码:

AddPresenter<ConcreteView> pres = new AddPresenter<ConcreteView>();
Run Code Online (Sandbox Code Playgroud)

我基本上有这个工作,但这些演示者和他们管理的视图被捆绑到运行时加载的插件,这意味着我需要一个作为插件接口的Manager类采用"模式"参数.此模式参数用于工厂方法以创建"添加"或"编辑演示者",但由于稍后会调用显示对话框,因此我需要通过IPresenter接口进行调用,如下所示:

private IPresenter<IView> pres;
public ShowTheForm()
{
    pres.ShowDialog();
}
Run Code Online (Sandbox Code Playgroud)

现在我遇到的问题是将AddPresenter的具体实例表示为'pres'成员.这是我所拥有的简化版本:

interface IView
{
    void ViewBlah();
}

interface IPresenter<V> where V : IView
{
    void PresBlah();
}

class CView : IView
{
    public void ViewBlah()
    {        
    }
}

class CPresenter<T> : IPresenter<T> where T : IView
{
    public void PresBlah()
    {
    }
}

private void button3_Click(object sender, EventArgs e)
{
    CPresenter<CView> cpres = new CPresenter<CView>();
    IPresenter<IView> ipres = (IPresenter<IView>)cpres;
}
Run Code Online (Sandbox Code Playgroud)

这是错误:

Unable to cast …
Run Code Online (Sandbox Code Playgroud)

c# generics casting interface covariance

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

在Sharepoint 2010事件接收器中重定向

我正在查看一些代码,它破坏了SP2010中List项目更改的保存.在事件接收器的构造函数中,HttpContext被存储为局部变量,然后在ItemUpdating中,最后检索包含返回URL的查询参数并传递SPUtility.Redirect(...).这具有取消在编辑表单中进行的任何更改的效果.因此,按照这样的情况,我发现在线我将HttpContext存储为静态类对象,并在ItemUpdated事件中重定向,现在编辑持续存在,然后重定向到我们期望的位置.

我有一个问题,即将特定用户的HttpContext作为静态存储在一个类上,如果另一个用户在最初和重定向之前设置上下文的时间之间执行相同的操作,则可能会被劫持.用户2将覆盖上下文并存在潜在问题.

我可以想到的唯一另一个选择是快速输出将存储一个静态字典,其中键是用户ID,然后在重定向之前删除该条目,以便不会留下杂散的HttpContext实例泄漏.

因此,从这里查看已接受的解决方案,servy42的第一个响应是,The fact that it works for a few trivial test cases at first doesn't make it a viable solution.但没有提出可行的解决方案.

还有另一个选项best approach may be changing Save Button in ribbon such that when clicked, a ECMA script first save your Item, then redirect to other page, or open other page in dialog.建议进一步向下,但这是唯一的另一种方式吗?

我对SP很新,只​​是试图用我有限的知识来处理大量错误的做事方式,而不幸的是被SP2010困住了.

有关如何去做的任何想法?

============

编辑:根据要求提供更多信息

所以有两个站点,一个称为A,它将有一个名为B的子站点.A有一个List并向该列表添加一个项目触发事件接收器,它创建子站点B和其他相关的东西.如果我从Bs的SharePoint列表中修改B"项目",那么我不需要重定向并返回列表就可以了.如果我正在寻找并在A上整齐地呈现甘特图列出B,如果我在点击保存后编辑B我们需要回到A.如果我在B上还有一个编辑按钮,所以我想回到B编辑完成后单击保存.

因此,当我们进入编辑屏幕时,我们将附加source =.从一些阅读我已经完成它似乎SharePoint将选择并重定向.编辑页面上的一个字段是A站点下面的相对URL,如果更改,则重定向URL将不再有效并抛出404,因此我们用新输入的值替换旧的B子路径.但是我们需要将代码重定向到新位置.

sharepoint redirect sharepoint-2010

7
推荐指数
1
解决办法
185
查看次数

如何将 AutoFac 与 .NET MAUI 结合使用

几年前,我创建了一套用于 CQRS 的 nuget 包,它使用 AutoFac 模块来连接内部结构。我想在我的 .NET MAUI 开发中使用它,因此我已将它们更新到 .NET 6.0,并且它们很好地链接到我的 MAUI 项目,但我不确定我的注册中缺少什么。我的框架的 AutoFac 模块注册了一个 IDateTimeService,但是当我将其添加到注册类的构造函数中时,它无法解析。

因此,按照 .NET Core 的 AutoFac 指南,我添加了 Populate 调用,然后加载 AutoFac 模块。

using Autofac;
using Autofac.Extensions.DependencyInjection;
using Pages;
using Perigee.Framework.Services;
using Services;
using ViewModels;


public static class MauiProgram
{
    public static MauiApp CreateMauiApp()
    {
        var builder = MauiApp.CreateBuilder();
        builder
            .UseMauiApp<App>()
            .ConfigureFonts(fonts =>
            {
                fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
                fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
            });
        
        builder.Services.AddSingleton<IAppNavigationService, AppNavigationService>();
        
        builder.Services.AddSingleton<AppShellViewModel>();
        builder.Services.AddTransient<MainPageViewModel>();

        builder.Services.AddSingleton<AppShell>();
        builder.Services.AddSingleton<MainPage>();
        

        // Hook in AutoFac for the PerigeeFramework services
        var autofacBuilder = …
Run Code Online (Sandbox Code Playgroud)

autofac autofac-module .net-6.0 .net-maui

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

.NET Maui 无法在 iOS 上运行应用程序

所以我有一个简单的应用程序,可以在 Android 模拟器和物理 Opel 手机上运行,​​但是当我部署到 iPhone 时,我遇到了一堆错误。对于初学者...

Could not resolve assembly Microsoft.VisualStudio.DesignTools.TapContract
Run Code Online (Sandbox Code Playgroud)

轻击手势肯定应该开箱即用吗?

这是完整列表:

2022-08-22 23:14:34.473 Xamarin.PreBuilt.iOS[94921:6409975] Could not resolve assembly Microsoft.VisualStudio.DesignTools.TapContract, Version=17.0.0.0, Culture=neutral, PublicKeyToken=null. Details: Could not load file or assembly '/var/mobile/Containers/Data/Application/6B3B6CF6-2A5A-452F-956D-74D8A66941EA/Documents/Lofty.Logbook.content/Microsoft.VisualStudio.DesignTools.TapContract.dll' or one of its dependencies.

2022-08-22 23:14:34.475 Xamarin.PreBuilt.iOS[94921:6409975] Could not resolve assembly Xamarin.HotReload.Contracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null. Details: Could not load file or assembly '/var/mobile/Containers/Data/Application/6B3B6CF6-2A5A-452F-956D-74D8A66941EA/Documents/Lofty.Logbook.content/Xamarin.HotReload.Contracts.dll' or one of its dependencies.

Resolved pending breakpoint for 'Xamarin.HotReload.HotReloadAgent.BreakpointSendToIde(System.String)' to D:\a\_work\1\s\HotReload\Source\Xamarin.HotReload.Agent\HotReloadAgent.cs:419 [0x00000].
2022-08-22 23:14:34.617 Xamarin.PreBuilt.iOS[94921:6409975] Could not resolve assembly Xamarin.HotReload.Contracts, Version=1.0.0.0, Culture=neutral, …
Run Code Online (Sandbox Code Playgroud)

ios .net-maui

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

IEnumerable.ToList()的影响

我只是想知道发生的事情打电话时在.ToList()IEnumerable在C#.这些项目是否实际上被复制到堆上的全新重复项目,或者新列表是否只是引用堆上的原始项目?

我想知道因为有人告诉我调用ToList是昂贵的,而如果只是将现有对象分配给新列表,那就是轻量级调用.

我写过这个小提琴https://dotnetfiddle.net/s7xIc2 只是检查哈希码足以知道吗?

c#

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

DbGeography替代C#POCO

我正在编写一个应用程序,我需要查询某个位置半径内的记录.我开始在我的PCO上只有一对纬度/长的属性,但意识到SQL中的空间搜索是针对列类型的地理位置完成的,这种搜索在POCO中转换为DbGeography(在另一个SO帖子中引用,也使用EF Powertools Reverse工程师POCO).

所以,我看到的问题是我尽可能地保持我的POCOS干净,尽可能地省去所有对实体框架和持久性存储的引用/依赖.我在模型/域组件中有我的POCOS,它永远不应该引用EF.只有我的Repository类和DataStore for DbContext子类和Fluent Configuration项目才知道EF.我还使用流畅的配置远离DataAnnotation属性.一旦你放入DbGeography你需要'使用System.Data.Entity.Spatial'和'EF'打破持久性不可知的方法,至少对于"普通"的旧C#对象.

有了这么多的数据库平台,并且尽可能地使这个系统成为未来的证明,并且在我想切换到另一个持久性存储的事件中重写数据存储代码的最小努力,保持我的域代码尽可能干净是非常重要的.我觉得很奇怪,基于EF流利代码配置引入,使我们不必使用DataAnnotations属性,因此维持System.Data.Entity的出来混的,但有空间,他们打破这种模式.

有谁知道如何处理我正在尝试做的事情?

- 斯科特评论后更新:所以还有一个小问题.我有对System.Data.Entity的引用,我在我的模型上有这个: public System.Data.Spatial.DbGeography GeoLocation {get; 组; }

我在配置类中有这个: this.Property(t => t.GeoLocation).HasColumnName("GeoLocation").HasColumnType("geography");

this.Property得到下划线,我得到这个编译错误: 严重性代码描述项目文件行抑制状态错误CS0453类型'DbGeography'必须是非可空值类型才能在泛型类型中将其用作参数'T'或方法'StructuralTypeConfiguration.Property(Expression>)'FoodRadar.DataStore C:\ Developer\SrcSt\FoodRadar\FoodRadar.DataStore\Configuration\VendorConfiguration.cs 66 Active

我试图另一个反向POCO发生器,其使用T4模板并生成使用System.Data.Entity.Spatial.DbGeography但需要到的EntityFramework参考静止.

我该如何指定映射?

c# entity-framework spatial

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

Angular 4字符串参数

我很难理解为什么我的输入参数变成了数字.我有这个组件:

import { Component, OnInit, Input } from '@angular/core';

@Component({
  selector: 'app-tile',
  templateUrl: './tile.component.html',
  styleUrls: ['./tile.component.css']
})
export class TileComponent implements OnInit {
  @Input() icon1: string;
  @Input() headerText1: string;
  @Input() mainText: string;
  @Input() footerText: string;

  constructor() { }

  ngOnInit() {
  }

}
Run Code Online (Sandbox Code Playgroud)

和模板:

<div class="widget widget-stats bg-green">
  <div *ngIf="icon1" class="stats-icon"><i class="fa {{icon1}}"></i></div>
  <div class="stats-info">
      <h4>Header - {{headerText1}}</h4>
      <p>Icon - {{icon1}}</p>
      <p>Main - {{mainText}}</p>    
      <p>Footer - {{footerText}}</p>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

从另一个组件传递这些:

<app-tile [headerText1]="43543" [mainText]="123456" [footerText]="243542354235" [icon1]="999"></app-tile>
Run Code Online (Sandbox Code Playgroud)

但我想要这个:

<app-tile [headerText1]="TOTAL VISITORS" [mainText]="93%" [footerText]="243542354235" …
Run Code Online (Sandbox Code Playgroud)

typescript angular

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

Xamarin XAML没有约束力

我从XAML数据绑定的正式Xamarin doco以及PluralSight教程中了解了一些示例,该教程说明了在C#代码中定义自定义ViewCell并遇到问题.首先,我宁愿使用XAML,因为它的流动性,但我遇到了重大问题. 这个例子是最新的例子,似乎对我来说很明显,但是如果我在XAML中指定ItemsSource,因为我的数据源永远不会绑定,所以缺少某些东西.这是我的XAML:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:TOFApp"
             x:Class="MyApp.MainPage" 
             Title="MyApp"
             Padding="0,20,0,0">

    <StackLayout>
        <!-- Place new controls here -->
        <ListView x:Name="thingyList"
                  ItemsSource="{Binding ThingyList}"
                  CachingStrategy="RecycleElement"
                  SelectedItem="{Binding SelectedThingy}">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <StackLayout Orientation="Horizontal" Padding="15,5,5,5">
                            <StackLayout.GestureRecognizers>
                                <TapGestureRecognizer Tapped="OnThingyTapped"></TapGestureRecognizer>
                            </StackLayout.GestureRecognizers>                                
                            <Image Source="" HeightRequest="50" WidthRequest="50" />
                                <StackLayout Orientation="Vertical">
                                <Label Text="{Binding Name}" 
                                       VerticalOptions="Center" 
                                       HorizontalOptions="StartAndExpand"
                                       FontSize="Medium" />
                                <Label Text="{Binding Description}" 
                                       VerticalOptions="Center" 
                                       HorizontalOptions="StartAndExpand"
                                       FontSize="Micro"
                                       FontAttributes="Italic" />
                                <Label Text="" 
                                       IsVisible="false" />
                            </StackLayout>
                        </StackLayout>
                    </ViewCell>

                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

    </StackLayout>

</ContentPage>
Run Code Online (Sandbox Code Playgroud)

和背后的代码

public partial class MainPage …
Run Code Online (Sandbox Code Playgroud)

c# xaml xamarin.forms

0
推荐指数
1
解决办法
72
查看次数