小编net*_*x01的帖子

Assembly.ReflectionOnlyLoadFrom不工作

我有一个Library1.dll包含一些接口的程序集,它们被序列化为数据库中的字节数组.出于某些原因,我们必须更改接口属性和定义.所以现在我正在编写一个迁移实用程序.所以我有2个版本Library1.dll,在我的实用程序中,我创建了一个文件夹,我存储了新版本Library1.dll.这个实用程序反过来也引用Library1.dllbin文件夹包含Library1.dll但是这个dll是在旧版本上编译的.我的新版本Library1.dll存储在一个私有路径中,我传递给Assembly.ReflectionOnlyLoadFrom函数实例化,因此GetTypes在加载的程序集上进一步使我能够进行数据转换.

但是ReflectionTypeLoadException当我试图Library1.dll从私人路径加载时我总是得到.

请帮帮忙!!! 任何帮助,将不胜感激.我真的被卡住了.

谢谢,AG

c# reflection remoting

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

F#属性设计

因此,当我在我的F#代码中创建一些属性时,因为F#不支持自动属性,据我所知.我必须创建支持字段并将它们初始化为null,这在函数式编程术语中似乎不正确.例如


 let mutable albums : DbSet = null
 let mutable genres : DbSet = null

member x.Albums with get() = albums and set(value) = albums <- value member x.Genres with get() = genres and set (value) = genres <- value
Run Code Online (Sandbox Code Playgroud)

这样做有更好的方法吗?非常感谢你的建议.

f#

6
推荐指数
3
解决办法
1187
查看次数

Seq toDictionary

如何从Seq构造字典.我似乎无法正确使用语法.

所以我有一个Seq,我想从它构建一个字典,类似于

文献

<Overrides>
  <token key="A" value="1"/>
  <token key="B" value="2"/>
  <token key="C" value="3"/>
  <token key="D" value="4"/>
  <token key="E" value="5"/>
  <token key="F" value="6"/> 





let elem = docs |> Seq.map(fun x -> x.Descendants(XName.op_Implicit "Overrides").Elements(XName.op_Implicit "token"))
            |> Seq.head
            |> Seq.iter(fun (k: XElement , v:XElement) ->  k.Attribute(XName.op_Implicit "key").Value, v.Attribute("value").Value) 
Run Code Online (Sandbox Code Playgroud)

但得到运行时错误

错误1此表达式应具有类型XElement,但此处的类型为"a*"b

f#

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

如何应用Seq map功能?

我最近一直在玩F#.我想知道而不是使用for循环来生成一个元素序列,它与列表中的每个其他元素相乘,我如何使用Seq map函数或类似的东西来生成类似下面的内容.

所以对于例如我有一个列表[1..10]我想应用一个产生类似结果的乐趣

[(1*1); (1*2);(1*3); (1*4); (1*5)......(2*1);(2*2);(2*3).....(3*1);(3*2)...]
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

非常感谢你的帮助.

f# seq

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

F#理解歧视联盟

我之前有点问过这个问题,很抱歉再次提出类似的问题.但不幸的是,我无法真正理解如何设计一个受歧视的工会.

所以我有一堆看起来像的数据结构

type Artist( artistId : int, name : String ) = do if name = null then nullArg String.Empty new(artistId: int) = Artist(artistId) member x.ArtistId = artistId member x.Name = name

