动态对象的创建和返回? [英] Dynamic object creation and return?

查看:60
本文介绍了动态对象的创建和返回?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我处于需要在方法[B] Examine [/B]中传递一些字符串的情况,该方法检查哪个类方法(来自不同的名称空间)适合传递该字符串进行处理.现在,在处理之后,每个方法都返回其自己的类型类的对象,该对象中存在该特定方法.我的[B] Examine [/B]方法需要返回将适应所有返回类类型的对象的类类型.也就是说,[B] Examine [/B]方法应该具有返回类型,该类型将根据其中的方法返回类型返回每种类型的对象.

I am in situation where I need to pass some string in a method [B]Examine[/B], that examines which class method (from different namespaces) is suitable to pass that string for processing. Now after processing, each method returns an object of its own type class, in which that particular method exists. My [B]Examine[/B] method needs to return such class type of object that will accomodate all returning classes types. That is, [B]Examine[/B] method should have a return type which will return every kind of class type object depending on methods return type in it.

推荐答案

我不知道我是否正确理解了你的问题.

I dont know whether i understood ur problem correctly.

我认为按照以下方式可以解决您的问题.

Any way i think following way can solve ur problem.

class Examine
{
public BaseType MethodExamine()
{
要//您要调用的某些标准
//Process1 obj.Processing1()或将返回Type1或Type 2的Process2 obj.Processing2(),在这里您可以为结果返回通用基类对象BaseType.
return BaseType obj
}

}


class Process1:BaseType
{
public process1 Processing1()
{{/>//返回Process1对象

}
}

类Process2:BaseType
{
/return Process2 obj
}
}

class Examine
{
     public BaseType MethodExamine()
    {
          //based on some criteria u want to call
         // Process1 obj.Processing1() or Process2 obj.Processing2() which will return Type1 or Type 2.
          // Here u can return the common base class object BaseType for both the result
         return BaseType obj
    }

}


class Process1 : BaseType
{
         public Process1 Processing1()
        {
                    // return Process1 object

         }
}

class Process2 : BaseType
{
          public Process2 processing2()
          {
                //return Process2 obj
           }
}


这篇关于动态对象的创建和返回?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