c#-3.0

Custom Linq Ordering

让人想犯罪 __ 提交于 2021-02-06 11:07:29
问题 I have over a thousand folders, each folder contains one or more files with the following names: Unordered: Alison.ext Heather.ext Molly.ext Paula.ext Sam.ext Ordered: Molly.ext Sam.ext Heather.ext Alison.ext Paula.ext I would like to write an expression to sort this list as described above. 回答1: //Creating a dictionary with the custom order var order = "MSHAP"; var orderDict = order.Select((c,i)=>new {Letter=c, Order=i}) .ToDictionary(o => o.Letter, o => o.Order); var list = new List<string>

Custom Linq Ordering

删除回忆录丶 提交于 2021-02-06 11:06:01
问题 I have over a thousand folders, each folder contains one or more files with the following names: Unordered: Alison.ext Heather.ext Molly.ext Paula.ext Sam.ext Ordered: Molly.ext Sam.ext Heather.ext Alison.ext Paula.ext I would like to write an expression to sort this list as described above. 回答1: //Creating a dictionary with the custom order var order = "MSHAP"; var orderDict = order.Select((c,i)=>new {Letter=c, Order=i}) .ToDictionary(o => o.Letter, o => o.Order); var list = new List<string>

IClientMessageInspector BeforeSendRequest method is not working when setting header using OperationContextScope

时光怂恿深爱的人放手 提交于 2021-01-28 18:45:55
问题 I have a client code implementation to consume a service with IEndpointBehavior to track request and response data. everything was working fine till I implement bearer token using OperationContextScope. var httpRequestProperty = new HttpRequestMessageProperty(); httpRequestProperty.Headers[System.Net.HttpRequestHeader.Authorization] = "Bearer " + accessToken; var context = new OperationContext(client.InnerChannel); context.OutgoingMessageProperties[HttpRequestMessageProperty.Name] =

Unable to cast object of type 'System.Net.FileWebRequest' to type 'System.Net.HttpWebRequest'

荒凉一梦 提交于 2021-01-28 05:05:57
问题 I'm getting the above error when trying to test on upload to FTP. But when I'm trying run this code from my local machine, it is giving error. Kindly advise. Here my code below : static void Main(string[] args) { var yourListOfFilePaths = Directory.GetFiles(filepath); using (ZipFile zip = new ZipFile()) { foreach (string filePath in yourListOfFilePaths) { zip.AddFile(filePath); // FILE PATH LOCATION / WHICH FOLDER FILES YOU WANTED TO ZIP zip.Password = "abc1234"; // CHANGE YOUR PASSWORD HERE

When does a mock object enter the replay state?

家住魔仙堡 提交于 2021-01-27 01:40:32
问题 When executing the second line of this code Rhino Mocks throws an InvalidOperationException with a message "This action is invalid when the mock object is in replay state" var mockScanner = MockRepository.GenerateMock<PortScanner>(null); mockScanner.Expect((scanner => { scanner.Scan(null, null); })); Stepping through the code in a debugger one can see the debugger run the method defined in the class and directly after control leaves this method the exception occurs. This similar code in

When does a mock object enter the replay state?

偶尔善良 提交于 2021-01-27 01:40:08
问题 When executing the second line of this code Rhino Mocks throws an InvalidOperationException with a message "This action is invalid when the mock object is in replay state" var mockScanner = MockRepository.GenerateMock<PortScanner>(null); mockScanner.Expect((scanner => { scanner.Scan(null, null); })); Stepping through the code in a debugger one can see the debugger run the method defined in the class and directly after control leaves this method the exception occurs. This similar code in

Extension Method for a Collection of Derived Types with Base Type in Method Signature

旧城冷巷雨未停 提交于 2021-01-21 09:30:05
问题 I want to write an extension method for a collection of objects that uses base class as a type requirement. I understand this is not necessarily the best way to do things, but I am curious because I'm interested in learning the nuances of the language. This example explains what I would like to do. public class Human { public bool IsHappy { get; set; } } public class Man : Human { public bool IsSurly { get; set; } } public class Woman : Human { public bool IsAgreeable { get; set; } } public

How to Join In LiteDb

不羁的心 提交于 2020-07-22 09:33:24
问题 How can i join between two table in LiteDb Like SQL Example : I Have Two table User and ActivityLog Here is the Model public class ActivityLog { [BsonId] public int Id { get; set; } public string UserId { get; set; } public string Action { get; set; } public DateTime ActionDateTime { get; set; } } public class User { [BsonId] public int Id { get; set; } public string UserId { get; set; } public string UserName { get; set; } public DateTime LoginDate { get; set; } } I need to join Activity

How to host my ASP.NET core site on IIS (in development environment, without deploy / publish)

有些话、适合烂在心里 提交于 2020-05-26 02:44:07
问题 I used to host my ASP.NET sites (not core) on IIS locally, in my development environment. Doing it helped me avoiding from using IIS Express (It's very uncomfortable to start & stop IIS express every time). In this way all I had to do is to rebuild and refresh the site. My goal is to work with ASP.NET core in the same way. I read this: https://docs.microsoft.com/en-us/aspnet/core/publishing/iis?tabs=aspnetcore2x and it didn't go well. What I'm looking for is to do it without deploy / publish

MS Bot Framework pass the values from server code (C# ) to front end code (JavaScript)

元气小坏坏 提交于 2020-03-25 16:02:13
问题 I've been using MS bot framework - Chat bot in my project and I'm using QnAMaker in the back end for my chat bot, which is running in direct line bot channel. On page load using JavaScript front end code, i'm sending some values say ABC to the bot (c# code - server hosted) via createStore method, after asking the question the bot will start querying it in the qnamaker using ABC as strict filters. After sometime, In one some scenario, i will give input to BOT and change the values as XYZ . up