473,385 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

problems typecast,find by function/member name and getting "managed reference"

HI!
I wrting some program part of it is XML config parser which contains
some commands(for flexibility of engenie).
how do i more simple(if it possible not via System.Reflection or
System.CodeDom.CodeCastExpression)
__problem typecast #1
Desc:i do needed checks but data/commands in XML is dynamic and i don't
wanna fix C# code again and again...
Sample:foreach (object some in somearray)
(some.GetType())some.someaction();

__problem #2 function/member exist and "managed reference"
Desc: how i said there is some name of function/member in XML data
which refers to some function/member in my public C# code i need to
find it and get reference to operate.
Sample:
foreach (String name in memberarray)
if (Core.Public.isMember[name]==True)
foreach (String action in memberarray[name].actionsarray)
if (Core.Public.Member[name].isMember[action]==True)
Core.Public.Member[name].action[action.param];

Sep 22 '06 #1
5 2277
SunnyDrake <su********@ua.fmwrote:
I wrting some program part of it is XML config parser which contains
some commands(for flexibility of engenie).
how do i more simple(if it possible not via System.Reflection or
System.CodeDom.CodeCastExpression)
__problem typecast #1
Desc:i do needed checks but data/commands in XML is dynamic and i don't
wanna fix C# code again and again...
Sample:foreach (object some in somearray)
(some.GetType())some.someaction();
The normal way to overcome this is to use an interface if possible.
Otherwise, you'll need to use reflection to get the appropriate
MethodInfo and invoke it.
__problem #2 function/member exist and "managed reference"
Desc: how i said there is some name of function/member in XML data
which refers to some function/member in my public C# code i need to
find it and get reference to operate.
Sample:
foreach (String name in memberarray)
if (Core.Public.isMember[name]==True)
foreach (String action in memberarray[name].actionsarray)
if (Core.Public.Member[name].isMember[action]==True)
Core.Public.Member[name].action[action.param];
I *think* you're basically asking for reflection here, but I'm not
sure. Here's a sample program if you are:

using System;
using System.Reflection;

class Test
{
static void Main()
{
Test t = new Test();
CallMethod (typeof(Test), t, "FirstMethod");
CallMethod (typeof(Test), t, "SecondMethod");
}

static void CallMethod (Type type, object target,
string methodName)
{
MethodInfo method = type.GetMethod(methodName);
// The "null" here is because we're assuming
// the method has no parameters
method.Invoke (target, null);
}

public void FirstMethod()
{
Console.WriteLine ("I'm in FirstMethod");
}

public void SecondMethod()
{
Console.WriteLine ("I'm in SecondMethod");
}
}

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Sep 23 '06 #2
Jon написав:
The normal way to overcome this is to use an interface if possible.
and then use Runtime.InteropServices._Type.GetInterface Method (String)
?
it's Net 2.0 :( and i need to add interface for each class and then add
functions to get variables :(. And interface will be a weak side of
design.
Otherwise, you'll need to use reflection to get the appropriate
MethodInfo and invoke it.
I *think* you're basically asking for reflection here, but I'm not
sure. Here's a sample program if you are:
static void CallMethod (Type type, object target,
string methodName)
{
MethodInfo method = type.GetMethod(methodName);
// The "null" here is because we're assuming
// the method has no parameters
method.Invoke (target, null);
}
thanks it's was a great help!.
now i only need find a way to get object by its name in string..
and still i'm not found a good solution to dynamicaly
typecast(unboxing) any *unknown type* to object at runtime.

Sep 26 '06 #3
SunnyDrake <su********@ua.fmwrote:
Jon ???????:
The normal way to overcome this is to use an interface if possible.
and then use Runtime.InteropServices._Type.GetInterface Method (String)
?
No, and then call methods in the interface.
it's Net 2.0 :( and i need to add interface for each class and then add
functions to get variables :(. And interface will be a weak side of
design.
I guess it depends on the exact situation - but I would *generally*
rather see a "strongly called" interface member than futz around with
reflection. It does depend though.
Otherwise, you'll need to use reflection to get the appropriate
MethodInfo and invoke it.
I *think* you're basically asking for reflection here, but I'm not
sure. Here's a sample program if you are:
static void CallMethod (Type type, object target,
string methodName)
{
MethodInfo method = type.GetMethod(methodName);
// The "null" here is because we're assuming
// the method has no parameters
method.Invoke (target, null);
}
thanks it's was a great help!.
now i only need find a way to get object by its name in string..
Objects don't have names. What exactly do you mean?
and still i'm not found a good solution to dynamicaly
typecast(unboxing) any *unknown type* to object at runtime.
Hang on - casting and unboxing are very different things. Casting at
runtime doesn't make sense because the point of casting is to give the
*compiler* more information, which clearly isn't relevant at runtime.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Sep 26 '06 #4
Jon написав:
The normal way to overcome this is to use an interface if possible.
and then use Runtime.InteropServices._Type.GetInterface Method (String)
No, and then call methods in the interface.
I guess it depends on the exact situation - but I would *generally*
rather see a "strongly called" interface member than futz around with
reflection. It does depend though.
let me explain .. this *program and it's parts* may be used be used be
different peope:
coders which work's on some modules(not core),artists who add new gfx
and add info about it in XML resource list file and designers who via
tool or directly in XML will place objects/ai rules(logic)/actions
etc... so one of core script side task is to load XML try to
find requested command(which name/type/state is unknown , only string
name(or hash number(functions may be created/changed by modules in
runtime or even via DCOM)) find appropriate type/object,initalize it in
C# type and perform actions on it described in XML(partialy solved thnx
to you).So as i thnk reflection and dynamic types is a good way, but as
a former C++ coder i'v hardly hitted in typecast of C#, in this way C#
to bee more *plastic* on base synatx have a long way to go....well you
can call me *stuped C# green*...but i wanna make long look on C# in my
coding.
thanks it's was a great help!.
now i only need find a way to get object by its name in string..
Objects don't have names. What exactly do you mean?
Object's don't have but (pre)boxed data have type and possibly can
still have intalization variable name, other part of it after
initalization putted in some ArrayList as objects so (in my cases it's
classes) they have inside variable name so i need
to get collection of initalized objects of *XML suppiled type name*
and/or get collection of initalized objects which in pre-boxed type
have public string name; of *XML suppiled value* in some domain
assembly.
and still i'm not found a good solution to dynamicaly
typecast(unboxing) any *unknown type* to object at runtime.
Hang on - casting and unboxing are very different things. Casting at
runtime doesn't make sense because the point of casting is to give the
*compiler* more information, which clearly isn't relevant at runtime.
?give struct of data,rule to access data parts in memory at runtime at
least this was so in C++!
this as i think was one of ideas to keep original GetType for objects
and for conversions
too... this is not relevant if code is unmodified(in compiled form)at
runtime,and make sense if same data at runtime maybe used in different
means(types,forms,purpose) without modification or creating new data.

Sep 26 '06 #5
Jon написав:
The normal way to overcome this is to use an interface if possible.
and then use Runtime.InteropServices._Type.GetInterface Method (String)
No, and then call methods in the interface.
I guess it depends on the exact situation - but I would *generally*
rather see a "strongly called" interface member than futz around with
reflection. It does depend though.
let me explain .. this *program and it's parts* may be used by
different peope:
coders which work's on some modules(not core),artists who add new gfx
and add info about it in XML resource list file and designers who via
tool or directly in XML will place objects/ai rules(logic)/actions
etc... so one of core script side task:
1) is to load XML
2) try to find requested command(which type/state is unknown , only
name in string(or hash number,btw. functions may be created/changed by
modules at
runtime or even via DCOM))
3) find appropriate type/object,initalize it in
C# type
4) perform actions on it,which described in XML(partialy solved thnx
to you).
So as i thnk reflection and dynamic types is a good way, but as
a former C++ coder i'v hardly hitted in typecast of C#, in this way C#
to be more *plastic* on base synatx have a long way to go....well you
can call me *stuped C# green*...but i wanna make long look on C# in my
coding(i'm buyed by some ideas and toolz :).
thanks it's was a great help!.
now i only need find a way to get object by its name in string..
Objects don't have names. What exactly do you mean?
Object's don't have,some of (pre)boxed data have type and possibly can
still have intalization variable name, other part of objects directly
after
initalization(in some type) putted in some ArrayList as objects.
Objects in my cases in original type is user classes, mostly have
inside (public string name;)
so i need to get collection of initalized objects of .GetType( *XML
suppiled type name*
) and/or get collection of initalized objects which in pre-boxed type
have public string name; == *XML suppiled value* in some domain
assembly.
and still i'm not found a good solution to dynamicaly
typecast(unboxing) any *unknown type* to object at runtime.
Hang on - casting and unboxing are very different things. Casting at
runtime doesn't make sense because the point of casting is to give the
*compiler* more information, which clearly isn't relevant at runtime.
?give struct of data,rule to access data parts in memory at runtime,at
least this was so in C++!
this as i think was one of ideas to keep original GetType for objects
and for conversions
too...
Casting is not relevant if some data(and code data) is unmodified(in
compiled form)at
runtime(to get new type of data you need to make a copy of current with
new type) ,and make sense if same data at runtime maybe used in
different
means(types,forms,purpose) without modification or creating new data.

Sep 26 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Pablo J Royo | last post by:
Hello: i have a function that reads a file as an argument and returns a reference to an object that contains some information obtained from the file: FData &ReadFile(string FilePath); But ,...
1
by: Junior | last post by:
I keep receiving this "The type or namespace name 'CASsEventHandler' could not be found (are you missing a using directive or an assembly reference?)" message in two particular lines, and I've...
3
by: Gary McGill | last post by:
I have a C# solution with a dozen or so projects. There are references between the projects, and these were all added as "Project" references. Everything's been working fine for months, but...
1
by: Robert A Riedel | last post by:
I am completely baffled when the following managed exception is thrown: "Object reference not set to an instance of an object" from a nested subroutine when referencing a variable allocated on the...
5
by: Trevor Andrew | last post by:
Hi There I am having some difficulty referencing Web Services. I am using Visual Studio .NET 2003, with the .NET Framework 1.1, and trying to write a VB.NET Windows Application that consumes an...
3
by: Samuel R. Neff | last post by:
I just started having a problem with the Add Reference dialog not displaying in VS.NET 2003. Whenever I click Add Reference the dialog doesn't display. I've tried several different projects and...
0
by: Kaimar Seljame | last post by:
Hi, I have to create a web service client which uses SOAP encoding but does not use "multi-reference" values (see http://www.w3.org/TR/2000/NOTE-SOAP-20000508/#_Toc478383513 item 10). If I...
5
by: Matthew.DelVecchio | last post by:
hello, i am working w/ a partner company's webservice, which they wrote in java. using a provided webservice.wsdl file, i am able to compile it into a proxy class, webservice.dll. i can add...
5
by: Mike Logan | last post by:
I used WSDL.exe to generate a client side web proxy for a web service, called the web service, got the results but an array returned by the web service is not in the results. However if I use...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.