propertyinfo

Cast a property to its actual type dynamically using reflection (where actual type is generic)

我是研究僧i 提交于 2021-02-05 09:17:06
问题 This is a slightly different question asked here. I modified the same code into my needs like below: using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; namespace cns01 { class Program { public class ClassA<T> { public int IntProperty { get; set; } = 999; } public class ClassB<T2> { public ClassA<int> MyIntProperty { get; set; } public ClassA<string> MyStringProperty { get; set; } } static void Main

One method to read parameters, properties and return types at runtime using C#

 ̄綄美尐妖づ 提交于 2020-01-17 06:55:56
问题 With continutation to my earlier thread Using reflection read properties of an object containing array of another object. I am hoping to make this wonderful method from EvgK a generic method that can be used in multiple places in my code base. public static void GetMyProperties(object obj) { List<MyPropertyInfo> oMyProp = new List<MyPropertyInfo>(); foreach (PropertyInfo pinfo in obj.GetType().GetProperties()) { if (!Helper.IsCustomType(pinfo.PropertyType)) { //add properties - name, value,

One method to read parameters, properties and return types at runtime using C#

耗尽温柔 提交于 2020-01-17 06:55:15
问题 With continutation to my earlier thread Using reflection read properties of an object containing array of another object. I am hoping to make this wonderful method from EvgK a generic method that can be used in multiple places in my code base. public static void GetMyProperties(object obj) { List<MyPropertyInfo> oMyProp = new List<MyPropertyInfo>(); foreach (PropertyInfo pinfo in obj.GetType().GetProperties()) { if (!Helper.IsCustomType(pinfo.PropertyType)) { //add properties - name, value,

How to get the property that has a DataMemberAttribute with a specified name?

喜你入骨 提交于 2020-01-14 08:03:12
问题 How can I reflectively get the property that has the DataMember with a given name (let's assume every DataMember has a unique name)? For example, in the following code the property with the DataMember that has name "p1" is PropertyOne : [DataContract(Name = "MyContract")] public class MyContract { [DataMember(Name = "p1")] public string PropertyOne { get; set; } [DataMember(Name = "p2")] public string PropertyTwo { get; set; } [DataMember(Name = "p3")] public string PropertyThree { get; set;

ksoap2 AsyncTask PropertyInfo not recevied to webservice, why?

强颜欢笑 提交于 2019-12-25 06:34:55
问题 I need to send some parameters to my web service and get result. I have used ksoap2-android-assembly-2.4-jar-with-dependencies.jar in lib, my web service work properly : [WebMethod] public string TestParams(string userName, string password, string startRowIndex, string maximumRows, string OrderType, string IdOpera) { return userName + " - " + password + " - " + startRowIndex + " - " + maximumRows + " - " + OrderType + " - " + IdOpera; } In main java code : private class AsyncCall extends

Get Property Info from an object without giving the property name as string

雨燕双飞 提交于 2019-12-21 19:56:56
问题 For some reasons, I need to create a Dictionary of PropertyInfo instances corresponding to some class' properties (let's call it EntityClass ). Ok, I could use typeof(EntityClass).GetProperties() . But I also need to determine a value for some specific properties (known at compile time). Normally I could do one of the following: EntityInstance.PropertyX = Value; typeof(EntityClass).GetProperty("PropertyX").SetValue(EntityInstance, Value, null); In order to fill up my dictionary, I need to use

How to differentiate between value-type, nullable value-type, enum, nullable-enum, reference-types through reflection?

假装没事ソ 提交于 2019-12-21 17:56:34
问题 How to differentiate between value-type, nullable value-type, enum, nullable-enum, reference-types through reflection? enum MyEnum { One, Two, Three } class MyClass { public int IntegerProp { get; set; } public int? NullableIntegerProp { get; set; } public MyEnum EnumProp { get; set; } public MyEnum? NullableEnumProp { get; set; } public MyClass ReferenceProp { get; set; } } class Program { static void Main(string[] args) { Type classType = typeof(MyClass); PropertyInfo propInfoOne =

How to differentiate between value-type, nullable value-type, enum, nullable-enum, reference-types through reflection?

不想你离开。 提交于 2019-12-21 17:56:27
问题 How to differentiate between value-type, nullable value-type, enum, nullable-enum, reference-types through reflection? enum MyEnum { One, Two, Three } class MyClass { public int IntegerProp { get; set; } public int? NullableIntegerProp { get; set; } public MyEnum EnumProp { get; set; } public MyEnum? NullableEnumProp { get; set; } public MyClass ReferenceProp { get; set; } } class Program { static void Main(string[] args) { Type classType = typeof(MyClass); PropertyInfo propInfoOne =

Setting all null object parameters to string.empty

依然范特西╮ 提交于 2019-12-20 04:23:02
问题 I have an object that is contains strings and further objects that contain strings, what i need to do is ensure that the object and any sub objects have an empty string and not a null value, so far this works fine: foreach (PropertyInfo prop in contact.GetType().GetProperties()) { if(prop.GetValue(contact, null) == null) { prop.SetValue(contact, string.empty); } } the problem is this only works for the objects strings and not the sub-objects strings. Is there a way to also loop over all sub

How do you get the Value of a property from PropertyInfo?

。_饼干妹妹 提交于 2019-12-19 05:04:26
问题 I've got an object that has a collection of properties. When I get the specific entity I can see the field I'm looking for ( opportunityid ) and that it's Value attribute is the Guid for this opportunity. This is the value I want, but it won't always be for an opportunity, and therefore I can't always look at opportunityid , so I need to get the field based on input supplied by the user. My code so far is: Guid attrGuid = new Guid(); BusinessEntityCollection members = CrmWebService