小编Adi*_*ter的帖子

模仿Windows用户

我正在使用代码来模拟用户帐户以访问文件共享.

public class Impersonator :
    IDisposable
{
    #region Public methods.
    // ------------------------------------------------------------------

    /// <summary>
    /// Constructor. Starts the impersonation with the given credentials.
    /// Please note that the account that instantiates the Impersonator class
    /// needs to have the 'Act as part of operating system' privilege set.
    /// </summary>
    /// <param name="userName">The name of the user to act as.</param>
    /// <param name="domainName">The domain name of the user to act as.</param>
    /// <param name="password">The password of the user to act as.</param> …
Run Code Online (Sandbox Code Playgroud)

c# windows impersonation

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

Lazy <T>延迟加载错误:字段初始值设定项无法引用非静态字段,方法或属性

我试图第一次使用延迟加载来初始化我的类中的进度对象.但是,我收到以下错误:

字段初始值设定项不能引用非静态字段,方法或属性.

private Lazy<Progress> m_progress = new Lazy<Progress>(() =>
{
    long totalBytes = m_transferManager.TotalSize();
    return new Progress(totalBytes);
});
Run Code Online (Sandbox Code Playgroud)

在.NET 2.0中,我可以执行以下操作,但我更喜欢使用更新的方法:

private Progress m_progress;
private Progress Progress
{
    get
    {
        if (m_progress == null)
        {
            long totalBytes = m_transferManager.TotalSize();
            m_progress = new Progress(totalBytes);
        }
        return m_progress;
    }
}
Run Code Online (Sandbox Code Playgroud)

有人可以帮忙吗?

非常感谢.

.net c# generics lazy-loading

11
推荐指数
1
解决办法
1585
查看次数

UserControl中的INotifyPropertyChanged

我有一个继承自TextBox控件的自定义控件.我想INotifyPropertyChanged在我的自定义控件中实现该接口.

public class CustomTextBox : TextBox, INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;
    protected void NotifyPropertyChanged(string info)
    {
        if (PropertyChanged != null)
            PropertyChanged(this, new PropertyChangedEventArgs(info));
    }
}
Run Code Online (Sandbox Code Playgroud)

我的问题是当我尝试引发PropertyChanged事件时,PropertyChanged事件处理程序始终为null.

有人可以帮帮我吗?

c# silverlight-4.0

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

为什么在打开.xls文件时显示错误消息

在我的asp.net,C#应用程序中,我们正在生成并下载.xls文件.但是当我试图打开时,它正在发出消息

"您尝试打开的文件'filename.xls'的格式与文件扩展名指定的格式不同.在打开文件之前,请验证文件是否已损坏且来自受信任的来源.是否要打开现在的文件?"

如果我按"是"它就会打开.我将文件扩展名更改为.xlsx,仍然是相同的消息.谁能告诉我为什么会这样?我在IIS管理器中添加了.xlsx MIME类型扩展,MIME类型为application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.它仍然显示相同的消息.请建议我如何摆脱它.

c# asp.net xls xlsx internet-explorer-5

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

下拉选择控制 - Windows 8 Metro - XAML

我想要下面的图片中的下拉菜单:

我不知道如何得到它们.我想这些是某种组合框,但我不确定.任何人都可以帮助我并提供xaml代码吗?!谢谢.

windows xaml controls microsoft-metro drop-down-menu

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

怎么施放lambdas?

我希望将一系列函数保存在一个源自某种基类型的字典中(例如,让我们调用基类"对象").那么,有可能将f1保持在f2吗?

Func<bool> f1 = () => true;
Func<object> f2 = f1;
Run Code Online (Sandbox Code Playgroud)

错误1无法将类型隐式转换System.Func<bool>System.Func<object>

这是我们能做的最好的吗?

Func<bool> f1 = () => true;
Func<object> f2 = () => (object)f1;
Run Code Online (Sandbox Code Playgroud)

错误:(无)

我想它需要通用友好是一个where语句...但我不确定你是否可以用lamdas做到这一点.


