.net

How to set assembly version, culture and public key token while compiling with Roslyn?

爷,独闯天下 提交于 2021-02-16 19:22:17
问题 I'm using Roslyn to emit a CSharpCompilation object in Visual Studio to a file. The DLL that is generated does not contain any assembly info other than the assembly metadata, and I'd like to add the version and sign it if possible. How can these be done with Roslyn? 回答1: You need to include source code which sets the Assembly* attributes just like in the VS C# project templates. If you have done that, the .NET version info is set. You can read that information with Reflection or tools like

how do I pass an argument to a class that inherits UITypeEditor

只谈情不闲聊 提交于 2021-02-16 18:36:31
问题 I have created an editor for a property. I would however like to pass some arguments to the constructor of the editor, but I am unsure as to how to do this. FOO _foo = new foo(); [Editor(typeof(MyEditor), typeof(UITypeEditor))] public object foo { get { return _foo; } set {_foo = value;} } ~ class MyEditor: UITypeEditor { public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, System.IServiceProvider provider, object value) { //some other code return obj; } }

Unit test serilog configuration

烈酒焚心 提交于 2021-02-16 18:07:57
问题 I have a piece of code for setting up serilog based on some custom configuration combined with hosting environment. E.g. the application writes to one sink in development and another sink in production. I'm trying to figure out how to write tests for this piece of code. Basically, I want to write a test that checks that a sink only is added if the environment name is set to a given value, and that the sink configuration, like log file path, respects the custom configuration that I provide.

Unit test serilog configuration

半腔热情 提交于 2021-02-16 18:06:51
问题 I have a piece of code for setting up serilog based on some custom configuration combined with hosting environment. E.g. the application writes to one sink in development and another sink in production. I'm trying to figure out how to write tests for this piece of code. Basically, I want to write a test that checks that a sink only is added if the environment name is set to a given value, and that the sink configuration, like log file path, respects the custom configuration that I provide.

DateTime does not exist in the current context

被刻印的时光 ゝ 提交于 2021-02-16 16:19:07
问题 I have the following class using System; using System.Globalization; namespace GenericSomething { public class Specific : Generic { public override bool DoSomething(string date) { DateTime newDate = DateTime.ParseExact(date, "yyyyMMdd", CultureInfo.InvariantCulture); if (newDate.Date == DateTime.Now.Date) return true; else return false; } } } When I'm debugging and i use "Add watch" on DateTime.Now.Date, i get "DateTime does not exist in the current context." And the condition is never

how can read values and put them in Array C#

依然范特西╮ 提交于 2021-02-16 15:34:18
问题 I start dicoverig C# today ... as you know there is some difuculties using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { int[] arr = new int[3]; int i; for (i=0; i < 3; i++) { arr[i] = Console.Read(); } for (int k = 0; k < 3; k++) { Console.Write(arr[k]); } Console.ReadKey(); } } } this code didn't work with me when i compiled it ...it make me put value for one time then he

How to handle “End Task” from Task Manager in .NET 5 console app?

故事扮演 提交于 2021-02-16 14:48:07
问题 My .NET 5 console application registers a HandlerRoutine by using SetConsoleCtrlHandler, so it can do some cleanup before exiting. This allows me to react to CTRL+C / CTRL+BREAK , ALT+F4 and the console being closed using the X button. Sadly, the HandlerRoutine doesn't get called when Task Manager tries to terminate the application after clicking End Task in the Process tab, even though the documentation for HandlerRoutine states the following regarding CTRL_CLOSE_EVENT : A signal that the

Execute BATCH script in a programs memory

流过昼夜 提交于 2021-02-16 14:35:34
问题 I am currently faced with a problem, I need to execute a batch script within a programs memory (so it does not have to extract the batch file to a temporary location). I am open to solutions in C# and C++ Any help would be appreciated 回答1: cmd.exe won't run a script from the memory of your process. The options which seem most obvious to me are: Relax the constraint that stops you extracting the script to a temporary file. Compress your script into a single line and use cmd.exe /C to execute

Execute BATCH script in a programs memory

匆匆过客 提交于 2021-02-16 14:35:29
问题 I am currently faced with a problem, I need to execute a batch script within a programs memory (so it does not have to extract the batch file to a temporary location). I am open to solutions in C# and C++ Any help would be appreciated 回答1: cmd.exe won't run a script from the memory of your process. The options which seem most obvious to me are: Relax the constraint that stops you extracting the script to a temporary file. Compress your script into a single line and use cmd.exe /C to execute

Enumerator.MoveNext() throws 'Collection was Modified' on first call

夙愿已清 提交于 2021-02-16 13:34:53
问题 Consider the following code: List<int> list = new List<int>(); IEnumerable<int> enumerable = list; IEnumerator<int> enumerator = enumerable.GetEnumerator(); list.Add(1); bool any = enumerator.MoveNext(); At runtime, the last line throws an: InvalidOperationException: Collection was modified; enumeration operation may not execute. I understand the need for IEnumerators to throw 'Collection was modified' exceptions when the IEnumerable changes, but I don't understand this: Why does the