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


Post New Web Links

how to get a class reference as a reference and not a string to send for a generic method

Posted By:      Posted Date: September 15, 2010    Points: 0   Category :ASP.Net
 
I got some property that i get using generic method, there for I dont have it's <T>and I want to send it to another generic method but , how the heck do I get it's <T> :P?please look at the code below to understandit gets an entity framework objects, scan all it's properties and if the property is another entity framework object it would send it back to him self , the issue is that i dont know the new object <T> to send it back to him self :(search for the bold part to see what i'm missing//contains objects which we added so there wont be double adding private List<object> _addedObjects; public FakeGenericRepositoryExtension() { _addedObjects = new List<object>(); } public void Create<T>(T entity) where T : class { //add to created objects _addedObjects.Add(entity); //do something with object //... //start recircle process Type entityType = typeof(T); //run thrue each member of Type foreach (var member in typeof(Type).GetProperties()) { //get member value var member_value = member.GetValue(entity, null); //if not null //we must test this otherwise we can't get .BaseType if (member_value != null) { //get current member's base type string memberBaseType = member.GetValue(entity, null).GetType().BaseTyp


View Complete Post


More Related Resource Links

Custom Web Part deployment with class library reference

  
Hi All, We have class library as a project in our solution as well as a web part project. Our web part simply references and executes a service utility class in the class library and outputs it into a label. The deployment is successful but when attempting to add the web part to the page, it comes out with a error page saying "File Not Found" with a correlation ID and date/time reference. Once we take out the code that executes the utility class, it deploys fine and we're able to add it to the page without any issues. It seems evident that any reference to our class library causes this "File Not Found" issue... but we're not sure how to implement this solution. Any ideas? Do we add the class library dll directly into the GAC?  If so, how? Is there another reference we have to implement in the AssemblyInfo.cs?  If so, what does that look like? Any help is appreciated. Thanks, Eric

Error on VS 2008 Class Library project: are you missing an assembly reference?)

  
http://msdn.microsoft.com/en-us/library/bb153523(office.12).aspx Working with ASP.NET 2.0 Web Parts and Windows SharePoint Services 3.0 Based on the above MSDN Walkthrough, I created a Class Library VS 2008 project. When clicking the Build menu, 11 errors on System.Web.Security etc popped up.  What's wrong? *********************************************** using   System; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; Error 1 The type or namespace name 'Security' does not exist in the namespace 'System.Web' (are you missing an assembly reference?) Error 2 The type or namespace name 'UI' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)

