Restrict The Generics To Take Only Value Types?

Jul 12, 2010

I had asked with one question in the interview regarding generics

How can we restricts the one generic method to take only the value types.It should not be able to take reference types.

View 2 Replies


Similar Messages:

Generics - Declarative Syntax For A Collection Of Value Types?

Jul 16, 2010

I know that in ASP.NET (talking about 2.0 here primarily) one can set a property on an object that takes a collection of things (an enumerable type I'm guessing is the trigger) and then reference it declaritivly. For example:

<ObjectDataSource properties="blahblahblah">
<SelectParameters>
<asp:Parameter />
</SelectParameters>
</ObjectDataSource>

It is the <asp:Parameter /> part which is the root of my question. Say I wanted a simpler collection on a type. Say a List<String> or if generics are out, an IntegerCollection or StringCollection. How would I use that declaratively? Is <string value=''> allowed, or can I put raw values into it like <StringCollection>string, string, string</StringCollection> or what?

EDIT:

I feel like I was not clear enough in my question. I understand that ObjectDataSource implements its SelectParameters property as a ParametersCollection, and that one can use that property declaratively (in an ASPX page) to set up Parameter types within that collection. What I'm wondering is if I made something like StringCollection as a property on another control, is there a syntax (in ASPX) for adding strings to that collection? Or would I have to define a wrapping class like how DropDownList takes ListItems to fill its collection?

View 2 Replies

Security - Restrict File Types Allowed For Upload?

Jun 16, 2010

I want to limit the allowed uploaded file types to images, pdfs, and docs. What is the recommended way to approach this?I assume checking the file extension alone is not enough, since an attacked can change the file extension as he wishes.I also thought about checking against MIME Type using PostedFile.ContentType.I still don't know if this is adding any further functionality than checking against file extensions alone, and if an attacker have and ability to change this information easily.This is basically for a course management system for students to upload assignments and teachers to download and view them.

View 2 Replies

Architecture :: Class Design - Application Allows Admins To Add Types Such As Document Types?

Oct 12, 2010

I have an application that allows admins to add types such as document types and training types that are in seperate tables with a foreign key in a transaction table.

When structuring my class I decided to go with an abstract-like pattern (without the factory methods though). So I have a Type abstract class that defines my Save, Delete, and GetList methods. I have a training type class that inherits this class. The thing is all types have 3 main properties - defined in the abstract base - but have different source tables and thus different store procedures in my DbCommand object. So basically I repeat setting up the same parameters on all the derived classes. I would like to implement the common stuff in the base but I am getting thrown off by the difference in data sources.

View 2 Replies

How To Get Value Of Property By Name Through Generics Of A Class

May 11, 2010

I have a class, let's say class Sample. Sample has unknown properties but inherits an interface ISample. Said interface includes one method which I'm trying to create. This interface has a method called getPropertyValue(object o, string PropertyName).

It returns the value of the o.PropertyName using generics (unless you have a better suggestion). How do I write it? In other words, I want to be able to pass the name (as a string) of a property and return its value. Samples in C# preferrable but VB ok and any comments or suggestions are welcome.

View 2 Replies

Understand Polymorphism When Using Generics In C#?

Aug 25, 2010

I am having a problem understanding how polymorphism works when using generics. As an example, I have defined the following program:

public interface IMyInterface
{
void MyMethod();
}.....

So, at least I haven't completely misunderstood that. I am unsure exactly how I am to write a method that accepts a generic collection of classes that conform to the same interface.

I have a plan to completely hack around this problem if need be, but I would really prefer to do it properly.

View 3 Replies

C# - Reflection And Generics Get Value Of Property?

Apr 29, 2010

i am trying to implement a generic method which allows to output csv file

public static void WriteToCsv<T>(List<T> list) where T : new()
{
const string attachment = "attachment; filename=PersonList.csv";
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.ClearContent();

[Code]....

but I am not able to get the value of the object's property

View 2 Replies

Generics And Duck-Typing XML In .NET?

Feb 12, 2010

I'm working with some XML representations of data instances. I'm deserializing the objects using .NET serialization but something in my soul is disturbed by having to write classes to represent the XML... Below is what I'd LOVE to do but I don't know if the syntax or if it is even possible:Consider the following:

dim xmlObject = SomeXMLFunction() 'where some function returns an object/string representation of xml...
xmlObject.SomePropertyDefinedInTheXML = SomeFunction()

View 4 Replies

Finding Types Of Websites And Types Of Categories

Mar 1, 2011

i Dont know how many types of asp.net websites.

ie. asp.net webiste types of categories.

Give me the deatiled Information.

View 1 Replies

Mvc Views With CLR Generics Syntax In Inherits Attribute?

Oct 18, 2010

For reasons I won't go into I need to use CLR generics syntax in an ASP.NET MVC view.

I.E. NOT this:

System.Web.Mvc.ViewUserControl<someobject>

but this:

System.Web.Mvc.ViewUserControl`1[[someobject]]

When I run the application I get

Parser Error: could not load type `System.Web.Mvc.ViewUserControl`1[[someobject]]

View 2 Replies

Find # Of Occurrences & Count In String Using Collections / Generics?

Mar 4, 2010

I tried so much working with this to get distinct Words and their count. I'm using ASP.NET 2.0. And i also googled so much.

1)Ex(String): The DOTNET is Very Cool! The Best.

2) Capture all the sequences like Space, FullStop, Question Mark, Exclamation, Apostrophe, New Line....(May be with RegEx?)

3)Split Words According to the above sequences

4)Get Distinct Words(Occurences) and their count based on the input string in 1st statement.

Desired O/P:
The - 2
DOTNET - 1
Is - 1
Very - 1
Cool - 1
Best - 1

This is my Sample Code for your Ref.

[Code]....

View 3 Replies

Get All Types Using LINQ In Mvc?

Sep 20, 2010

viewModel.Messages = repository.GetAllMessages().OrderBy(x => x.MessageText);

with this I am getting 75 messges and i am displaying all the Messages in the Grid with two columns MessageText and MessageType But I need to write a Linq Query to get all my Distinct MessageTypes from Messages?

View 1 Replies

SQL Server :: Restrict Insert To Once Per Day?

Dec 20, 2010

How do I do this? My table contains a name, date , and a notes column. What I'm thinking is this, check the last inserted row where name = @name and date = getdate() then if this exists do nothing else perform the insert statement.

View 9 Replies

How To Restrict Access To An Specified Folder

Feb 15, 2011

How can I Restrict Access to an specific folder, for example I have a folder that Authenticated users upload different files in it. the problem is that every user can access the files via URL in the browser.I don't use asp.net login controls for authenticating and role memberships, I have written login page and roles my self via code behind.

View 1 Replies

How To Restrict User To Do Rating Only Once

Jan 15, 2011

How to restrict user to do rating only once..i m using AjaxControlToolkit Rating Control i VB.NET !

View 1 Replies

How To Restrict Class Usage

Mar 18, 2011

Is there a way to enforce a class only to be used in ASP.NET ? So that it can't be referenced in a WinForm app or throw exception when instantiated. Is there some kind of .NET class attribute for this purpose?

View 2 Replies

Restrict Page Access In IIS 6.0

Aug 24, 2010

I want to be able to restrict page access in a web application deployed in IIS 6.0. Say my web applications has these pages:

a.aspx
b.aspx
c.aspx
d.aspx

The proper way to access is [URL]" From a.aspx the other aspx pages could be loaded. What I want to be prevent is someone typing in: [URL]

View 2 Replies

Restrict The User Without Login?

Feb 15, 2011

i created some pages in asp.net. but i want to allow the users only if he is login. how to do that. is there any controls available for that one.

View 3 Replies

C# - Find Types In All Assemblies

Jan 14, 2011

I need to look for specific types in all assemblies in a web site or windows app, is there an easy way to do this? Like how the controller factory for ASP.NET MVC looks across all assemblies for controllers.

View 3 Replies

SQL Server :: How Many Types Of Views

Jul 22, 2010

what is views how many types of views , why we used views.

View 5 Replies

How Many Types The Authentication IIS Provided

Oct 4, 2010

How many types the Authentication IIS Provided? Is Form-authentication is provided by of IIS? if no,then how it works?

View 1 Replies

C# - Define A Variable Of Different Types?

Feb 8, 2011

to define a variable/property of more than one type. Let's say i want a property TextWebControl that is a WebControl and also implements Web.UI.ITextControl(f.e. like a TextBox or Label). But i don't want to enforce that it is a TextBox or Label, but only one that inherits from WebControl and also implements ITextControl so that it also would work with controls added in future releases of .Net-Framework.

.Net-Framework 4.0

Edit: I have retagged the question and added VB.Net because it's my default language. Normally it's no problem for me to understand C# also, but i must admit that it's difficult to translate generic stuff to VB.Net without experiences and it's also better documentated in C# than in VB. So i would appreciate(and aceept) a working example of a VB.net generic type of ITextControl/WebControl.

From Marc's answer i understand that i need a generic class. But how do i instantiate it in SomeClass? This won't compile:

Class SomeClass
Public Property info As InfoControl(Of WebControl, ITextControl)
End Class

View 3 Replies

C# - Browser Detection - IE And FF Types?

Feb 8, 2010

I need to separate IE and FF browsers from others it's a pseudo-code :

If (CurrentBrowser == IE(6+) or FF(2+) )
{
...
}
else
{
...
}
in protected void Page_Load() event (think so)
if ((Request.Browser.Type == "IE") || (Request.Browser.Type == "FF"))
{
WebMsgBox.Show("1111");
}

no effects :-/ what is IE and FF types?

View 6 Replies

C# - Formatting Address Of Different Types?

Apr 1, 2010

I have various classes which all contain address details, i.e. AddressLine1, AddressLine2, AddressLine3, Suburb, Town, etc.

On the front end, I need to format the address in a particular way, i.e.

AddressLine1<br />
AddressLine2<br />
Suburb State Postcode

If AddressLine2 does not exist or empty, don't show it. Quite straight-forward. I am trying to determine the best way to show this info. At the moment, the Address property of each class calls a FormatAddress method which writes out the html string. This exists as a method of the class. My opinion is that any formatting should exist from the front-end control i.e. ascx etc. However, if these DetailClasses need to format the same address info, what would be the best option, also making it easier to maintain?

View 2 Replies

C# - Getting Two Different Data Types From IEnumerable?

Jun 29, 2010

I have IEnumerable object with value1 and value2. value2 is an array and value1 is string. I want to databind this object to Listview like that. So both value1 and value2[0] (always first item in array) could be accessed via <%# Eval("value1") %> and <%# Eval("value2") %> .

How to write expression to handle both items ?

ListViewItems.DataSource = f.Items.Select(t => t.value1, t.value2[0]);
ListViewItems.DataBind();

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved