小编Roh*_*est的帖子

如何将有向无环图(DAG)转换为树

我一直在寻找将DAG转换为树的C#示例.

有没有人有正确方向的例子或指针?

澄清更新

我有一个图表,其中包含我的应用程序需要加载的模块列表.每个模块都有一个依赖的模块列表.例如,这是我的模块,A,BC,D和E.

  • A没有依赖关系
  • B取决于A,C和E.
  • C取决于A.
  • D取决于A
  • E取决于C和A.

我想要解决依赖关系并生成一个看起来像这样的树...

- 一个

- + - B

----- + - Ç

--------- + - d

- + - 电子

拓扑排序

感谢您的信息,如果我执行拓扑排序并反转输出,我将按以下顺序

  • 一个
  • C
  • d
  • Ë

我想维护层次结构,以便将我的模块加载到正确的上下文中,例如......模块E应该与B在同一个容器中

谢谢

罗汉

c# tree directed-acyclic-graphs data-structures

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

MakeCert - 是否可以更改密钥大小?

当我使用MakeCert.exe生成证书时,我想将密钥大小从1024更改为2048.

这可能吗?或者我是否需要设置证书颁发机构(CA)?

size key certificate makecert

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

创建表达式以使用out参数调用方法

我试图创建一个调用内部方法的表达式,内部方法有一个out参数,这可能吗?

public class Program
{
    static void Main(string[] args)
    {
        var type = typeof (Program);
        var methodInfo = type.GetMethod("ValidateActiveControl", BindingFlags.Instance | BindingFlags.NonPublic);

        var p1 = Expression.Parameter(type, "program");
        var p2 = Expression.Parameter(typeof (bool), "validatedControlAllowsFocusChange");

        var invokeExpression = Expression.Call(p1, methodInfo, p2);
        var func = (Func<Program,bool, bool>)Expression.Lambda(invokeExpression, p1, p2).Compile();

        var validatedControlAllowsFocusChange = true;
        // I would expect validatedControlAllowsFocusChange to be false after execution...
        Console.WriteLine(func.Invoke(new Program(), validatedControlAllowsFocusChange));
        Console.WriteLine(validatedControlAllowsFocusChange);

    }