关注Armen的信息,我挖掘了字符串和bool的定义:

public sealed class String : IComparable, ICloneable, IConvertible, IEnumerable,
                             IComparable<String>, IEnumerabl<char>,
                             IEquatable<String> 

public struct Boolean : IComparable, IConvertible, IComparable<Boolean>,
                        IEquatable<Boolean>
Run Code Online (Sandbox Code Playgroud)

他对ref Vs的价值是正确的.String是否隐式派生自对象?根据@ PeterK的链接看起来这是结构的行为.

"ValueType会覆盖Object中的虚方法,并为值类型提供更合适的实现.另请参阅Enum,它继承自ValueType."

宾语:

System.Object:所有类,结构,枚举和委托.(来自http://msdn.microsoft.com/en-us/library/system.object)

这反过来又Func<bool>无法分配到Func<object>一点点愚蠢.即从这个角度看,继承层次结构是正确的.

.net lambda casting c#-4.0

10
推荐指数
1
解决办法
184
查看次数

WPF XAML网格可见性触发器

我有一个位于网格第一行的状态消息,我希望它在可见性发生变化时滑入和滑出.
第一个可见性触发器运行良好,并快速打开第一个网格行.一旦我添加'Collapsed'触发器,一切都无效.当可见性设置为折叠时,如何将动画反转为滑动关闭?

<Grid Grid.Row="0" Height="55" Visibility="{Binding StatusMessageVisibility, Mode=TwoWay}">
    <Grid.Style>
        <Style TargetType="Grid">
            <Style.Triggers>
                <Trigger Property="Visibility" Value="Visible">
                    <Trigger.EnterActions>
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimation Storyboard.TargetProperty="Height" From="0" To="55" Duration="0:0:.1" />
                            </Storyboard>
                        </BeginStoryboard>
                    </Trigger.EnterActions>
                </Trigger>
                <Trigger Property="Visibility" Value="Collapsed">
                    <Trigger.EnterActions>
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimation Storyboard.TargetProperty="Height" From="55" To="0" Duration="0:0:.1" />
                            </Storyboard>
                        </BeginStoryboard>
                    </Trigger.EnterActions>
                </Trigger>                        
            </Style.Triggers>
        </Style>
    </Grid.Style>
    <TextBlock Text="Hi There" />
</Grid>
Run Code Online (Sandbox Code Playgroud)

wpf animation xaml triggers visibility

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

基于GUI的IoC容器?

是否有一个IoC容器,其中配置是实时的,并通过类似图的gui而不是通过代码或类似xml的配置完成?

我在考虑像Simulink这样的东西,图中的每个框都代表一个C#对象,链接代表依赖注入.

我看到很多非常酷的用例,但我找不到任何甚至远程看起来像这样的东西.

.net c# inversion-of-control

9
推荐指数
0
解决办法
465
查看次数

使用标记扩展进行绑定时出错:解析标记扩展时遇到未知属性

原则上,我开发了一种将RadioButtons绑定到几乎任何东西的简洁方法:

/// <summary>Converts an value to 'true' if it matches the 'To' property.</summary>
/// <example>
/// <RadioButton IsChecked="{Binding VersionString, Converter={local:TrueWhenEqual To='1.0'}}"/>
/// </example>
public class TrueWhenEqual : MarkupExtension, IValueConverter
{
    public override object ProvideValue(IServiceProvider serviceProvider)
    {
        return this;
    }

    public object To { get; set; }

    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return object.Equals(value, To);
    }
    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if ((bool)value) return To;
        throw new NotSupportedException();
    } …
Run Code Online (Sandbox Code Playgroud)

data-binding wpf xaml radio-button

9
推荐指数
2
解决办法
4513
查看次数

缺少GitHub图标

是否有其他人的GitHub缺少图标?没有JS错误,从我resources在Chrome开发人员工具中看到的内容,没有404错误.

icons github

9
推荐指数
2
解决办法
2302
查看次数