更改属性上的ReadOnly属性不起作用(Change ReadOnly attribute on property doesn't work)

   IT问题网   2021-01-19 00:00:00

问 题

我试图改变readonly属性而不是反射。一切都运行良好的正常属性。但是当我使用自定义编辑器时,它并没有改变属性。我也试过在这个论坛上得到答案,但是有一天没有人看过这个话题,所以我再次问这里(和上次)



以下是我想要更改的属性:

 [uipatheditor.ofdparams(" 视频文件| * .wmv"" 选择背景视频")] 
[编辑( typeof (uipatheditor), typeof (uitypeeditor))]
[readonly( false )]
[描述(" 背景视频")]
[类别(" 外观")]
public string 视频
{
get { return _backgroundvideo; }
set {_ backgroundvideo = value ; }
}

[readonly( false )]
[描述(" 视频的音量")]
[类别(" 外观")]
public int 成交量
{
获取 {返回 _volume; }
set { if value lt; = 100 amp;amp; value gt; = 0 )_ volume = value ;}
}






这是代码我用来做到这一点:

 propertydescriptor属性; 
readonlyattribute属性;
fieldinfo isreadonly;

property = typedescriptor.getproperties( typeof (menuprop))[" 视频"];
attribute =(readonlyattribute)property.attributes [ typeof (readonlyattribute)];
isreadonly = attribute.gettype()。getfield(" isreadonly",bindingflags.nonpublic | bindingflags.instance);

isreadonly.setvalue(attribute,video);

property = typedescriptor.getproperties( typeof (menuprop))[" volume"];
attribute =(readonlyattribute)property.attributes [ typeof (readonlyattribute)];
isreadonly = attribute.gettype()。getfield(" isreadonly",bindingflags.nonpublic | bindingflags.instance);

isreadonly.setvalue(attribute,volume);






随着volume-property运行良好。但是在video属性上它没有效果......



我想改变属性[readonly(false)],因为它是我想要的属性网格编辑这些属性。我想根据选择的对象在可编辑和不可编辑之间切换。

解决方案

视频属性上定义了编辑器,该编辑器负责只读检查,尝试将其删除。

您好,

尝试在google搜索可能会找到它;



这段代码得到它形式谷歌可能会帮助你



------------------- -----

  class  testclass 
{
private bool ismypropertyreadonly;

public bool ismypropertyreadonly
{
get { return ismypropertyreadonly; }
set {ismypropertyreadonly = value ; }
}

private int myvar;

public int myproperty
{
get { return myvar; }

set
{
if (ismypropertyreadonly )
{
throw new system.exception(" myproperty属性是只读的。");
}
else
{
myvar = value ;
}
}
}
}

这不能为我编译:



 isreadonly.setvalue(属性,视频); 




这个编译,但给你不正确的行为:



 isreadonly.setvalue(属性,卷); 




试试这样:



公共课menuprop 
{
// ...班级内容...

public void changereadonlyto(bool readonly)
{
propertydescriptor property;
readonlyattribute属性;
fieldinfo isreadonly;

property = typedescriptor.getproperties(typeof(menuprop))["video"];
attribute =(readonlyattribute)property.attributes [typeof(readonlyattribute)];
isreadonly = attribute.gettype()。getfield("isreadonly",bindingflags.nonpublic | bindingflags.instance);

//在此设置属性值为true或false
isreadonly.setvalue(attribute,readonly);

property = typedescriptor.getproperties(typeof(menuprop))["volume"];
attribute =(readonlyattribute)property.attributes [typeof(readonlyattribute)];
isreadonly = attribute.gettype()。getfield("isreadonly",bindingflags.nonpublic | bindingflags.instance);

//在此设置属性值为true或false
isreadonly.setvalue(attribute,readonly);
}
}




还要确保 uipatheditor 尊重价值 readonlyattribute

标签:更改属性不起作用



分享:

  • 微信
  • QQ好友
  • QQ空间
  • 新浪微博


热门推荐

我如何分割我的表格(how do i split my form)

problem ok i want to split my form in half so on the left ...

将templatefield动态添加到gridview(adding templatefield dynamically to gridview)

problem give the tutorial to add template field, controls ...

在c#的帮助下导出pdf文件(Export pdf File with the help of c#)

problem how to convert more then one pdf file ...

计算中间日期并在gridview中显示它(calculate inbetween date and show it in gridview)

problem hello friends, by using date time pi ...

为它的学生项目(Project for an it student)

problem hi, i m an bsc it student ,as many of you will kn ...

单击更改图标通知(Change Icon Notify on Click)

problem is possible changer notifyicon1 on click the prog ...

如果用户已经登录,则在同一浏览器中重定向到主页asp .net c#(Redirect to Home page if user already logged in, in same browser asp .net c#)

problem i want to make application that if user in logged ...

需要帮助来使用MySqlTransaction(Need help in using MySqlTransaction)

problem hi all i would like to use mysqltransaction in my ...

如何使用VBscript导航Windows注册表树(How to navigate Windows registry tree with VBscript)

problem does anyone know how to go about navigating the w ...

silverlight内存泄漏(silverlight memory leak)

problem hi, i was creating a dependencyproperty changed w ...

如何在json中获取单个元素(How to get single element in json)

problem in wcf service i am getting json response in that ...

双击文件打开程序,如何在c#中实现(double click on file opens program, how to implement in c#)

problem usually when a program in installed, you can clic ...

如何在我添加的现有数据表中添加新列,但它是bofore行的结尾(how add new column in existing datatable i added but its is come end of the bofore rows)

problem my datatable contans two columns id value ----- ...

如何在c#.net中的现有页面中打开新网址(How to open new url in existing page in c#.net)

problem hi to all, this is mdsiddiqali.i added new page n ...

DeleteObject方法不会删除任何内容 - 请帮忙。(DeleteObject method doesn't delete anything - please help.)

problem hello. i am trying to create method that will del ...

项目模板类型在C#中使用?(PROJECT TEMPLATE TYPE TO USE IN C#)

problem edit; okay i am creating a dock for programs to r ...

如何在我添加的现有数据表中添加新列,但它是bofore行的结尾(how add new column in existing datatable i added but its is come end of the bofore rows)

problem my datatable contans two columns ; id value ---- ...

在c#和asp.net中使用LinkedIn API?(Working with LinkedIn APIs in c# and asp.net )

problem hey i was trying to design an asp.net based webs ...

设计模式的案例研究(Case Studies for Design Pattern)

problem hi everyone, though i found "design patterns exp ...

返回所有组件(Retur all components)

problem dears, i need a method to return all named contro ...