change object reference

  • Thread starter Thread starter felipecsl
  • Start date Start date
F

felipecsl

Does anyone know if there is a way to change the way the reference that
is returned from an object? I need to return an object member when
someone tries to retrieve "this".
e.g.:

//Suppose we have the object FooBar...

class Foobar{
private string m_someStuff;
private FooBar m_anotherInstance;
 
Dnia 23-03-2006 o 14:48:46 felipecsl said:
Does anyone know if there is a way to change the way the reference that
is returned from an object? I need to return an object member when
someone tries to retrieve "this".
e.g.:

//Suppose we have the object FooBar...

class Foobar{
private string m_someStuff;
private FooBar m_anotherInstance;
.
.
.
}

//and we want to pass it as a parameter to another function:

FooBar fb = new FooBar();
MyFunc(fb);

//what I want, is fb.m_anotherInstance to be passed as parameter to
MyFunc(). is this possible?
[PD] What you want to do is a kind of code obfuscation :) But if you
really want you can do something like this (you will have to use the a
second type):
class a
{
b b;

public static implicit operator b(a a)
{
return a.b;
}
}

class b
{
...
}

This way when you will call MyFunc(b b) with param a you will effectively
pass a.b as a param.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top