Simple error connection string null reference

  
 It is failing on SqlHelper.ExecuteNonQuery(System.Configuration.ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString     public static string GetAboutMeName(string sUserID, string connectionString)        {             SqlParameter[] parameters = new SqlParameter[2];                      parameters[0] = new SqlParameter("@sUserID", SqlDbType.VarChar, 50);            parameters[0].Value = sUserID;             parameters[1] = new SqlParameter("@sResult", SqlDbType.NVarChar, 1000);            parameters[1].Direction = ParameterDirection.Output;             // Execute the stored procedure            SqlHelper.ExecuteNonQuery(System.Configuration.ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString, CommandType.StoredProcedure, "sprGetAboutMeName", parameters);         &n

An object reference is required for the nonstatic field, method, or property 'object.GetType()'

  

I'm getting this error, what i'm missing?

error: An object reference is required for the nonstatic field, method, or property 'object.GetType()'

 

static public void RegisterScriptMethod(System.Web.UI.Page page, string methodName, string methodBody)

{

StringBuilder sb = new StringBuilder();

sb.Append(

"<script language='javascript'>");

sb.Append(

"function " + methodName + " {" + methodBody + "}");

sb.Append(

"</script>");

//page.RegisterClientScriptBlock(methodName, sb.ToString());

Design Question - Child Class Reference

  

There has to be a better way to design the following:

public class Member {
  public int stateID {get; set;}

  public State state {
    get {
      if (this.stateID > 0) 
        state = State.GetByID(this.stateID);
    }
  }
}

public class State {
  public string name {get; set; }

  public static State GetByID(int id) {
    //populates state from db
  }
}


Now if I loop through a list of members and need to display the state name for each member and I call "myMember.State.name" - I'll get the name of the state but it costs me an extra query everytime I call that - even though some of the states may be the same.

Is there a way somehow keep some sort of cache of state name from the db for access?


Thanks.


Web config connection string error: a field initializer can not reference the nonstatic field

  

Hello:

I am try to get connection string from web config, but I got error" a field initializer can not reference the nonstatic field, method, or property '_default.connStr'. I search a lot. It says that I need constructor, but I am not sure how to write the constructor at class: public partial class _Default : System.Web.UI.Page


Here is my code:

{public partial class _Default : System.Web.UI.Page

    string txt;
    string username;
    OleDbCommand myCommand = null;
    OleDbDataReader myDataReader = null;
 

//retrieve the connection string from the ConnectionString Key in Web.Config
    string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

    //create a new OleDB connection
    OleDbConnection myConnection = new OleDbConnection(connStr);

protected void Page_Load(object sender, EventArgs e)
    {

            string strOledb = @"select * from tableone";
     
            OleDbCommand myCommand = new OleDbCommand(strOledb);

Serializing / Storing VS2010 generated WCF Proxy Class reference in SQL SessionState

  

Hello,

I have a WCF 4 service being consumed by an ASP.NET 3.5 (SharePoint 2010 actually) application.

Because we have implemented session support in the WCF service (ws2007HttpBinding) to maintain some objects that are very expensive to intialize, I'm also trying to keep my service client reference persisted on the ASP.NET consumer-side. However in order to persist it across post-backs, I need to add it to the session (using SharePoint's SQL SessionState provider), and this causes serialization (binary serialization) of the WCF service referece.

The ASP.NET application is throwing an error, because it cannot serialize the WCF service reference.

Any thoughts?


The Connection String Reference

  
Excellent site which provides readymade connection strings for all major data sources.

Executing method of the Generic class using Reflection.

  

Hi.

I have a generic class:

 abstract public class BaseTC<T>:IExecutable where T : Core, new()
  {
    private Type2 testInfo;
    private Type1 settings;
    private T core = null;
    ..
}

and I want to load such class from library the class is located in, and create an instance of it and execute methods later on.

I know how to use non-generic classes, but no idea how to call the same with generics.


Add Service Reference changing list to arrays in proxy class

  

I'm trying to consume an asmx service in a console app. When I add the service reference to my project i'm noticing that in the proxy class the lists are replaced with arrays. Also, the default constructors are missing. This is causing problems when i'm attempting to build the request object using the proxy classes. I've generated some classes using xsdobjectgen which i'm using as parameters to my web method. I've tried changing the Collection type in the settings but its still not working. Any ideas on whats going wrong?

 


Returning reference value from AJAX web method call on JQuery

  

I got this flag that I am checking for authenticated signed in users:

 

    <script type="text/javascript">
        $(document).ready(function () {
            $('#test').click(function () {
                alert(flag());
            });
        });

        function flag() {
            var _flag = "False";
            $.ajax({
   &n

Add Service Reference changing list to arrays in proxy class

  

I'm trying to consume an asmx service in a console app. When I add the service reference to my project i'm noticing that in the proxy class the lists are replaced with arrays. Also, the default constructors are missing. This is causing problems when i'm attempting to build the request object using the proxy classes. I've generated some classes using xsdobjectgen which i'm using as parameters to my web method. I've tried changing the Collection type in the settings but its still not working. Any ideas on whats going wrong?

 


Intellisense / class reference not working in MembershipProvider derived class file in App_Code fold

  

Hi,

I am new to ASP.NET and may be biting off more than I can chew, but I figure if I jump in the deep end I may learn more.

Can somebody tell me why the Visual Studio intellisense is not working in a newly created class file inside the App_Code folder?

I presume that System.Web is not being referenced from the App_Code folder correctly for some reason, because as soon as I type "using System.Web", everything is fine and then stops when I want to add ".Security" (no dropdown). I think this has an influence on the fact that the inherited MembershipProvider in my code is not highlighted/referenced and I cannot use the "Implement Abstract Class" option.

If I create a new class file in the root folder of my website, everything works fine. I have even tried to delete and recreate the file in my App_Code and it still did not work. I also tried to copy the file from my App_Code folder to the root and it still did not work. My code is as follows:

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;

namespace PodcastManager
{
    public class

WCF class library reference poster

  

Hi there,

 

Can anyone send the WCF class library reference poster?

 

Regards

TechV


Parsing string as a Button type reference in Visual c#

  

So basically, id like to parse the name of a string as an Button reference, and then alter the properties of that particular button with the reference being the same as the string parsed.

something like

Button b101 = new Button();

this.Controls.Add(b101);

s="b101";

boxlight((Button)s);

 

 private void boxlight(Button obj)
        {
            obj.BackColor = Color.RED;

}

however explicit type casting for this conversion is not supported.

 


[img]http://img260.imageshack.us/img260/8141/elfenlied1signaturedarkross17q.png[/img]

Unable to add reference to Class Library from a Workflow Console Application (VS 10 beta 2)

  
I got a really strange problem. I am using the beta 2 version of Visual Studio 10.

I have a Class Library, Activity Library and a Workflow Console Application. From the Workflow Console Application I want to make a reference to the Class Library (I've made some BusinessEntities there..), but I get the following error: 'The type or namespace name '<namespace name>' does not exist in the namespace blabla..

I made the reference, added it by typing using etcetera, but still getting error, also get an error where I import the reference (in the using part)

Can anyone help me out with this ? Is this a bug in Visual Studio 10 beta 2, or am I doing something wrong ?

How to reference an UI control from my ModelView class?

  

I have a listview which contains checkbox items

 <ListView x:Name="listControl"
               SelectionMode="Multiple"
               ItemsSource="{Binding Userlist}"
               ItemTemplate="{StaticResource ItemDataTemplate}" 
               CheckBox.Unchecked="OnUncheckItem" />

I need to know how to reference "listContro

Categories: 
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