clr

C# Generics: Constraining T where T : Object doesn't compile; Error: Constraint cannot be special class 'object'

情到浓时终转凉″ 提交于 2019-12-22 01:26:55
问题 When I constrain T with : Object like this: public interface IDoWork<T> where T : Object { T DoWork(); } I get the error: Constraint cannot be special class 'object' Does that mean there is an implied difference with the following that does compile? public interface IDoWork<T> // where T : Object { T DoWork(); } 回答1: There is no difference between the two constraints, except for that one is disallowed for being useless to explicitly state. The C# 4.0 language specification (10.1.5 Type

What are the implications of using unsafe code

独自空忆成欢 提交于 2019-12-22 01:24:24
问题 Aside from the fact that the code itself can access memory directly. What are the other implications of using the "/unsafe" compiler flag and the "fixed" keyword? Are there any knock on effects related to code signing and deployment of my .exe (my app is desktop only)? (This isn't about whether or not I should be doing this, the why is covered in my question here) 回答1: Unsafe code is not verifiable, so you have to be aware of that. In a Full Trust environment, that's not a big deal, but if

Proper Measurement of Characters in Pixels

帅比萌擦擦* 提交于 2019-12-22 01:09:05
问题 I'm writing a text box from scratch in order to optimize it for syntax highlighting. However, I need to get the width of characters in pixels, exactly, not the garbage Graphics::MeasureString gives me. I've found a lot of stuff on the web, specifially this, however, none of it seems to work, or does not account for tabs. I need the fastest way to measure the exact dimensions of a character in pixels, and tab spaces. I can't seem to figure this one out... Should mention I'm using C++, CLR/CLI,

Oracle Data Provider to CLR type mapping

故事扮演 提交于 2019-12-21 20:10:15
问题 Where can I find the listing of ODP to CLR type mapping? On Oracle database, the NUMBER(9,0) type comes out in .NET app as System.Decimal from the MS Oracle driver, but as System.Int32 from ODP driver. I need an exact specification of types coming out from database (not the CLR to DB parameter mapping). 回答1: Run this simple test to get mappings for SqlServer and Oracle (both MS and ODP.NET drivers): using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient

Does a value type keep Type pointer + Sync root + Static fields like a reference type?

非 Y 不嫁゛ 提交于 2019-12-21 19:56:52
问题 Does a value type keep Type pointer + Sync root + Static fields like a reference type? This question is an extended version of the following one: do-value-types-have-type-objects. Can anyone clarify: Do value types have a related System.Type-object stored in CLR heap? Where value type static fields and methods are stored if there is no associated type object? Do value types have sync root field (are value types thread safe if there is no sync root block for them)? 回答1: Do value types have a

How much space does string.Empty take in CLR

泪湿孤枕 提交于 2019-12-21 19:44:16
问题 How much space does string.Empty take in CLR? I'm guessing it's just one byte for the NULL character. 回答1: No, the string is a complete object, with an object header (containing a type reference, sync block etc), length, and whatever characters are required... which will be a single null character (two bytes) and appropriate padding to round up to 4 or 8 bytes overall. Note that although strings in .NET have a length field, they're still null-terminated for the sake of interop. The null

Cast generic class to interface

一个人想着一个人 提交于 2019-12-21 18:06:14
问题 I have a problem with casting a generic class to the interface it is implementing. My code is like this: interface foo { void foobar(); } class bar: foo { public void foobar() { throw new NotImplementedException(); } } now I have my factory that creates instances of my classes by the interface, mostly a simple microkernel (service locator). I will simplify it here. Normally it will look up the implementing class from the configs and the factory take the type as T but that doesn't matter for

Could the CLR support a “function pointer” value type?

℡╲_俬逩灬. 提交于 2019-12-21 07:56:18
问题 A few days ago I asked why delegates are reference types, based on my misguided notion that all you need for a delegate are two references: one to an object, and one to a function. What I completely overlooked (not because I wasn't aware, simply because I forgot) is that in .NET, delegates are at least partially in place to support events as a built-in implementation of the Observer pattern, which means that every delegate supports multiple subscribers by way of an invocation list . This got

SQL - Similarity between two strings of varying length

微笑、不失礼 提交于 2019-12-21 04:26:34
问题 I have a SQL Server table of products, and each product has a description that is publicly available on our website. I want to prevent, or at least warn our users when, a description is too similar to another product's description. Each product's description length can greatly vary. I'd like query for products with descriptions that include duplicate/similar paragraphs/blocks of text between one another. i.e. String A has a bunch of unique content, but shares a similar/identical paragraph w/

List closed types that runtime has created from open generic types

蹲街弑〆低调 提交于 2019-12-21 03:55:23
问题 When I list all the types in the current AppDomain, I see my generic types with the generic placeholders. However, if I instantiate my generic types with a type and then list all the types in the appDomain, I don't see the newly created closed types. In the example below, the output is only: Foo`1[T] I'm looking for the closed type: Foo`1[System.Int32] Is there a way to see the closed types that the runtime has created for me based on my open generic types? class Foo<T> { } class Program {