.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: Type.GetMethod using int for enum parameter

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


we are using a "device system" here which is using reflection to invoke methods.

Consider this class:

public class Test
  public void SetDayOfWeek(DayOfWeek day)


MethodInfo m =
    BindingFlags.Instance | BindingFlags.Public,
    new Type[] { typeof(int) }, null);

m is null - probably because I am passing an int as the enum parameter DayOfWeek.

Is there any way to have an int be accepted as enum parameter in such a lookup?



View Complete Post

More Related Resource Links

type object parameter



I have a problem I can't figure out.

I've been trying to add a listbox with multi select enabled as a parameter to my select statement in sqldatasource.

So i created a function like this :

string strItemTypes = "";
foreach (ListItem li in lbItemType.Items)
   if (li.Selected)
      strItemTypes += "," + li.Value;
strItemTypes = strItemTypes.Substring(1);

which gives me the selected items like this for example : "1,2,3"...
Then I've been trying to add it to my sql select statement :

SELECT tblOfficesItems.idOfficesItems, tblStockItems.Name, tblStockItems.Description, tblStockItemTypes.TypeItem, tblStockItems.Notes FROM tblOfficesItems INNER JOIN tblStockItems ON tblOfficesItems.fkItem = tblStockItems.idItem INNER JOIN tblStockItemTypes ON tblStockItems.fkTypeItem = tblStockItemTypes.idTypeItem WHERE tblStockItems.fkTypeItem IN ( @fkTypeItems )

using a hiddenfield with a controlparameter of type=object
but it just don't seem to work, seems like the data just won't bind or something and I don't get any errors so I'm confused!!

then i tried this :

SELECT tblOfficesItems.idOfficesItems, tblStockItems.Name

How can I access a Type with generic parameter in XAML

Hello, How can I access a Type with generic parameter in XAML. class SampleClass<T> { } now in XAML: i want to access xmlns:local="Ref to SampleClass" How it will create the instance of SampleClass<T>?

How to expose an enum type to a client via WCF if it isn't used as a param type in any service oper