    internal bool ValidateActiveControl(out bool validatedControlAllowsFocusChange)
    {
        validatedControlAllowsFocusChange = false;

        // Some code here...

        return true; …
Run Code Online (Sandbox Code Playgroud)

c# expression

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

404.13自定义错误的IIS配置

我有一个简单的ASP.NET MVC 3网站在IIS 7.0中托管,并且很难显示404.13 http状态代码的自定义http错误页面.

我的Web.Config中有以下配置

<system.web>
    <httpRuntime maxRequestLength="2048"/>
    <customErrors mode="Off"/> 
</system.web>

<system.webServer>
    <httpErrors errorMode="Custom" existingResponse="Replace">
        <clear/>
        <error statusCode="404" subStatusCode="-1" path="/home/showerror" responseMode="ExecuteURL"  />
        <error statusCode="404" subStatusCode="13" path="/home/showerror" responseMode="ExecuteURL"  />
    </httpErrors>
    <security>
        <requestFiltering>
            <requestLimits maxAllowedContentLength="1048576"/>
        </requestFiltering>
    </security>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)

当我导航到不存在的页面时,我的错误页面会正确呈现.但是,如果我上传的文件大于1MB,我会收到一个空的404响应.网址永远不会被执行.如果我将responseMode更改为Redirect,则会正确重定向用户.

iis-7 asp.net-mvc-3

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

使用每种类型继承的表时返回实体类型

假设我有以下实体

public abstract class Animal
{
    public int Id {get;set;}
}

public class Cat : Animal
{
}

public class Dog : Animal
{
}
Run Code Online (Sandbox Code Playgroud)

是否可以在不创建实例的情况下确定实体的类型.

var id = 1;
var type = context.Animals.GetTypeOfAnimal(id)

public static Type GetTypeOfAnimal(this ObjectSet<Animal> source, int id)  
{
    // What shall I do here, I dont want to fetch the instance at this point...
    var animal = source.First(a => a.Id == id);
    return animal.GetType();
}
Run Code Online (Sandbox Code Playgroud)

我考虑使用以下方法的一个解决方案......

public static Type GetTypeOfAnimal(this ObjectSet<Animal> source, int id)  
{ …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework-4

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

数据绑定时执行字符串转换的通用结构

不久之前,我正在阅读一篇关于创建的一系列类的文章,这些类处理了字符串转换为泛型类型.下面是一个模拟类结构.基本上,如果设置StringValue,它将执行一些转换为类型T.

public class MyClass<T>
{
    public string StringValue {get;set;}
    public T Value {get;set;}
}
Run Code Online (Sandbox Code Playgroud)

我记不起我正在阅读的文章,或者我正在阅读的课程名称.这已经在框架中实现了吗?或者我应该创建自己的?

c# generics

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

什么控制.NET中的CurrencyPositivePattern

跑步时

var x = 10.0M;

Console.WriteLine(typeof(Program).Assembly.ImageRuntimeVersion);

var culture = System.Globalization.CultureInfo.GetCultureInfo("da-DK");

Console.WriteLine(culture.NumberFormat.CurrencyPositivePattern);
Console.WriteLine(x.ToString("C", culture));
Run Code Online (Sandbox Code Playgroud)

我们看到使用不同框架版本时的差异.

v2.0.5072
2
kr 10,00
Run Code Online (Sandbox Code Playgroud)

VS

v4.0.30319
3
10,00 kr.
Run Code Online (Sandbox Code Playgroud)

另外,为什么我会在机器之间看到不同的NumberFormat.CurrencyPositivePattern.它是特定于框架还是与操作系统相关?

40,00 kr.vs kr.20,00

.net c# locale

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

如何检查装配是否已更改

是否可以判断装配是否已更改?

我有一个标准项目,生成一个名为MyAssembly.dll的程序集。

在一个单独的项目中,我读取了程序集并生成了哈希。

当我为程序集生成哈希值时,每次重新编译时都会不同。我已将程序集版本设置为静态,是否需要更改其他任何属性?

class Program
{
    static void Main(string[] args)
    {
        var array = File.ReadAllBytes(@"MyAssembly.dll");
        SHA256Managed algo = new SHA256Managed();
        var hash = algo.ComputeHash(array);

        Console.WriteLine(Convert.ToBase64String(hash));
    }
}
Run Code Online (Sandbox Code Playgroud)

谢谢

罗汉

.net c#

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

结构大小,检查是64位还是32位

我有一个Windows应用程序执行一个简单的例程来确定是否存在USB令牌.该方法始终在32位计算机上正常工作,但在64位计算机上进行测试时,我们开始看到意外结果.

我打电话给以下方法

[StructLayout(LayoutKind.Sequential)]
internal struct SP_DEVINFO_DATA
{
    public Int32 cbSize;
    public Guid ClassGuid;
    public Int32 DevInst;
    public UIntPtr Reserved;
};

[DllImport("setupapi.dll")] 
internal static extern Int32 SetupDiEnumDeviceInfo(IntPtr DeviceInfoSet, Int32 MemberIndex, ref  SP_DEVINFO_DATA DeviceInterfaceData);
Run Code Online (Sandbox Code Playgroud)

SP_DEVINFO_DATA结构的文档告诉我们cbSizeSP_DEVINFO_DATA结构的大小(以字节为单位).

如果我们计算32位机器的cbSize,那么对于64位机器,它将是28和32.

我已经通过使用不同的cbSize值重新编译在两台机器上测试了这个,我想知道的是我如何计算它作为运行时?我的应用程序需要在两种架构上运行.

internal static Int32 GetDeviceInfoData(Int32 iMemberIndex)
{
    _deviceInfoData = new Win32DeviceMgmt.SP_DEVINFO_DATA
    {
        cbSize = ?? // 28 When 32-Bit, 32 When 64-Bit,
        ClassGuid = Guid.Empty,
        DevInst = 0,
        Reserved = UIntPtr.Zero
    };

    return Win32DeviceMgmt.SetupDiEnumDeviceInfo(_deviceInfoSet, iMemberIndex, ref _deviceInfoData);
}
Run Code Online (Sandbox Code Playgroud)

谢谢

罗汉

c#

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

ASP.NET Ajax

我有一个自定义控件,具有以下原型.

Type.registerNamespace('Demo');

Demo.CustomTextBox = function(element) {
    Demo.CustomTextBox.initializeBase(this, [element]);
}

Demo.CustomTextBox.prototype = {

    initialize: function() {
    Demo.CustomTextBox.callBaseMethod(this, 'initialize');

        this._onblurHandler = Function.createDelegate(this, this._onBlur);

        $addHandlers(this.get_element(),
                     {
                         'blur': this._onBlur
                     },
                     this);
    },

    dispose: function() {
        $clearHandlers(this.get_element());

        Demo.CustomTextBox.callBaseMethod(this, 'dispose');
    },

    _onBlur: function(e) {
        if (this.get_element() && !this.get_element().disabled) {
            alert(this.get_element().value);
        }
    }
}

Demo.CustomTextBox.registerClass('Demo.CustomTextBox', Sys.UI.Control);

if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
Run Code Online (Sandbox Code Playgroud)

如何在_onBlur方法中将回发事件提升到服务器?

干杯

罗汉

javascript asp.net-ajax

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

使用Reflection.Emit的奇怪参数序列

我最近一直在关注Reflection.Emit.我写了一个简单的程序,它生成一个DynamicMethod,它简单地调用另一个具有相同参数的方法

class Program
{
    static void Main(string[] args)
    {
        Program p = new Program();
        p.Test();
    }

    public delegate void TestHandler(int a, int b, int c, int d, int e, int f);

    public void Test()
    {
        DynamicMethod method = new DynamicMethod(string.Empty, typeof(void), new[] { typeof(Int32), typeof(Int32), typeof(Int32), typeof(Int32), typeof(Int32), typeof(Int32) }, typeof(Program));


        MethodInfo method1 = typeof(Program).GetMethod("Question",BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic,null,new Type[]{typeof(Int32),typeof(Int32),typeof(Int32),typeof(Int32),typeof(Int32),typeof(Int32)},null);
        MethodInfo method2 = typeof(MethodBase).GetMethod("GetCurrentMethod", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[] { }, null);
        MethodInfo method3 = typeof(Console).GetMethod("WriteLine", BindingFlags.Static …
Run Code Online (Sandbox Code Playgroud)

c# reflection reflection.emit dynamicmethod

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

使用'this'作为通用参数,转换问题

这可能吗?当我编译时,我得到一个错误,即使用约束也无法将Component转换为TComponent

public interface IComponent<TKey, TComponent> where TComponent : IComponent<TKey, TComponent>
{
    TComponent Parent { get; }
    void Register(TKey key, TComponent component);
    void RegsiterWith(TKey key, TComponent component);
}

public class Component<TKey, TComponent> : IComponent<TKey, TComponent> where TComponent : IComponent<TKey, TComponent>
{
    private TComponent _parent;

    public void Register(TKey key, TComponent component)
    {
        component.RegsiterWith(key, this);
    }

    public void RegsiterWith(TKey key, TComponent component)
    {
        component.Register(key, this);
    }

    public TComponent Parent { get { return _parent; } }
}
Run Code Online (Sandbox Code Playgroud)

c# generics

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