PC Review


Reply
Thread Tools Rate Thread

C#: Member variable always null in inherited class! Bug or feature?

 
 
Fett
Guest
Posts: n/a
 
      14th Feb 2005
Problem: My member variables in the child class are always null. I
don't know why this happens!

I have a base class for handling a user flow in my web, CWebUseCase,
the class is declared like: public class CWebUseCase {...};

This class is inherited into several specific flows like this one
CXmlFileList, which I will use to present a simple list to the user.

//CXmlFileList declaration:
public class CXmlFileList : CWebUseCase, IWebUseCase
{
private string strTest = "Test string";

public void testFunction()
{
// This Assert fails!!!!
Debug.Assert(strTest!=null);
strTest = "Hello";
// This Assert also fails ?????
Debug.Assert(strTest!=null);
}
}

The class is instanciated dynamically and the assembly in which the
class resides is also loaded dynamically:

/* Other class which calls the use cases */

// Load the assembly
assembly = Assembly.LoadFile(strAssemblyPath);
// Instanciate the class and cast the type to the implemented interface
uc = (IWebUseCase) assembly.CreateInstance("MyNamepace.CXmlFileList");
// Cast the interface to the base class
m_uc = (CWebUseCase)uc;

// Call the test function
m_uc.testFunction();



Why doesn't the member variable take any values? Does it have anything
todo with the dynamic creation?

Please help me, this "feature" affects an otherwise quit good design of
our application.

Thanks!/Peter

 
Reply With Quote
 
 
 
 
=?Utf-8?B?UmFrZXNoIFJhamFu?=
Guest
Posts: n/a
 
      14th Feb 2005
Hi Fett,

I would say the best method to extract strings from strings would be by
using Regular Expressions.

Since, in this case you need the value in between the quotes, you could use
the :q construct.

HTH,
Rakesh Rajan

"Fett" wrote:

> Problem: My member variables in the child class are always null. I
> don't know why this happens!
>
> I have a base class for handling a user flow in my web, CWebUseCase,
> the class is declared like: public class CWebUseCase {...};
>
> This class is inherited into several specific flows like this one
> CXmlFileList, which I will use to present a simple list to the user.
>
> //CXmlFileList declaration:
> public class CXmlFileList : CWebUseCase, IWebUseCase
> {
> private string strTest = "Test string";
>
> public void testFunction()
> {
> // This Assert fails!!!!
> Debug.Assert(strTest!=null);
> strTest = "Hello";
> // This Assert also fails ?????
> Debug.Assert(strTest!=null);
> }
> }
>
> The class is instanciated dynamically and the assembly in which the
> class resides is also loaded dynamically:
>
> /* Other class which calls the use cases */
>
> // Load the assembly
> assembly = Assembly.LoadFile(strAssemblyPath);
> // Instanciate the class and cast the type to the implemented interface
> uc = (IWebUseCase) assembly.CreateInstance("MyNamepace.CXmlFileList");
> // Cast the interface to the base class
> m_uc = (CWebUseCase)uc;
>
> // Call the test function
> m_uc.testFunction();
>
>
>
> Why doesn't the member variable take any values? Does it have anything
> todo with the dynamic creation?
>
> Please help me, this "feature" affects an otherwise quit good design of
> our application.
>
> Thanks!/Peter
>
>

 
Reply With Quote
 
=?Utf-8?B?UmFrZXNoIFJhamFu?=
Guest
Posts: n/a
 
      14th Feb 2005
Hi Fett,

Sorry...this post was meant for the "getting data..." message

- Rakesh Rajan

"Rakesh Rajan" wrote:

> Hi Fett,
>
> I would say the best method to extract strings from strings would be by
> using Regular Expressions.
>
> Since, in this case you need the value in between the quotes, you could use
> the :q construct.
>
> HTH,
> Rakesh Rajan
>
> "Fett" wrote:
>
> > Problem: My member variables in the child class are always null. I
> > don't know why this happens!
> >
> > I have a base class for handling a user flow in my web, CWebUseCase,
> > the class is declared like: public class CWebUseCase {...};
> >
> > This class is inherited into several specific flows like this one
> > CXmlFileList, which I will use to present a simple list to the user.
> >
> > //CXmlFileList declaration:
> > public class CXmlFileList : CWebUseCase, IWebUseCase
> > {
> > private string strTest = "Test string";
> >
> > public void testFunction()
> > {
> > // This Assert fails!!!!
> > Debug.Assert(strTest!=null);
> > strTest = "Hello";
> > // This Assert also fails ?????
> > Debug.Assert(strTest!=null);
> > }
> > }
> >
> > The class is instanciated dynamically and the assembly in which the
> > class resides is also loaded dynamically:
> >
> > /* Other class which calls the use cases */
> >
> > // Load the assembly
> > assembly = Assembly.LoadFile(strAssemblyPath);
> > // Instanciate the class and cast the type to the implemented interface
> > uc = (IWebUseCase) assembly.CreateInstance("MyNamepace.CXmlFileList");
> > // Cast the interface to the base class
> > m_uc = (CWebUseCase)uc;
> >
> > // Call the test function
> > m_uc.testFunction();
> >
> >
> >
> > Why doesn't the member variable take any values? Does it have anything
> > todo with the dynamic creation?
> >
> > Please help me, this "feature" affects an otherwise quit good design of
> > our application.
> >
> > Thanks!/Peter
> >
> >

 
Reply With Quote
 
Fett
Guest
Posts: n/a
 
      14th Feb 2005
hrrrmmm....It seems as it is only the debugger that displays "null" in
the "Tooltips" when the mouse pointer is over the variables...the
Assert statements doesn't fail after all. I still consider this a bug
but now I can get around it!

/Peter

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to hide base class member variable in derived class (w/oshadows)? Joe Duchtel Microsoft VB .NET 5 18th Jun 2009 07:37 PM
Base Class Method to use Shadow'ed member variable of Derived Class? Joe HM Microsoft VB .NET 2 4th Apr 2006 03:59 PM
share member variable of 1 class between 2 other classes Scott Starker Microsoft C# .NET 5 30th Jan 2006 06:53 AM
member variable alignment in __gc class? Bae,Hyun-jik Microsoft VC .NET 1 29th Apr 2005 07:39 PM
std::deque< class > member variable within class - A little help please Dan Trowbridge Microsoft VC .NET 7 8th Dec 2003 12:10 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:42 AM.