codedom

CodeDom and collection initializers

六月ゝ 毕业季﹏ 提交于 2019-12-05 02:27:58
问题 Is there a way to generate a dictionary initializer using the C# CodeDom? Are those supported at all? I would like to have: private IDictionary<string, string> map = new Dictionary<string, string> { { "Name", "Value" }, ... }; 回答1: This is not possible using the CodeDom constructs. They were not updated for collection initializers. LukeH has an excellent blog post on the subject of 3.5 features and the CodeDom http://blogs.msdn.com/b/lukeh/archive/2007/07/11/c-3-0-and-codedom.aspx 回答2: You

How do I change accessibility on an accessor using CodeDom?

◇◆丶佛笑我妖孽 提交于 2019-12-04 17:39:58
In C#, you can have more restrictive accessors on the accessors of a property like this: public List<String> Name { get; protected set; } How can I accomplish this when generating code using CodeDom? CodeDom doesn't directly support this. CodeDom dates from an era when C# and Visual Basic didn't support different accessibility on the get and set method, and hasn't been updated to support the new functionality. You will probably need to use a CodeSnippetTypeMember (though with a bit of ingenuity you could still use CodeDom to generate the getter and setter bodies). 来源: https://stackoverflow.com

Is the VC++ code DOM accessible from VS addons?

倖福魔咒の 提交于 2019-12-04 14:54:10
问题 Visual Studio IntelliSense for VC++ includes the "complete" EDG C++ parser (also used by Intel and others). Since the C# Code DOM is accessible to addons (correct me if I'm wrong), is the C++ Code DOM also accessible? Can this be used to analyse an open VC++ project within the VS environment? 回答1: The Visual C++ Refactoring extension is able to rename a member project-wide. Its built by MS but obviously they used the internal Code DOM to achieve this. So it is possible, I just don't know how,

Adding Assemblies to BuildManager using CodeDOM causing intermittent errors

帅比萌擦擦* 提交于 2019-12-04 13:58:07
I am using CodeDOM to create an in-memory assembly at run time like so: public Assembly Compile(CodeCompileUnit targetUnit) { string path = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).AbsolutePath); var compilerParameters = new CompilerParameters { GenerateInMemory = true, IncludeDebugInformation = true, TreatWarningsAsErrors = true, WarningLevel = 4, CompilerOptions = "/nostdlib", }; //For system.dll compilerParameters.ReferencedAssemblies.Add(typeof(System.Diagnostics.Debug).Assembly.Location); //For system.core.dll compilerParameters.ReferencedAssemblies.Add

T4 vs CodeDom vs Oslo [closed]

点点圈 提交于 2019-12-04 11:04:35
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . In an application scaffolding project on which I'm working, I'm trying to decide whether to use Oslo , T4 or CodeDom for generating code. Our goals are to keep dependencies to a minimum and drive code generation for a domain driven

How can I use CodeDOM to create and load an assembly in an AppDomain?

妖精的绣舞 提交于 2019-12-04 09:12:24
I am working on a project that will use CodeDOM to create a class that evaluates a user-defined expression, creates an assembly for the class, and loads the assembly. Since there can be a fair number of user-defined expressions, I would like to first create an AppDomain, execute the CodeDOM creation/loading and executing for the assembly within that AppDomain, and then unload the AppDomain. I've searched quite a bit, and found many examples of how to load an existing assembly into an AppDomain, but I can't seem to find one that shows me how to create the assembly from within the AppDomain.

Execute JavaScript from within a C# assembly

末鹿安然 提交于 2019-12-04 08:59:03
问题 I'd like to execute JavaScript code from within a C# assembly and have the results of the JavaScript code returned to the calling C# code. It's easier to define things that I'm not trying to do: I'm not trying to call a JavaScript function on a web page from my code behind. I'm not trying to load a WebBrowser control. I don't want to have the JavaScript perform an AJAX call to a server. What I want to do is write unit tests in JavaScript and have then unit tests output JSON, even plain text

Dynamic code generation

眉间皱痕 提交于 2019-12-04 08:00:29
I am currently developing an application where you can create "programs" with it without writing source code, just click&play if you like. Now the question is how do I generate an executable program from my data model. There are many possibilities but I am not sure which one is the best for me. I need to generate assemblies with classes and namespace and everything which can be part of the application. CodeDOM class: I heard of lots of limitations and bugs of this class. I need to create attributes on method parameters and return values. Is this supported? Create C# source code

How do I create a class that inherits from another and passes a type parameter in CodeDom?

北战南征 提交于 2019-12-04 04:28:07
问题 Here's what I want the resulting class declaration to look like: public sealed partial class Refund : DataObjectBase<Refund> { } } This code (snipped): targetClass = new CodeTypeDeclaration(className); targetClass.IsClass = true; targetClass.TypeAttributes = TypeAttributes.Public | TypeAttributes.Sealed; targetClass.IsPartial = true; //partial so that genn'ed code can be safely modified targetClass.TypeParameters.Add(new CodeTypeParameter{ Name=className}); targetClass.BaseTypes.Add(new

CodeDom generic type constraint

喜欢而已 提交于 2019-12-04 00:33:34
Is there a way to generate a class constraint with CodeDom. Because when I use something like var method = new CodeMemberMethod(); var genericParam = new CodeTypeParameter("InterfaceType"); genericParam.Constraints.Add("class"); method.TypeParameters.Add(genericParam); the generated code is like private InterfaceType GetImpl<InterfaceType>() where InterfaceType : @class { } The best workaround i found is to use a leading whitespace before the class genericParam.Constraints.Add(" class"); But this seems to be at best a workaround. It seems that there is no straigntforward way to specify that