¡@

Home 

c# Programming Glossary: propertyinfo

Convert IEnumerable to DataTable

http://stackoverflow.com/questions/1253725/convert-ienumerable-to-datatable

of a T DataTable table new DataTable typeof T .Name PropertyInfo props typeof T .GetProperties BindingFlags.Public BindingFlags.Instance.. T this List T items var tb new DataTable typeof T .Name PropertyInfo props typeof T .GetProperties BindingFlags.Public BindingFlags.Instance..

Dynamic LINQ OrderBy on IEnumerable<T>

http://stackoverflow.com/questions/41244/dynamic-linq-orderby-on-ienumerablet

in props use reflection not ComponentModel to mirror LINQ PropertyInfo pi type.GetProperty prop expr Expression.Property expr pi type..

How can I read the properties of a C# class dynamically?

http://stackoverflow.com/questions/4629/how-can-i-read-the-properties-of-a-c-sharp-class-dynamically

properties you can use the following code to get a PropertyInfo object for a particular property for a class and then use that.. to manipulate a particular object. String propName Text PropertyInfo pi someObject.GetType .GetProperty propName pi.SetValue someObject..

Comparing object properties in c#

http://stackoverflow.com/questions/506096/comparing-object-properties-in-c-sharp

comparisonObject.GetType if sourceType destinationType PropertyInfo sourceProperties sourceType.GetProperties foreach PropertyInfo.. sourceProperties sourceType.GetProperties foreach PropertyInfo pi in sourceProperties if sourceType.GetProperty pi.Name .GetValue.. new List string ignore foreach System.Reflection.PropertyInfo pi in type.GetProperties System.Reflection.BindingFlags.Public..

Convert DataTable to generic List?

http://stackoverflow.com/questions/545328/convert-datatable-to-generic-list

obj Activator.CreateInstance T Type entityType typeof T PropertyInfo properties entityType.GetProperties for int i 0 i properties.Length.. T DataTable table where T class new List Tuple DataColumn PropertyInfo map new List Tuple DataColumn PropertyInfo foreach PropertyInfo.. DataColumn PropertyInfo map new List Tuple DataColumn PropertyInfo foreach PropertyInfo pi in typeof T .GetProperties ColumnAttribute..

How to create LINQ Expression Tree with anonymous type in it

http://stackoverflow.com/questions/606104/how-to-create-linq-expression-tree-with-anonymous-type-in-it

source IEnumerable string fieldNames Dictionary string PropertyInfo sourceProperties fieldNames.ToDictionary name name name source.ElementType.GetProperty.. return null private static string GetTypeKey IEnumerable PropertyInfo fields return GetTypeKey fields.ToDictionary f f.Name f f.PropertyType.. public static Type GetDynamicType IEnumerable PropertyInfo fields return GetDynamicType fields.ToDictionary f f.Name f..

.Net - Reflection set object property

http://stackoverflow.com/questions/619767/net-reflection-set-object-property

be set using System.Reflection MyObject obj new MyObject PropertyInfo prop obj.GetType .GetProperty Name BindingFlags.Public BindingFlags.Instance..

Retrieving Property name from lambda expression

http://stackoverflow.com/questions/671968/retrieving-property-name-from-lambda-expression

method. Here's a method that'll return the PropertyInfo object for the expression. It throws an exception if the expression.. an exception if the expression is not a property. public PropertyInfo GetPropertyInfo TSource TProperty TSource source Expression.. the expression is not a property. public PropertyInfo GetPropertyInfo TSource TProperty TSource source Expression Func TSource TProperty..

How to remove all event handlers from a control

http://stackoverflow.com/questions/91778/how-to-remove-all-event-handlers-from-a-control

BindingFlags.NonPublic object obj f1.GetValue b PropertyInfo pi b.GetType .GetProperty Events BindingFlags.NonPublic BindingFlags.Instance..

Writing a CompareTo DataAnnotation Attribute

http://stackoverflow.com/questions/1607832/writing-a-compareto-dataannotation-attribute

if obj null return null var type obj.GetType var propertyInfo type.GetProperty propertyName if propertyInfo null return null.. var propertyInfo type.GetProperty propertyName if propertyInfo null return null return propertyInfo.GetValue obj null as IComparable.. propertyName if propertyInfo null return null return propertyInfo.GetValue obj null as IComparable public override bool IsValid..

Attribute.IsDefined doesn't see attributes applied with MetadataType class

http://stackoverflow.com/questions/1910532/attribute-isdefined-doesnt-see-attributes-applied-with-metadatatype-class

typeof MyTestClass .GetProperties foreach PropertyInfo propertyInfo in properties Console.WriteLine Attribute.IsDefined propertyInfo.. in properties Console.WriteLine Attribute.IsDefined propertyInfo typeof MyAttribute Console.WriteLine propertyInfo.IsDefined.. propertyInfo typeof MyAttribute Console.WriteLine propertyInfo.IsDefined typeof MyAttribute true Console.WriteLine propertyInfo.GetCustomAttributes..

Get an IDataReader from a typed List

http://stackoverflow.com/questions/2258310/get-an-idatareader-from-a-typed-list

a dynamic setter for the property summary param name propertyInfo param returns returns public static GenericSetter CreateSetMethod.. public static GenericSetter CreateSetMethod PropertyInfo propertyInfo If there's no setter return null MethodInfo setMethod propertyInfo.GetSetMethod.. If there's no setter return null MethodInfo setMethod propertyInfo.GetSetMethod if setMethod null return null Create the dynamic..

