system.reflection

How to call static method from ASP.NET MVC controller in C#

与世无争的帅哥 提交于 2019-12-12 18:34:01
问题 GetMethod does not find public static method if called from ASP .NET MVC controller. (From console application it work OK). To solve this dummy SaveEntityGenericWrapper method is used. How to remove SaveEntityGenericWrapper from code ? Why GetMethod("SaveEntityGeneric") returns null but GetMethod("SaveEntityGenericWrapper") works if called from ASP .NET MVC 2 controller ? How to make SaveEntityGeneric private if partial trust is used in MVC2 ? public class EntityBase() { public void

Reflection exclude all attributes from base class and specific attribute from all other derived classes

为君一笑 提交于 2019-12-12 10:16:12
问题 I have the following base, middle and derived classes below:: public class Base { [DataMemberAttribute()] public int ValueBase { get; set; } [IgnoreForAllAttribute("Param1", "Param2")] public int IgnoreBase { get; set; } } public class Middle : Base { [DataMemberAttribute()] public int ValueMiddle { get; set; } [IgnoreForAllAttribute("Param1", "Param2")] public int IgnoreMiddle { get; set; } } public class MostDerived : Middle { [DataMemberAttribute()] public int ValueMostDerived { get; set;

How can I dynamically add inherited properties to EF datastore?

…衆ロ難τιáo~ 提交于 2019-12-12 03:42:42
问题 In this post, I asked and answered how to dynamically import values for classes & properties in an EF/DbSet model with no hard coding. I couldn't believe I stumbled around long enough to figure out one way to do it. But... It revealed a problem that hours of looking through the instance hierarchy in the Locals window couldn't resolve: While I can import data dynamically on the target class, any properties from the base class it extends from fail. The initial post above illustrates this at the

C# Load Assembly w/ Common References

六眼飞鱼酱① 提交于 2019-12-12 02:55:43
问题 I've run into a slight issue - I'm writing a program that loads DLLs, each of which contain a class which inherits from a class existing in a library referenced by both the loaded DLL and the "host" program that is loading the DLL. The issue here is that, when I try to load and cast to the superclass: var assembly = Assembly.LoadFrom(dllPath); var type = assembly.GetTypes().FirstOrDefault(x => x.IsSubclassOf(typeof (MySuperclass))); ... Although both are referencing the class containing

Troubles changing current browser in Coded UI Tests

扶醉桌前 提交于 2019-12-11 11:39:16
问题 I have coded some automated web tests in C#, they use the Coded UI Test Library. These tests are not a bunch of recorded actions, They have been coded and executed on IE. I am using Visual Studio 2010 and I'm trying to launch my tests on Firefox 3.6. I have already installed the required components for this purpose. The problem is that I want to choose the browser I want to use to test my applications, so I want to change the field "currentBrowser" but I cannot have access to this property

How to set Property value using Reflection?

僤鯓⒐⒋嵵緔 提交于 2019-12-11 11:01:49
问题 I try to build a Generic Method which take class and set value using reflection and return a class type. protected static T GetSecureModel<T>(T model) { T secureModel = default(T); foreach (var property in model.GetType().GetProperties()) { if (string.CompareOrdinal(property.PropertyType.FullName, "System.String") == 0) { property.SetValue(property.Name, property.GetValue(model, null).ToString(), null); } } return secureModel; } How to return a Class after set value ? 回答1: OK. I solve it.

What's the equivalent to PropertyInfo.ReflectedType in .NET Core / .NET Standard?

怎甘沉沦 提交于 2019-12-11 07:28:31
问题 I need something like what PropertyInfo.ReflectedType does in the full framework. For now I've been not able to figure out what can be the alternative to the whole property of PropertyInfo . 回答1: ReflectedType is not supported in .NET Core and was "intentionally excluded" as guys from Microsoft says. This question on github contains a link to blog that explains the reason but is broken right now... You may look on PRs like Nunit. Eliminate use of ReflectedType in preparation for ASP .Net 5

Reflection - setting Type of returned obj?

こ雲淡風輕ζ 提交于 2019-12-11 05:03:01
问题 I am populating different types objects with datarows with each attrivute of the relevant object = to the similiarly name field in the datarow. I'd like to use a generic function to do this. How do I force the Type of the return object from the generic function. I don't yet know what the <T> syntax actually means: PopulateObject<T> does not return the type as I get compiler error - Cannot implicitly convert type 'object' to 'JobCard' See my code below public JobCard AcceptJobCard(Guid

How to prevent MemberInfo.IsDefined from throwing FileNotFoundException on irrelevant attributes?

对着背影说爱祢 提交于 2019-12-11 03:21:19
问题 My project references TypesDefinitionAssembly with type SomeType , which is marked by attributes XSerializationOptions from XSerializationLibrary and YSerializationOptions from YSerializationLibrary . Obviously, to check whether SomeType is marked by XSerializationOptions , I need to reference XSerializationLibrary as well. However, I don't want to reference YSerializationLibrary (which might even not be available). Currently, the call to typeof(SomeType).IsDefined(typeof

How can I loop though columns by name in an SSIS Script component?

ぐ巨炮叔叔 提交于 2019-12-10 18:22:17
问题 I'm loading a pipe delimited flat file into a staging table. During the load process an SSIS script component performs some operations on a row. It may set a flag in one field based on values in another field, add a prefix to certain columns, or apply formatting. For example, if a date is missing, the field is assigned to a default date. (if Row.EndDate_isNull then Row.EndDate = defaultDate) These scripts become cumbersome when the same transformation needs to be applied to a series of rows.