关于.NET 特性,的运行时修改,请高手帮忙(200分,另外开贴给)

组合缺一 2005-01-24 10:25:00
我想要在程序运行的时候,修改方法或类的特性。请帮忙搞定一下。

真正搞定以后,马上另外开贴给分,这里的20分,送给帮忙顶的朋友
...全文
181 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
组合缺一 2005-01-27
  • 打赏
  • 举报
回复
不知道上面的兄弟,有没有编译过上面的代码.呵呵.我估计是不可以的.


不过,谢谢各位了....如果真不行...我只能用CODEDOM来运态编译它.呵呵.
Simonzy 2005-01-26
  • 打赏
  • 举报
回复
不知道下面的方法可以不,一个大胆的设想:

[WebServiceBindingAttribute(Name="Service1Soap", Namespace="http://service1.net/")]
public class Service1 :SoapHttpClientProtocol
{

private string mAttribute;

/// <remarks/>
public Service1(string ResponseNamespaceAttribute)
{
this.Url = "http://localhost/WebService1/Service1.asmx";
mAttribute = ResponseNamespaceAttribute;
}

/// <remarks/>
[SoapDocumentMethodAttribute("http://tempuri.org/HelloWorld",
RequestNamespace ="http://service1.net/",
ResponseNamespace =mAttribute,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Use =SoapBindingUse.Literal,
ParameterStyle =SoapParameterStyle.Wrapped)]
public string HelloWorld()
{
object[] results = this.Invoke("HelloWorld", new object[0]);
return ((string)(results[0]));
}
}
maxxxz 2005-01-25
  • 打赏
  • 举报
回复
你参看一下一些开源的开发工具。对DLL的动态加载,和即时编译。
你把你要更改的东西定义一个设计状态,在设计状态下修改的结果保存成一个源码文件,调用CSC或相应的编译程序来编译,利用插件的动态加载方式加载刚才编译得到的DLL就可以实现,注意保存现在的运行状态,同时把运行状态能传递给加载起来的这个新DLL。运行时设计的大概思想就是这样的。
webserv2 2005-01-25
  • 打赏
  • 举报
回复
应该不能把
sunnygx 2005-01-25
  • 打赏
  • 举报
回复
?
sutalon 2005-01-25
  • 打赏
  • 举报
回复
关注中

up
AllenTing 2005-01-25
  • 打赏
  • 举报
回复
不懂,帮顶
AhBian 2005-01-25
  • 打赏
  • 举报
回复
这个基本上很难,这么做就改变了类型的实际定义了。
一个类型一旦在内存中生成后好象是不能再改它的定义了。
即使动态生成一个新类型后,此类型也不能再修改其定义了,除非再动态一个新类型,但后者已不是前者了呀。

个人愚见,不足挂齿。
组合缺一 2005-01-25
  • 打赏
  • 举报
回复
没人能帮忙吗?自己先顶一下.
nga96 2005-01-24
  • 打赏
  • 举报
回复
能行么
web_gus 2005-01-24
  • 打赏
  • 举报
回复
同意, liduke(天下有雪) 这叫做反射?
组合缺一 2005-01-24
  • 打赏
  • 举报
回复
大哥,我要的是修改它。。。不是获取它。注意题义:)
liduke 2005-01-24
  • 打赏
  • 举报
回复
using System;
using System.Reflection;

// Define a custom attribute with one named parameter.
[AttributeUsage(AttributeTargets.All)]
public class MyAttribute : Attribute
{
private string myName;
public MyAttribute(string name)
{
myName = name;
}
public string Name
{
get
{
return myName;
}
}
}

// Define a class that has the custom attribute associated with one of its members.
public class MyClass1
{
[MyAttribute("This is an example attribute.")]
public void MyMethod(int i)
{
return;
}
}

public class MemberInfo_GetCustomAttributes
{
public static void Main()
{
try
{
// Get the type of MyClass1.
Type myType = typeof(MyClass1);
// Get the members associated with MyClass1.
MemberInfo[] myMembers = myType.GetMembers();

// Display the attributes for each of the members of MyClass1.
for(int i = 0; i < myMembers.Length; i++)
{
Object[] myAttributes = myMembers[i].GetCustomAttributes(true);
if(myAttributes.Length > 0)
{
Console.WriteLine("\nThe attributes for the member {0} are: \n", myMembers[i]);
for(int j = 0; j < myAttributes.Length; j++)
Console.WriteLine("The type of the attribute is {0}.", myAttributes[j]);
}
}
}
catch(Exception e)
{
Console.WriteLine("An exception occurred: {0}", e.Message);
}
}
}
组合缺一 2005-01-24
  • 打赏
  • 举报
回复
//
//我定义了如下这样的一个类,我想在运行的时候,修改像“SoapDocumentMethodAttribute”这样的特性里面的一些值,如“ResponseNamespace”的值。
//


[WebServiceBindingAttribute(Name="Service1Soap", Namespace="http://service1.net/")]
public class Service1 :SoapHttpClientProtocol
{

/// <remarks/>
public Service1()
{
this.Url = "http://localhost/WebService1/Service1.asmx";
}

/// <remarks/>
[SoapDocumentMethodAttribute("http://tempuri.org/HelloWorld",
RequestNamespace ="http://service1.net/",
ResponseNamespace ="http://tempuri.org/", Use =SoapBindingUse.Literal,
ParameterStyle =SoapParameterStyle.Wrapped)]
public string HelloWorld()
{
object[] results = this.Invoke("HelloWorld", new object[0]);
return ((string)(results[0]));
}
}
EATSAHARA 2005-01-24
  • 打赏
  • 举报
回复
说的具体些,举个例子最好

110,566

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