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

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

Setting method parameters to accept only string or Type.

Posted By:      Posted Date: May 22, 2011    Points: 0   Category :.NET Framework

I have a dictionary object I'm working on that can take keys of either of two types: string or System.Type. Currently I have TKey set as object, and then explicitly check the type. Is there a better way to handle this?


as an example, in the below code, I want to ...

  replace IDictionary<object,IDataTranslator> with IDictionary<string or Type,IDataTranslator>

  replace the two internal dictionary with one, that is only string/Type - that way I don't have to do any redundant type checking?


//stores data for specialized/default translations between types/strings
//IDataTranslator is a custom interface used in the library
public class translators : IDictionary<object,IDataTranslator>
 //holds the string-based translators
 protected Dictionary<string,IDataTranslator> m_translators_s;
 //holds the dictionary based translators.
 protected Dictionary<Type,IDataTranslator> m_translators_t;


View Complete Post

More Related Resource Links

Read an XML file, setting uname/pw, Accept, Content-Type

Hi; To read some REST XML data we need to set the username, password, and tell it for the http request Accept: application/xml Content-Type: application/xml Is there a sample anywhere showing how to do this? thanks - daveVery funny video - Reporting as a Metaphor

How to Encrypt Query String Parameters in ASP.NET

Encrypt Query String Parameters in ASP.NET.u can send secure data one page another page u can also use query string to encrypt

Conversion from string to type 'Date' is not valid



Im receiving a strange error Error Message: Conversion from string "15/08/2010 22:21:35" to type 'Date' is not valid.

I know this is generally down to cultural date formats etc, however the reason this is strange is it just randomly occured twice in the last week, the website has been running since october and nothing has changed,

The error constantly occured until the IIS was reset and recompilled the site, its been running fine since, however im just trying to figure out what could cause such an error to occur.

I've narrowed it down to a line of code which is:

bktime = DReader.Item("Bktime").ToString

bktime = Year(CDate(bktime)) & "-" & fmt(Month(CDate(bktime)), 2) & "-" & fmt(Day(CDate(bktime)), 2)

Has anyone else encountered this randomly occuring and is there anything i can put in place to prevent this in future?



Problem with Finder method with parameters



Could someone explain me how to provide some value to the parameters in a finder method. For exemple I know that the BDC list WP use this method. Is there a way to provide some value for those parameter at runtime? I really don't understand (even after some deep search on the web) where are the values for the parameters from and how we can connect to them. Even with C# code I can't find any information on how it work.

I don't want to define my parameters as filter in the ADF because then I will have this filter section in my BDC list WP (or is there a way to get rid of that?). Actually one of the parameter should be automatically calculated from a value in a SP list, the other parameter should be provided by my own filter web part.

Thank you for your help.

BCS Updater Method in External Content type


HI, I have a List (External Content type ) with CRUD methods written.for example. Employee with fields






If want to update only Remarks field and want to display the other fields.(other field should not be editable). How can i do it throught VS2010. If I made those fields readOnly and preupdaterField true. those fields not displays while editing. I want to show those fields but not to edit. any suggestions????

2)while displaying (ReadList )if I want to display only EmpName and EmpID.How can i do it?


or please try to give some links about all the properties for a Type Decriptor and how they are related with CRUD methods.



Capture and pass "abc\xyz" as a string into my WCF method

Hi All, I am trying to implement WCF Method where client has to pass like "abc\xyz" as a string i have to capture it and pass to my method. I am not able to do it. In our application we can split the string  and we can do what ever we can do . but string comes from client site so who do i capture into my method. I am very much new in WCF. Could u please help me. Thanks Shekhar  

Cleanest way of setting max string length for text in GridView cells?

I want to make sure that each row in the table is the height of one line of text only.  I know you can set RowStyle-Wrap="false", but I also don't want any really wide rows.  I know I can go through each cell on RowDataBound or something and cut it to a particular length and then append an ellipsis on the end, but is there a neater way of doing the same thing?

How to pass parameters from Application Main method to modules.

Hi , We created Prism WPF application.we have to pass some parameters(some information) to modules(they are instantiated by Bootstrapper) from Main method of App.xaml  Thanks in Advance.

Passing Parameters to Web Service Method using XML DataSource

I would like to know how to pass parameter values to a web service that I am using as a data source.  I am using the Data Source Type XML.  I have been able to retrieve data back from the web service method that does not require parameters.  But I need to be able to use a web service that requires parameter values.  How do you use the XML data source type with parameters?  I have use information from the article  http://www.codeproject.com/KB/reporting-services/SSRS2005XML.aspx. thanks, Lloyd

