.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

Assign values to base class properties

Posted By:      Posted Date: September 29, 2010    Points: 0   Category :ASP.Net

In my controller have a FormViewModel which inherits from a domain class declared in dbml.  In the constructor of the FormViewModel I want to do a shorthand assignment to the inherited class properties with the passed in object (ie thisPerson) without iterating through each property of the inherited class and assigning its value with corresponding property in the passing in object. Should I use super, base, this, or something else?

public MyFormViewModel: Person
  public SelectList Cities {get; private set;}
  public SelectList State {get; private set;}

  public MyFormViewModel(){}

  public MyFormViewModel(Person thisPerson) 

        this = thisPerson; 
     //or super = thisPerson;
     //base = thisPerson;


View Complete Post

More Related Resource Links

Class Properties Not Reflecting Their Changed Values


 I am using a class to track if a user cleared their personal information found within some text boxes on a form. In the button click event to clear the text boxes I am creating a new object to the class and assigning true to one property value. Sounds simple until I try and submit the form with a different button, and create a another object reference that I use in an IF statement to check the property value for true. Every time the statement fails because the value being returned from the getter in my class is false.

This is the class:

Public Class FormStateClass
    'property holds true or false 
    'based on if the user clears the populated form values.
    'True = Form was cleared
    'False = Form was not cleared

    Private _test As Boolean
    Public Property FormState As Boolean
            Return _test
        End Get
        Set(ByVal value As Boolean)
            _test = value
        End Set
    End Property

End Class

This is the code I am using to set the property to true:

Dim thisForm = New FormStateClass With {.FormState = True}

I've also tried these statements:

How to change the default page base class?


I've tried setting the <pages pageBaseType="DynamicWebPage" /> value in web.config, but when I response.write out the page type, I'm still getting Microsoft.WebPages.WebPage.

I'm simply trying to sub-class WebPage and add some additional functionality such as a dynamic PageData dictionary similar to Phil Haack's dynamic ViewData dictionary.



Can I replace the EntityObject as base-class in Entity Designer 3.5 sp1?


I'm using EF3.5sp1 for a project, and I've been working around many of its problems... as such, my entity partial classes have a lot of logic in them for change-tracking and whatnot.  Obviously, I'd like to factor this logic out into a common base class, but of course all my objects must derive from EntityObject.  Is it possible to tell them to derive from some class of my own invention (which would actually likely derive from EntityObject themselves)?

I'd rather avoid editing the EDMX file unless the changes will be safe on entity-model-update, since I'm still making changes to the database schema in this early state of my project.


Also, is there any good workaround for the fact that the change isn't tracked when you change EntityReference.EntityKey?

CLR Inside Out: What's New in the .NET Framework 4 Base Class Library


Just about everyone who uses Microsoft .NET uses the Base Class Libraries (BCL).When we make the BCL better, almost every managed developer benefits. This column will focus on the new additions to the BCL in .NET 4 beta 1.

Justin Van Patten

MSDN Magazine September 2009

CLR Inside Out: Base Class Library Performance Tips and Tricks


The common language runtime (CLR) sits at the very heart of managed code. Indeed, it is the heart of managed code, so to understand managed code you need to understand the CLR.

Kit George

MSDN Magazine January 2006

Serial Comm: Use P/Invoke to Develop a .NET Base Class Library for Serial Device Communications


Out-of-the-box, the only way of coding RS232 serial communications applications in the .NET environment is to import the outdated and somewhat limited MSComm ActiveX control. This article describes the development of a lean, multithreaded, and modern RS232 base class library in C# managed code. The library uses Platform Invocation Services to interact with the Win32 API directly. Application programmers can use the library from any .NET language through inheritance; the article explores examples written in C# and Visual Basic .NET.

John Hind

MSDN Magazine October 2002

Web Service and Base Class Sub Routines



I have several Web Services that I call using jQuery, they are all <WebMethod()> _    Public Function and return either a boolean or string, depending on the function.

I have some Web Service functions, where I would like to call sub routines I have in my base class, they are Public Sub's.

When I add a call of a sub routine in the Web Service function, I get a blue line that says 'Object reference not set to an instance of an object'.  If I change the sub routine to Public Shared Sub, then the blue line and error go away, but I get other errors from the calls I was successfully making to the base class routines before.

Is there a way to get these two to work together?

"The base class includes the field 'WebUserControl1', but its type (common_WebUserControl) is not


I tried to convert a project from ASP.NET 1.1 to 2.0 and found one big problem which stops the whole process.

An .aspx page from the subfolder "admin" includes a user control from the subfolder "common". Both subfolders ("admin" and "common" are in the root).

- admin
-- aspx page
- common
-- user control

The page works well when started from Visual Studio, but when the project is precompiled for deployment, the next error occurs:

"The base class includes the field 'WebUserControl1', but its type (common_WebUserControl) is not compatible with the type of control (ASP.common_webusercontrol_ascx)"

I tried to use "Reference" in the .aspx page, but that doesn't work.

