system.reflection

Entity Framework : Why this code doesn't work

我怕爱的太早我们不能终老 提交于 2020-02-08 09:39:28
问题 I'm using Entity Framework 6.0, DbContext. I'm using this method to copy an object and some related children: Imports System.Data.Objects Imports System.Data.Objects.DataClasses Imports System.Runtime.CompilerServices Public Module Entities <Extension()> Public Function CloneEntity(Of T As Class)(entity As T, context As ObjectContext, Optional include As List(Of IncludeEntity) = Nothing, Optional copyKeys As Boolean = False) As T Return CloneEntityHelper(entity, context, include, copyKeys)

Why after changing a static readonly field via reflection the output of that readonly field is old?

自闭症网瘾萝莉.ら 提交于 2020-01-13 05:06:28
问题 Why is the "someValue" variable which is readonly (but we still can change its value via reflection) output as "10", although it actually did change to 55? static class Program { static readonly int someValue = 10; static void Main(string[] args) { Console.WriteLine(someValue); // 10 typeof(Program) .GetField("someValue", BindingFlags.Static | BindingFlags.NonPublic) .SetValue(null, 55); // change readonly field via reflection to 55 Console.WriteLine(someValue); // output in console 10, //

Reflection: How do I find and invoke a local functon in C# 7.0?

空扰寡人 提交于 2020-01-12 12:43:12
问题 I have a private static generic method I want to call using reflection, but really I want to 'bundle' it inside of another method. C# 7.0 supports local functions so this is definitely possible. You would say "why don't you just call it directly?" but I'm using it to get the ability to use an object and System.Type in a strongly typed manner so I need to call it dynamically. This code already works if I have it as it's own private static generic method. private static void HandleResponse

Reflection: How do I find and invoke a local functon in C# 7.0?

我怕爱的太早我们不能终老 提交于 2020-01-12 12:40:11
问题 I have a private static generic method I want to call using reflection, but really I want to 'bundle' it inside of another method. C# 7.0 supports local functions so this is definitely possible. You would say "why don't you just call it directly?" but I'm using it to get the ability to use an object and System.Type in a strongly typed manner so I need to call it dynamically. This code already works if I have it as it's own private static generic method. private static void HandleResponse

Using System.Type to call a generic method

删除回忆录丶 提交于 2020-01-11 08:48:18
问题 I am using C#/.NET 4.0 and a Protocol Buffers library (protobuf-net) which provides the following functionality. public static class Serializer { public static void Serialize<T>(Stream destination, T instance); public static void Serialize<T>(SerializationInfo info, T instance); public static void Serialize<T>(XmlWriter writer, T instance); public static void Serialize<T>(SerializationInfo info, StreamingContext context, T instance); public static T Deserialize<T>(Stream source); } I need to

Is it possible to enumerate all methods and properties that are available via Invoke() of an [ADSI] object?

萝らか妹 提交于 2020-01-11 01:41:40
问题 I am curious if someone can describe how to enumerate ADSI methods available via a bound instance as [ADSI]$instance.psbase.Invoke() ? Research has turned up "refer to the docs for the ADSI interface". but I am not particularly happy with that answer. If I instantiate with: [ADSI]$lhost_group="WinNT://./Administrators,group" Then attempt: @($lhost_group.psbase.Invoke("Members")) | foreach-object {$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)} Powershell will return the

Loading library dynamically

可紊 提交于 2020-01-06 14:37:20
问题 I have the following project structure: Web API Class Library A Class Library B Class Library C These are the references between the projects Web API directly references A and B B directly references C C has a method which needs to ensure that A is loaded to use, by reflection, a type defined in it. My code actually is like the following public class C { public void MethodCallingBType( string fullClassName ) { //e.g. "MyNamespace.MyType, MyNamespace" string[] parts = fullClassName.Split( ','

ASP.NET Core 2.1 reflection doesn't work when deploying in AWS lambda

放肆的年华 提交于 2020-01-06 07:21:12
问题 I have a library with the below code for dependency injection. This loads all implementation classes ending with Handler and register them. public static class HandlerRegistrationExtension { private static IDictionary<Type, Type> _decoratorsAttributes; public static void AddHandlers(this IServiceCollection services, IDictionary<Type, Type> decoratorsAttributes) { _decoratorsAttributes = decoratorsAttributes ?? new Dictionary<Type, Type>(); List<Type> allAssembliesTypes = Assembly

how to create an instance of class and set properties from a Bag object like session

徘徊边缘 提交于 2020-01-05 09:27:34
问题 the class will be declared in runtime and values are stored in a Bag object like session or ViewBag . Now I want to create an instance of the class and set it's properties using Bag data . I know that I should use reflection , but I don't know if there is any method out of box that does such things or I should create one ? session["Foo"] = "foo"; session["Bar"] = "bar"; var instance = System.Activator.CreateInstance(Type.GetType(className)); instance = ? // how to set properties using session

How to use a dynamically generated object as the data source of CodeEffects generator

邮差的信 提交于 2020-01-02 05:21:51
问题 We are using this component www.codeeffects.com which allows us to create business rules based on the object properties. The html of the view is like this: @{ ViewBag.Title = "Post Example"; Html.CodeEffects().Styles() .SetTheme(ThemeType.Gray) .Render(); } @using (Html.BeginForm("Evaluate", "Post", FormMethod.Post)) { <div class="area"> <h1 class="title">Post Example</h1> <div style="margin-top:10px;"> <span>Info:</span> <span style="color:Red;">@ViewBag.Message</span> </div> <div style=