clr

How to modify the boxed value without creating a new object in C#?

那年仲夏 提交于 2020-05-24 05:05:21
问题 How to modify the boxed value without creating a new object in C#? E.g. if I have object o = 5; and I want to change the value of the boxed 5 to 6 , how can I do that? The o = 6; will create a new object on the heap and assign the reference to that object to the o . Are there any other ways to change the boxed value? 回答1: You can do the "boxing" yourself, than you can modify it. class Box { public int Value { get;set;} } This prevents the automatic boxing. If you define yourself an conversion

How to share an object across app domains in c# if the class is not serializable

混江龙づ霸主 提交于 2020-05-17 08:49:22
问题 For context, this is a follow-up to this question: How can I reload a class in .net To save the trouble of re-reading that post, my "high-level" problem is I want to do this: while(true) { sleep(naptime); reload_code(); // use magic? do_something_useful(); } Where do_something_useful is compiled separately from the code in the while loop, and reload_code would pick up the latest (compiled) version. I was given a link to another answer on this site, which basically said do_something_useful

Where does CLR store methods for instances of one type

牧云@^-^@ 提交于 2020-05-13 14:33:36
问题 class MyClass { public string MyProperty { get; set; } public void MyMethod() { //Do something difficult here //100500 lines of code here ... } } We have a lot of instances of MyClass . Does CLR creates this really memory-expensive MyMethod() for any instance of the class ? 回答1: No it does not. This method will compiled once, when we have the first call of this method. Then the compiled code will be used by any instance of type MyClass . So any performance hit happens only in the first call

Where does CLR store methods for instances of one type

依然范特西╮ 提交于 2020-05-13 14:33:04
问题 class MyClass { public string MyProperty { get; set; } public void MyMethod() { //Do something difficult here //100500 lines of code here ... } } We have a lot of instances of MyClass . Does CLR creates this really memory-expensive MyMethod() for any instance of the class ? 回答1: No it does not. This method will compiled once, when we have the first call of this method. Then the compiled code will be used by any instance of type MyClass . So any performance hit happens only in the first call

Why doesn't the CLR call Dispose automatically

落花浮王杯 提交于 2020-03-26 05:25:08
问题 I'm hoping i know my facts correctly if not please correct me. 1) You use Dispose to clean unmanaged resources, that means no garbage collection for them. 2) Value types are stored on the stack, reference types are stored on the heap and pointers to reference types are stored on the stack(not really sure about this one but i think it's correct) 3) Finilizers are called by the Garbage Collector. 4) Garbage Collection is called by the CLR and not by the user(although the he can) for reference

How is return by reference implemented in C#?

给你一囗甜甜゛ 提交于 2020-03-02 09:14:17
问题 Given that C# GC can move memory around, how could ref-return even be implemented? Would the code below cause 'undefined behaviour'? public struct Record { public int Hash; public VeryLargeStruct Data; } public class SomeClass { private Record[] _records = new Record[16]; public ref VeryLargeStruct GetDataAt(int index) => ref _records[index].Data; } I would assume that if memory associated with _records reference moved that it would invalidate local references such as: ref var data = ref

AppDomain Assembly not found when loaded from byte array

对着背影说爱祢 提交于 2020-02-27 06:42:28
问题 Please bear with me, I spent 30+ hours trying to get this work - but without success. At the start of my program I load an Assembly (dll) in bytearray and delete it afterwards. _myBytes = File.ReadAllBytes(@"D:\Projects\AppDomainTest\plugin.dll"); Later on in the program I create a new Appdomain, load the byte array and enumerate the types. var domain = AppDomain.CreateDomain("plugintest", null, null, null, false); domain.Load(_myBytes); foreach (var ass in domain.GetAssemblies()) { Console

AppDomain Assembly not found when loaded from byte array

旧街凉风 提交于 2020-02-27 06:41:45
问题 Please bear with me, I spent 30+ hours trying to get this work - but without success. At the start of my program I load an Assembly (dll) in bytearray and delete it afterwards. _myBytes = File.ReadAllBytes(@"D:\Projects\AppDomainTest\plugin.dll"); Later on in the program I create a new Appdomain, load the byte array and enumerate the types. var domain = AppDomain.CreateDomain("plugintest", null, null, null, false); domain.Load(_myBytes); foreach (var ass in domain.GetAssemblies()) { Console

Calling C# dll from C++

别说谁变了你拦得住时间么 提交于 2020-02-16 05:22:41
问题 I have a native C++ DLL, and I want to import a C# DLL and use some of its functions (for example connecting to a database). Now I have read that you can turn the DLL into a TLB COM file, and I have done that no problems. My problem lies with the C++. To call that TLB file I need to set CLR support. I use themida to help secure all my DLL's as well as PEC. They do not support .net DLL's and when I enable CLR the programs recognize it as a .net DLL. Is there anyway to call a c# function inside

How do I prevent my SQL statements from SQL injection when using CLR/C++ with multiple variables?

a 夏天 提交于 2020-02-02 13:09:30
问题 I am having a major problem where I do not know how to prevent SQL injection when writing SQL statements in CLR/C++ Below is the code String^ sqlstr = "SELECT * FROM "; sqlstr += tableName + " WHERE " + field + " = " + fieldEntity; I need to be able to input correct SQL Injection preventions to this statement. Background code class database { protected: string fieldEntity; string tableName; string field; ... ____ OleDbDataReader^ openData(String^ fieldEntity, String^ field, String^ tableName)