Conversion from type 'TextBox' to type 'String' is not valid

I have a FormView that allows a user to register for a company event. I want to do a couple of things with this form. 1. I need to write this data to a MS SQL database 2. I need to send an email confirmation of their registration to their email. I know how to do both of these things, but i am having trouble doing both at the same time. It would be nice if I could do it in one click, but I coded it into two pages to try to help simplify it. The first page allows the user to input their information into a formview and when they click the submit button, it places those answers into session variables:Protected Sub InsertButton_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Session("FirstName") = Me.FormView1.FindControl("FirstName") Session("LastName") = Me.FormView1.FindControl("LastName")  <li> <label> First Name</label> <asp:TextBox ID="FirstName" runat="server" class="text-box" Text='<%# Bind("FirstName") %>' /> </li> </ul> </div>

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?

infopath 2007 Expected value type: end-of-string ! calculated field

Hello I am using infopath since there is no field with type date and time in InfoPath 2007. I created three fields one for date one, for hours, and one for minutes then I created forth field that concatenate the values of the three fields this field will be used as column in form template library used by my form. All seems good so far but when I tried to concatenate those fields go the following error Expected value type: end-of-string how can I solve this ? my xpath looks like ../my:calmomoDate../my:cbmomoHours:../my:cbmomoMunites Thanks  Momo

BCS : How to set permissions to an external content type's method

guys, Environment: sp 2010, BCS using SPD I have created an external content type from a LOB sql server 2008 DB, created list and form pages, created read, update, delete, edit methods( all the default operations that SPD shows), from the list page i am able to read and write data back the LOB DB also successfully. Also i know there are permissinos that i can set on the external content type but the problem that i am facing is that i dont see any place\ option where i can assign\ restrict permissions of the content type's method to a certain SP group from neither CA nor SPD i.e if i want a certain group to have only execute permissions only on READ method. Would be great if anyone can tell me if at all this is possible. thanks sameer

Is there a method that returns the control's type, such as "TextBox", "TextBlock", "Canvas", etc.,

Hello, I have a method that is passed in a FrameworkElement Ctrl.  When I use Ctrl.GetType().ToString() I get "System.Window.Controls.TextBox" or another string if a different type of control is passed in.  All I am interested in is the text after the last dot/period.  In my searching I thought I came across something that just returned the portion I'm looking for, but now can't find it. Is there a method that returns the control's type, such as "TextBox", "TextBlock", "Canvas", etc., without its parents? Regards, Robert

Weird Issue with the MOSS Search : FileExtension metadata object type instead of string

Hello, We 've got a strange issue with the search and especially with the FileExtension metadata. when we make a query on the search engine, we receive for the FileExtension metadata an unexcpected result. here is a printscreen showing the issue. http://cid-53eee937847a625e.photos.live.com/self.aspx/Public/Untitled.jpg as you can see the Type of the FileExtension is object and it should be string and I checked the type of the object and it's System.String[] the element at the index 0 contains the value! what's wrong ? thx in advance


Hi all,Here's some simple code<a href='<%= string.Format("../Print/Print1.aspx?withParameter={0}", Para )%>'>HyperLinkText</a>and it works well. so i guess i can write anything like this, so i wrote a test:<input type="button" value="Btn1" onclick='<%= string.Format("window.open('','_blank')") %>'/> <input type="button" value="Btn2" onclick="window.open('','_blank')"/>However, Btn1 does not work.. for some reason i have to NOT to use server control, so i wite it in inline-code style,why the first hyperlink work well, but Btn1 fails?could anyone tell me?thank you~

error: cannot implicitly convert type 'string' to 'int?'

Hey guys,I am trying yo build the following class for which i get an error on the line this.id = e.id as cannot implicitly convert type 'string' to 'int?'. can anybody help me with it??many many Thanks,Chetan.using System;using System.Collections;using System.Collections.Generic;using System.Linq;using System.Data.Linq;using System.Text;using System.Runtime.Serialization;using HsInternet.Data.DAL;namespace HsInternet.Data.BLL{    public class Baby    {        public int id { get; set; }        public string name { get; set; }        public string parents { get; set; }        public int gender { get; set; }        public string weight { get; set; }        public string length { get; set; }        public DateTime date { get; set; }        public DateTime time { get; set; }        public string image { get; set; }        public string ipa { get; set; }        public string ipb { get; set; }        public Baby()  &
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