Hi,   I want to 'expose' an enum type from my server via WCF so that my client can access it. This happens automagically if I use the enum as a parameter type within a service operation, however, what if the particular enum isn't part of any service operation?   In other words, I've defined serveral enums within my Server that are quite useful to my client (even though they don't appear in any of my paramter declarations for the service operations).   The only way I can get this to work is simply create dummy service operations that contains these enum's as arguments. The MEX page then exposes these types for my client to use, but this seems a bit naff.   Thanks   Paul.

Calling a method with a class object as parameter data type.

   [WebMethod]    public string GetInfo(Customer inCust)    {        // Code in here    } I have a web service that resides on a remote server. I want to call a public method of theweb service named  "GetInfo". The method is shown above. The web service method expects a class object oftype "Customer". What I did to create a Customer object was to define in my asp.net project my own class named "Customer" which is exactlythe same as the class that belongs to the web service project on the remote server. I then created an instance of Customerand tried to call the web service passing in an object of type customer : my.Service ws = new my.Service(); // Get web service connectionCustomer aCustomer = new Customer();aCustomer.Initialize();ws.GetInfo(aCustomer) // call web service passing in a Customer object The problem is that the compiler gives me the following error: Value of type '_Default.Customer' cannot be converted to 'ws.Class1'. Here Default is refering to my Default.aspx.cs code. Why is this? Do I need to Cast my "aCustomer" class object to a type ofws.Customer ? How do I do that?

How to get input parameter's count and type by using MetadataImporter

I want to get each input parameter type of all operations in WCF Service via MetadataImporter, the code as below: Service Contract: it is default after you created a wcf applicaiton in vs 2010     [ServiceContract]     public interface IService1     {         [OperationContract]         string GetData(int value);         [OperationContract]         CompositeType GetDataUsingDataContract(CompositeType composite);         // TODO: Add your service operations here     }   Client Side:             string mexAddress = http://localhost:53720/Service1.svc?wsdl;                      BasicHttpBinding binding = new BasicHttpBinding();             MetadataExchangeClient MEXClient = new MetadataExchangeClient(binding);             MetadataSet metadata = MEXClient.GetMetadata(new Uri(mexAddress),  MetadataExchangeClientMode.HttpGet);          &nb

Use a generic type parameter with a GetBody<>

I have a generic messaging system which can pass any type of message around.  I have put the type of object in the Message Header so that I know when I receive it what type I need.  Is there any way to take the string that contains the name of the type and use that in the MessageReceived.GetBody<>. It would be nnice to be able to do that instead of a messy if else checking the string to know message types and then hard coding the Type in the GetBody.   Thanks in advance    needbrew

Allow System.Enum and System.ValueType as parameter types in a custom attribute

This is a continuation from a Microsoft Connect posting: https://connect.microsoft.com/VisualStudio/feedback/details/507907/error-an-attribute-argument-must-be-a-constant-expression-etc-incorrectly-received-when-the-argument-is-of-type-enum I am replying to Karel Zikmund’s latest posting, dated 29/07/2010 at 12:57.   Thank you for your response Karel, but once again, I am afraid you are wrong: > > This is irrelevant: the same is true irrespective of whether the parameter type is System.Enum or System.Object. > It is actually relevant - Think how IL code for this code should look like: >    void MyMethod(System.Enum arg) { System.WriteLine(arg); } >    MyMethod(MyInt1Enum.One); >    Mymethod(MyInt4Enum.Two); I’ve looked at the generated IL. It looks exactly the same as it does if I change the parameter type to System.Object. This is also what I expected. What IL did you expect to be generated? > System.Object is passed by reference which is a fixed size (4 or 8 bytes on x86 or x64 arch respectively). Yes, and so is System.Enum (and System.ValueType). > Enums and value types are passed by value (unless they are boxed) and their size therefore has to be known at JIT time. Yes, but System.Enum and System.ValueType are both neither an enum type nor a value type — they are both reference types that

CLR type reflection when creating a channel using the ChannelFactory

In the Xsd that represents our canonical model, a complex type has various choices (several xsd:elements within xsd:choice) – i.e. the property when deserialized into C# has several XmlElement attributes decorated above it….

[System.Xml.Serialization.XmlElementAttribute("exampleRequest1", typeof(ExampleRequest1))]

[System.Xml.Serialization.XmlElementAttribute("exampleRequest1", typeof(ExampleRequest2))]

[System.Xml.Serialization.XmlElementAttribute("exampleRequest1", typeof(ExampleRequest200))]

[System.Xml.Serialization.XmlElementAttribute("exampleRequest1", typeof(ExampleRequest201))]

Report Parameter type for a list of Employees to prompt like AJAX Textbox intellisence when the user


Hi All,

I have around 300 employees report to run for a specific employee, I cannot have a Dropdown as it would be too long for the report user to choose from. Is it possible in SSRS 2008 to have a text box that would provide intellisence like AJAX textbox and provides user with Employee name to choose from database or is there any other better way to select the right mployee name to run this kind of report. being a newbie to SSRS I am unable to go furthur on this. All help is great help. Thanks in advance for responding.

Get method parameter's values using reflection


By writing the following code I can get the method parameters metadata.


        void test(int x, string s)
            StackTrace st = new StackTrace(true);

            foreach (StackFrame sf in st.GetFrames())
                MethodBase mb = sf.GetMethod();
                foreach (ParameterInfo pi in mb.GetParameters())


I need the parameters value (the value that was passed to the method).

Can I get it in C#?


Thanks Gil

Error Value cannot be null Parameter name: type after move app to server


Hey, i have a WebSite project which i published, in the machine where i published the WebSite everything works smooth.

when i moving it to the server, i got the Error:

Value cannot be null.<br>Parameter name: type

Value cannot be null.
Parameter name: type

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: type


and the details of it:


[ArgumentNullException: Value cannot be null. Parameter name: type] System.Activator.CreateInstance(Type type, Boolean nonPublic) +2843963 System.Web.Profile.ProfileBase.CreateMyInstance(String username, Boolean isAuthenticated) +76 System.Web.Profile.ProfileBase.Create(String username, Boolean isAuthenticated) +312 System.Web.HttpContext.get_Profile() +108 PasswordRecovery.get_Profile() +39 PasswordRecovery.Page_PreInit(O

Is it possible to pass an array of values, or a custom type as a parameter?


I am using a web service as a datasource.  When I create my report I would like to pass
a string array to this web method to retrieve the data for the report.  Is this possible or is there
a similar way to do this such as passing a custom type?





Service Reference: return type converted to a "ref" parameter



I created a WCF service using Message Contracts. One of the operations in the service takes in an entity (embedded in a message contract) and returns an updated version of the entity:

EWADemo.MessageContracts.CustomersService.SaveCustomersResponseMessage SaveCustomers(EWADemo.MessageContracts.CustomersService.SaveCustomersRequestMessage request);

[MessageContract(WrapperName = "SaveCustomers")]
public partial class SaveCustomersRequestMessage
 public EWADemo.DataContracts.Customers Customers

[MessageContract(WrapperName = "SaveCustomersResponse")]
public partial class SaveCustomersResponseMessage
 public EWADemo.DataContracts.Customers Customers

When I tried creating a s

Specifying a parameter in a matrix filter - the data type automatically changes to 'text' when it



When specifying a parameter in a matrix filter (Report Builder 2) the data type automatically reverts to 'text' when it should be 'date/time'.  Removing the parameter and re-adding it displays it correctly as 'date/time' but this isn't saved when clicking 'OK'. 

The problem only becomes apparent when the parameter is set to 'allow multiple values'.  Once this is selected the report throws up the following error:

"An error has occured during report processing. The processing of FilterExpression for the tablix 'Tablix1' cannot be performed.  Cannot compare data types System.String and System.Object[]. Please check the data type returned by the FilterExpression."

Is this a bug with Report Builder 2 or is there something wrong with my report model?

Any help/guidance greatly appreciated.

C# why class cannot derive from type parameter?


Unlike C++, why template class can not be derived from type parameter in C#

public class FeatureObject <Interface> : FeatureBase, Interface


it give compiler error: cannot derive from 'Interface' because it is a type parameter.

Any reason?




Convert string value to type and pass as type parameter.



In the below code... i am getting all filenames from a directory.  parsing out the directory names & the .vb extension. . . then converting those filesnames to classes.  Every file in the LPCriteria direcotry is its own class with a "Evaluate" function.

The problem comes in here:

Dim boolFlagged As Boolean = CType(MyInstance, objType).Evalua

Because the "objType" comes up as "type 'objType' is not defined".   the parameter requested is "Object as Type".  But i dont know the type, as it is really the name of the file...       any ideas how i get this parameter passed in?   Thanks! :)

Dim strPath As String = System.AppDomain.CurrentDomain.BaseDirectory()
Dim files As String() = System.IO.Directory. _
     GetFiles(strPath & "App_Code\GeneralClasses\LPCriteria\", "*")


Stored Procedure multile values parameter with integer type



I have created a store procedure with input paramenter @param1 of integer type to return result from a select statement as below:

SELECT * FROM TableABC WHERE columnabc LIKE (@param1)

the columnabc in the WHERE clause is of integer type.

I will like to be able to pass multiple values of integer to @param1, such as @param1 = 1, 2, 3.

Please advise how do I achieve that?



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