Does anybody know any workaround for this?

override of base class error please help!!!


i would really like to override http keepalives for my webservice and i found some source code that seems promising but i get an error that says

"function GetWebRequest" Cannot be declared override. 


    Protected Overrides Function GetWebRequest(ByVal uri As Uri) As WebRequest
        Dim webRequest = DirectCast(MyBase.GetWebRequest(uri), HttpWebRequest)
        webRequest.KeepAlive = False
        Return webRequest
    End Function

how do i implement this into my serivice and why im i getting this error??? in other words what in hell is the uri that i should be passing into this function.

Any assictance would be greatly appreciated.


Abstract class properties work when not implemented?

Hi, I was just looking at a code example and was confused by the behavior of classes implementing an abstract class. So the project has an abstract class named GeneralItem with some abstract properties. Another class named NspItem inherits GeneralItem. NspItem does not implement any of the abstract properties from GeneralItem yet I can write code that successfully sets those properties. How is that working? Is the compiler automatically creating them for me? Example: public abstract class GeneralItem { public string Description { get; set; } } public class NspItem : GeneralItem { public NspItem() { } } static class Program { [STAThread] static void Main() { NspItem item = new NspItem(); item.Description = "Some String"; Console.WriteLine(item.Description); } } //Output would be: Some String

BinaryFormatter, SortedSet base class and a few instance variables.

/* This example successfully serializes and deserializes the SortedSet<string> base contents, but all the instance variables show up uninitialized. Here's the output: n1: 0 n2: 0 str: s == "String 1" s == "String 2" s == "String 3" Any ideas? */ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.Serialization.Formatters.Binary; using System.Runtime.Serialization; using System.IO; [Serializable] public class MyObject : SortedSet<string> {     public MyObject() : base() { }     protected MyObject(SerializationInfo info, StreamingContext context)         : base(info, context)     {     }     public int n1 = 0;     public int n2 = 0;     public String str = null; } namespace BasicBinarySerializationInheritanceFromSortedSet {     class BasicBinarySerializationInheritenaceFromSortedSetTest     {         static void Main(string[] args)         {             {                 MyObject obj = new MyObject();   &nb

All data in class properties disappear across WCF service

Hi, I have a class that i share betwee silverlight client and wcf service. I populate properties of the class with real data from the client, to be used in the server. I use debugger to step through the code when the call gets to the server, all the data ara gone and are replaced with null. All DateTime value change to 1/1/1001. But if pass primitive types such as int, string, no problem. This is happening only on one machine, but not on ther machine. Can someone tell me what is going on here? Thanks in advance

Can you Serialize a Derived class, cast as it's base?

Can you Serialize a Derived class, cast as it's base? (Using the stock XmlSerializer.Serialize?)   (The overall goal I'm trying to achieve, is I have 1 object, and I need to serialize it in 2 different ways, 1 with full info, one with half info, and I *thought* a base class would be the way to do it)   e.g. I have a base and derived class   [XmlRoot("MyBaseXml" )] public class MyBaseClass { public string baseField = "base" ; } [XmlRoot("MyDerivedXml" )] public class MyDerviedClass : MyBaseClass { public string derivedField = "derived" ; }   I make a new instance of my derived class MyDerviedClass obj = new MyDerivedClass();   And then I have the following serialization method(s)   /// <summary> /// Saves an object to a file /// </summary> /// <param name="obj"> Object to save</param> /// <param name="fileName"> Path to output to</param> public void Serialize(object obj, string fileName) { Type type = obj.GetType(); XmlSerializer xmlSerializer = new XmlSerializer(type); Serialize(obj, fileName, type); } /// <summary> /// Saves an object to a file casting it as a specific type /// </summary> /// <param name="obj"> Object to save</param> /// <param name="fileName"

Base class contructor firing first. why?

Hi,If I create instance of derived class, the code in base class constructor executing first. why is that? any reason?see code belowPublic Class class1 Sub New() Console.WriteLine("1") End Sub End Class Public Class class2 Inherits class1 Sub New() Console.WriteLine("2") End Sub End Class

Some Useful Properties of Binding Class

When binding the UI control with the data source the Binding class has some useful properties.In this post we will look at them and use them in sample application. The properties which we are going to discuss in this post are the FallbackValue ,TargetNullValue, and StringFormat. Image 1 shows the output of the example code.

Is it possible to add a class method to CLR base class like Date?

Hi All, I would like to add a class method like ParseYYYYMMDD to the Date base class. So that I can use the following code. Dim result As Date = Date.ParseYYYYMMDD(dateString) Any idea? Is it possible via extension? Thanks! Regards, AlexAlex Lau from HKSAR

Is it possible to get a base class by it's member?

I.e. I've got my class that contains a Panel. I do dragdrop with that panel, so when i get an form.dragdrop event I'm getting my Panel in eventArgs. I want to get the base class (MyClass), that contain that Panel to invoke some methods. Smth. like GetParent Class... Could you tell, is it possible?
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