.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Reflection question: PropertyInfo properties seem in an inconsistent state

Posted By:      Posted Date: October 10, 2010    Points: 0   Category :.NET Framework


Noticed something odd here... In class System.Collections.CollectionBase there is a property called InnerList

(see http://msdn.microsoft.com/en-us/library/system.collections.collectionbase.innerlist%28v=VS.90%29.aspx)

From the msdn link you can see that this property is read-only, as there is only a "get" and no "set". In the reflections namespace there is a class called PropertyInfo. When I query the PropertyInfo object corresponding to this InnerList property I get CanRead = true and CanWrite = false (as expected).

BUT when I go to retrieve the get method (with GetGetMethod) I get null. How is this possible, what does this mean?

Thanks in advance,

View Complete Post

More Related Resource Links

using reflection to emit properties to the top of the entity graph


I've got a class

  public class Criminal

public HouseholdMember[] LiedAboutFSHousehold { get; set; }

      public HouseholdMember[] FoodstampTrafficingHousehold { get; set; }
HouseholdMember inherits Person, as do many other classes.  

  public class HouseholdMember: Person


What I&#

C# Properties question

Hello, I have a class that contains several properties. This class is serialized to an XML file. The properties are: TestA, TestB, TestC, TestD. Can I make some code that allows me to: Serialize TestA and TestB to the XML file if condition X is met and serialize TestC and TestD to the XML file if condition Y is met? Right now, all properties are serialized to the XML file and that's not what I want. Thanks in advance!

Dependency Properties get/set method question



I recently added a new dependency property to a control of mine and bound its value to my control's ViewModel.  I put custom code in the Get method of the dependency property and saw the return value from that method does not come across to the ViewModel.  After some research, it seems that when the XAML parser attempts to get or set this property's value that it does not use these get/set methods at all.  So to make this DP useful for my scenario, I have to figure out another way to set this value ahead of time, i.e. through code.

My question is, what is the point of these get/set methods for your DP if the XAML parser isn't going to use them?  Is it really all that useful to use these in code?  I would imagine DP's are mostly being used for the purpose of data binding in which case it'd be helpful to be able to define how WPF will get and set the value.  I liken this scenario to a public property with a private backing field, and having WinForms or whatever just directly access the backing field and skipping my property's getter/setter, which would obviously be a bug.

I'd appreciate any insight on this.

conceptual state question


Good morning everyone:

I know this might be a silly question, but here I go.

It's clear that I should persist my workflows (in WF .Net 3.5) so they don't grab my resources. In my case I'm building a state machine workflow and I know that my persisted workflow keeps the state where the current item goes into the state machine, so, should I store an item state also in database? or should I only keep it into the persisted workflow?

In my case I am creating a workflow for the lifecycle of a product, and the product goes through many states in his "life", IMHO I think I should store the product state (in a database where the product exists, products table), even if it's replicated into the persisted workflow, am I right?

Thanks for any help or hints!

Reflection question - how to tell if a method is defined in an interface?


OK so the Reflection namespace has tools so you can tell if a method has a base definition in a class (MethodInfo.GetBaseDefinition().DeclaringType). This way for instance I can query the ToString method of my favorite class and see that yes, indeed this inherits from System.Object.

I also can detect if a method is an explicit interface implementation, by checking the name of the method (methods representing explicit interface implementation will have the fully qualified name of the interface pre-pended to the value of the Name property) so I'm okay there.

But what about plain ole interface implementations? How do I get this info?

Thanks if you can help!

Reflection question - how to tell which exceptions a method throws


I've found an ExceptionHandlingClauses collection in MethodBody but I'm looking for the exceptions that are *thrown*. You know, when you look at the ReadByte method of FileStream on msdn and you see that the ReadByte method throws two exceptions - the NotSupportedException and the ObjectDisposedException. 

How can I get this info programatically?


Error retrieving Workflow Properties in a Custom State Machine Workflow WSS 3.0

Using Visual Studio 2008 and the Office 2008 State Machine workflow template, I created a VERY SIMPLE workflow with ONE state. In the state initialization, I create a simple task. This works fine when I hard code the title, etc for the task. But, when I need to get some properties out of the list where the workflow was started, I get an exception  I've done this in a sequential workflow and it works fine. Error is: "Value cannot be null. Parameter name: uriString. Code snippet is:

using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Workflow;
using Microsoft.SharePoint.WorkflowActions;

namespace SOPProjectWorkflow
    public sealed partial class Workflow1 : StateMachineWorkflowActivity
        public Workflow1()

        public SPWorkflowActivationProperties workflowProperties = new SPWorkflowActivationProperties();
        public Guid

Question on WorkflowApplication class design ( Func Properties)





I found out that the Workflow Application class offers Func<T> properties to inject code for example when a error occurs.

whats the reason behind the Design Decission of giving the WorkFlow Foundation class Func<T> properties instead of event?


For Example


 Func<WorkflowApplicationUnhandledExceptionEventArgs, UnhandledExceptionAction> OnUnhandledException { get

; set

; }





 Action<WorkflowApplicationCompletedEventArgs> Completed { get

; set

; }


Is it just to prevent the multiple receipients ?

Or is it related to memory mangement due to fix pins caused by eventhandlers ? To be honest i must confess that i'm not sure wether Func<T> will created a fix pin in memory :-(

I'm not sure about if this is good or not, but it would be very nice to get knowledge of the reason why this class is event

How to get user defined properties from List in runtime using Reflection in .Net

Class Employee 
public int Sno  
     get ;  
public string Name  
     get ;  
     set ;  
        public int Salary  
    get ;  
    set ;  
class Program 
          static void Main(string [] args)  
       object r = test();  
       Type objtype = r.GetType();  
       PropertyInfo [] pi = objtype.GetProperties();  
       foreach (PropertyInfo p in pi)  
          object propertyValue = p.GetValue(r, null );  
          Console.WriteLine(":::" + propertyValue.ToString()); 
          //how to get the value of the property 
             Console .ReadLine();  
            }    //end of Main 
             private static object test()  
                List<Employee> list = new List<Employee >();  
      Employee obj = new Employee()  
                 { Name = "Ramakanth" , salary =111,Sno =10};  

                    obj = new Employee()
                 { Name = "Sravan", salary = 100, Sno = 20 };
        object objaa = list;  
        return objaa;  