Simple C# CSV Excel export class

http://stackoverflow.com/questions/2422212/simple-c-sharp-csv-excel-export-class

Get properties using reflection. IList PropertyInfo propertyInfos typeof T .GetProperties if includeHeaderLine add header.. includeHeaderLine add header line. foreach PropertyInfo propertyInfo in propertyInfos sb.Append propertyInfo.Name .Append sb.Remove.. add header line. foreach PropertyInfo propertyInfo in propertyInfos sb.Append propertyInfo.Name .Append sb.Remove sb.Length..

Declaring Func<in T, out Result> dynamically

http://stackoverflow.com/questions/3752305/declaring-funcin-t-out-result-dynamically

on Queryable things get a little more complicated var propertyInfo typeof T .GetProperty sortExpressionStr Type orderType propertyInfo.PropertyType.. typeof T .GetProperty sortExpressionStr Type orderType propertyInfo.PropertyType first find the OrderBy method with no types specified.. orderBy Expression.Lambda Expression.Property orderParam propertyInfo orderParam how to use var sequence new T 0 .AsQueryable sample..

Sortable JqGrid using LINQ to MySQL (DbLinq) and Dynamic LINQ - Orderby doesn't work

http://stackoverflow.com/questions/4078592/sortable-jqgrid-using-linq-to-mysql-dblinq-and-dynamic-linq-orderby-doesnt

orderdData repository System.Reflection.PropertyInfo propertyInfo typeof Ticket .GetProperty sidx if propertyInfo null orderdData.. propertyInfo typeof Ticket .GetProperty sidx if propertyInfo null orderdData String.Compare sord desc StringComparison.Ordinal.. StringComparison.Ordinal 0 from x in repository orderby propertyInfo.GetValue x null descending select x from x in repository orderby..

Automatically INotifyPropertyChanged

http://stackoverflow.com/questions/527602/automatically-inotifypropertychanged

memberExpression.Expression as ConstantExpression var propertyInfo memberExpression.Member as PropertyInfo Invoke event foreach.. constantExpression.Value new PropertyChangedEventArgs propertyInfo.Name summary Subscribe to changes in an object implementing.. memberExpression lambda.Body as MemberExpression var propertyInfo memberExpression.Member as PropertyInfo Notify handler if PropertyName..

Retrieving Property name from lambda expression

http://stackoverflow.com/questions/671968/retrieving-property-name-from-lambda-expression

inference on the method call. You can do the following var propertyInfo GetPropertyInfo someUserObject u u.UserID share improve this..

AutoMapper (Or Similar) - Allow Mapping of Dynamic types?

http://stackoverflow.com/questions/7778216/automapper-or-similar-allow-mapping-of-dynamic-types

null return entity foreach var entry in properties var propertyInfo entity.GetType .GetProperty entry.Key if propertyInfo null .. var propertyInfo entity.GetType .GetProperty entry.Key if propertyInfo null propertyInfo.SetValue entity entry.Value null return.. .GetProperty entry.Key if propertyInfo null propertyInfo.SetValue entity entry.Value null return entity dynamic CurUser..

Loop Through An Objects Properties In C#

http://stackoverflow.com/questions/957783/loop-through-an-objects-properties-in-c-sharp

use public properties. Is that enough foreach PropertyInfo propertyInfo in firstType.GetProperties if propertyInfo.CanRead object.. PropertyInfo propertyInfo in firstType.GetProperties if propertyInfo.CanRead object firstValue propertyInfo.GetValue first null.. if propertyInfo.CanRead object firstValue propertyInfo.GetValue first null object secondValue propertyInfo.GetValue..

C# Developing .Net3.5 using reflection to get/set values to nested properties and/or nested fields

http://stackoverflow.com/questions/19936888/c-sharp-developing-net3-5-using-reflection-to-get-set-values-to-nested-properti

more nested class structures. c# inheritance reflection propertyinfo fieldinfo share improve this question You can get element..

Why is TargetInvocationException treated as uncaught by the IDE?

http://stackoverflow.com/questions/2658908/why-is-targetinvocationexception-treated-as-uncaught-by-the-ide

can I stop this from happening c# exception reflection propertyinfo targetinvocationexception share improve this question Hm..

Get string name of property using reflection

http://stackoverflow.com/questions/3661824/get-string-name-of-property-using-reflection

I can get the PropertyInfo.Name from it c# reflection propertyinfo share improve this question If you already have a PropertyInfo..

Declaring Func<in T, out Result> dynamically

http://stackoverflow.com/questions/3752305/declaring-funcin-t-out-result-dynamically

Func in T out Result dynamically Consider this var propertyinfo typeof Customer .GetProperty sortExpressionStr Type orderType.. Customer .GetProperty sortExpressionStr Type orderType propertyinfo.PropertyType now I want to declare Func int orderType I know.. is any workaround this is exactly what I want to do var propertyinfo typeof T .GetProperty sortExpressionStr Type orderType propertyinfo.PropertyType..

Is there a way to set properties on struct instances using reflection?

http://stackoverflow.com/questions/6280506/is-there-a-way-to-set-properties-on-struct-instances-using-reflection

know of an equivalent for PropertyInfo. c# reflection propertyinfo share improve this question The value of rectangle is being..

Reflection - get attribute name and value on property

http://stackoverflow.com/questions/6637679/reflection-get-attribute-name-and-value-on-property

and value on my properties using Reflection c# reflection propertyinfo share improve this question Use typeof Book .GetProperties..