and Genre() = let mutable name = String.Empty let mutable genreId : int = 0 let mutable description = String.Empty let mutable albums = List.empty member x.Description with get() = description and set( value ) = description <- value
member x.Albums with get() = albums and set ( …

Run Code Online (Sandbox Code Playgroud)

f#

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

Master Detail MVVM WPF无法正常工作

我无法让我的绑定工作在Detail ListView上.我已粘贴下面的所有MVVM模式代码.请帮忙!!!

我的观点:DirectoryDe​​tailView.cs

<UserControl x:Class="S2.Views.DirectoryDetailView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition/>
        <ColumnDefinition/>
    </Grid.ColumnDefinitions>
    <ListView Grid.Column="0" ItemsSource="{Binding Path = DirectoryDetails}"
              IsSynchronizedWithCurrentItem="True"
              SelectedItem="{Binding SelectedDirName, Mode=TwoWay}">
        <ListView.View>
            <GridView>
                <GridViewColumn DisplayMemberBinding="{Binding Path = FileName}"
                                Header="File Name"/>
            </GridView>
        </ListView.View>
    </ListView>
    <ListView Grid.Column="1" Margin="10,0,0,0" ItemsSource="{Binding Path = DirectoryDetails}">
        <ListView.View>
            <GridView>
                <GridViewColumn DisplayMemberBinding="{Binding Path = FileDetails.Length}"
                                Header="Length"/>
                <GridViewColumn DisplayMemberBinding="{Binding Path = FileDetails.LastAccessTime}"
                                Header="LastAccessTime"/>
            </GridView>
        </ListView.View>
    </ListView>
</Grid>
Run Code Online (Sandbox Code Playgroud)

我的型号:

public class DirectoryModel : INotifyPropertyChanged
{
    private string _fileName;
    private DateTime _createdTime;

    public string FileName
    {
        get
        {
            return _fileName; …
Run Code Online (Sandbox Code Playgroud)

c# data-binding wpf mvvm

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

Linq查询性能,比较编译查询与非编译查询

我想知道如果我将常见的where子句查询提取到一个公共表达式中它会使我的查询更快,如果我在一个集合上说10个linq查询的东西与where子句的完全相同的第一部分.

我做了一个小例子来解释一下.

public class  Person
{
    public string First { get; set; }
    public string Last { get; set; }
    public int Age { get; set; }
    public String Born { get; set; }
    public string Living { get; set; }
}

public sealed class PersonDetails : List<Person>
{
}



PersonDetails d = new PersonDetails();
        d.Add(new Person() {Age = 29, Born = "Timbuk Tu", First = "Joe", Last = "Bloggs", Living = "London"});
        d.Add(new Person() { Age = 29, Born …
Run Code Online (Sandbox Code Playgroud)

c# linq functional-programming

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

F#类重新排序Visual Studio

我正在构建一个示例应用程序,其中我的类型层次结构不适用于Visual Studio中的类型排序.无论我以何种方式安排文件(向上,向下),我都无法定义所有类.

所以他们在f#项目中的顺序

type Artist() =
    let mutable artistId = 0
    let mutable name = String.Empty

    member x.ArtistId 
        with get() = artistId
        and set (value) = artistId <- value

    member x.Name
        with get() = name
        and set ( value ) = name <- value

type Genre() =
    let mutable name = String.Empty
    let mutable genreId = 0
    let mutable description = String.Empty
    let mutable albums = [new Album()]

    member x.Name 
        with get() = name
        and set (value) = name <- …
Run Code Online (Sandbox Code Playgroud)

f#

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

如何使用C#和Linq使c#方法更具功能性

private void DoSomeWork()
{
    ManualResetEvent[] waitEvents = new ManualResetEvent[rowCount];

    int i = 0;

    foreach (DataRow row in StoredProcedureParameters.Tables[0].Rows)
    {
        waitEvents[i] = new ManualResetEvent(false);
        var workerClass = new WorkerClass();

        var collection = new Dictionary<string, object>();
        foreach (DataColumn dataColumn in StoredProcedureParameters.Tables[0].Columns)
        {
            collection[dataColumn.ColumnName] = row[dataColumn.ColumnName];
        }

        workerClass.Parameters = collection;
        workerClass.Event = waitEvents[i];
        i++;

        ThreadPool.QueueUserWorkItem(WorkerFunction, workerClass);
    }
}

private class WorkerClass
    {
        public ManualResetEvent Event;
        public Dictionary<string, object> Parameters;
    }
Run Code Online (Sandbox Code Playgroud)

c# linq

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

如何使用lambda和功能C#范例删除不必要的列表

Hello Functional C#Friends,

所以这次我试图压缩我的代码并编写更多功能,lambda样式,以及我想创建不必要的列表和类,让编译器为我做的工作.我确实设法以功能方式转换了一小段代码,但之后我不知道如何去做.

var errorList = new List<DataRow>();

IEnumerable<DataRow> resultRows = GetResultRows();

resultRows      
     .Filter(row => row.Field<string>("status").Equals("FAILURE", StringComparison.InvariantCultureIgnoreCase))
     .ForEach(row => { errorList.Add(row); });

if (errorList.Count > 0)
{
    var excludedBooks = new List<string>();
    foreach (DataRow row in errorList)
    {
        if (ToUseBooksList.Contains((string)row["main_book"]))
        {
            BookCheckResults.AddRow(string.Format("Error for MainBook {0}, RiskType {1}",
                                                  row["main_book"], row["risk_type"]));
            if (!excludedBooks.Contains((string)row["main_book"]))
            {
                excludedBooks.Add((string)row["main_book"]);
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我的扩展方法:

public static void ForEach<T>(this IEnumerable<T> collection, Action<T> action)
{
    if (collection == null)
        throw new ArgumentNullException("collection");
    if (action == null)
        throw …
Run Code Online (Sandbox Code Playgroud)

c# linq lambda

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

这个lambda表达式有什么问题?

我真的很难理解为什么,当我改变我的代码使用lamdba表达式时,它不起作用.

此代码在控制台上工作和打印:

object dummy = new object();
InterServer.ExecuteDataReader(new InterServerRequest(ServerID.a_01, "dbo.getbooks") 
    { 
        Params = new Dictionary<string, object> { 
            { "Tool", "d1" }, 
            { "Loc", locale == string.Empty ? null : locale } } 
    },
    (_, reader) =>
        {
            reader.AsEnumerable(r => (r.GetString(r.GetOrdinal("book")))).ToList().ForEach(Console.WriteLine);
            return new Response(dummy);
        }
    );
Run Code Online (Sandbox Code Playgroud)

此代码已更改为使用lambda表达式; 它没有打印任何东西,我不明白为什么:

InterServer.ExecuteDataReader(new InterServerRequest(ServerID.a_01, "dbo.getbooks")
    { 
        Params = new Dictionary<string, object> { 
            { "Tool", "d1" }, 
            { "Loc", locale == string.Empty ? null : locale } } 
    },
    (_, reader) =>
        {
            return new Response(new …
Run Code Online (Sandbox Code Playgroud)

c# lambda functional-programming

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

在类中包装Byte []以减少内存开销

我在应用程序中传递了大量数据作为byte []对象.在很多情况下,这也是存储问题.如果我在类中包装byte []怎么样呢?

[Serializable] public class MyClass {public byte [] Data {get; 组; }}

你们是否认为我会获得任何性能becoz现在引用类型将传递而不是值类型,因此数据不必每次都被复制.

期待您的回答

.net c# clr

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

F#替代列表语法

所以我有一个带有属性名称的类型类型.

我正在创建一个类型名称列表,如下所示.

let genres = new Genre()
    [ genres.Name <- "Disco"; 
      genres.Name <- "Jazz"; 
      genres.Name <- "Rock"; ] |>ignore
Run Code Online (Sandbox Code Playgroud)

想知道是否有更多的创造这种创造的方式?

f#

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

标签 统计

c# ×7

f# ×6

linq ×3

functional-programming ×2

lambda ×2

.net ×1

clr ×1

data-binding ×1

mvvm ×1

reflection ×1

remoting ×1

seq ×1

wpf ×1