Error: The following program shows the error "Target Parameter Count Exception was unhandled" 
Please help me how to rectify this error..

Properties Window Question for Visual Studio 2010

For Visual Studio 2010, how do you change the writing of the properties window categories like accessibility, appearance and behavior?  It is a grey foreground and grey background.

Truly Understanding View State

This article provides a detailed understanding of the ViewState.

WCF Tip: Using Properties in Service Contracts

you'll notice all of the Service Contracts are implemented with interfaces containing only methods. For the longest time I thought that's all that was supported, until I thought about it a little more. In C# land, properties are simply wrappers around a get method and set method, so why wouldn't we be able to use properties in a service contract? Well the answer is we can.

Automatic vs Explicit Properties

If the reason that motivated the change from automatically implemented property to explicitly implemented property was to change the semantics of the property then you should evaluate whether the desired semantics when accessing the property from within the class are identical to or different from the desired semantics when accessing the property from outside the class.

Design Patterns - Using the State Pattern in C#

What is the State Pattern?

The State Pattern is a behavioral pattern that can be used to alter the behavior of an object at run time. As the state of an object changes, the functionality of the object can change drastically. This change of behavior is hidden from the Client and the Client interfaces with a wrapper object known as the Context. The State Pattern is a dynamic version of the Strategy Pattern.

Dependency Properties

When you begin to develop appliations with WPF, you will soon stumble across DependencyProperties. They look quite similar to normal .NET properties, but the concept behind is much more complex and powerful

Xml File Methods and Properties

Method and Properties of XmlTextWriter class:
The XmlWriter class is a base class that outputs an XML data structure. It has methods to sequentially write XML elements in a proper hierarchy to create an XML file or other types of output streams. The System.Xml namespace provides support for the XmlWriter. It must be imported to the ASP.NET page with the directive

<%@ Import Namespace="System.Xml" %>

The XmlTextWriter

XmlWriter is an abstract class that is implemented as an extended XMLTextWriter class. The XmlTextWriter writes a sequence of XML nodes one element at a time. Output can be written to an XML file, although other streams of output data can be produced. It can create a new file or overwrite an existing file. Its non-cached writing techniques provides very fast generation of an output stream.

view state vs request parameters


If  the view state is the data entered into the form fields then they are supposed to be available in the request parameters or request body. Then why would we need view state for?


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend