标签: setvalue

System.Array的SetValue/GetValue方法是否是线程安全的?

我们在办公室进行了一些讨论,没有记录答案:

System.Array.SetValue线程安全的?

using System;
using System.Text;
using System.Threading;

namespace MyApp
{
    class Program
    {
        private static readonly object[] arr = new object[3];

        static void Main(string[] args)
        {
            string value1 = "hello";
            int value2 = 123;
            StringBuilder value3 = new StringBuilder();
            value3.Append("this"); 
            value3.Append(" is "); 
            value3.Append("from the StringBuilder");

            var states = new object[]
                             {
                                 new object[] {0, value1},
                                 new object[] {1, value2},
                                 new object[] {2, value3}
                             };

            ThreadPool.QueueUserWorkItem(MySetValue, states[0]);
            ThreadPool.QueueUserWorkItem(MySetValue, states[1]);
            ThreadPool.QueueUserWorkItem(MySetValue, states[2]);
            Thread.Sleep(0);

            Console.WriteLine("press enter to continue");
            Console.ReadLine(); …
Run Code Online (Sandbox Code Playgroud)

c# arrays thread-safety setvalue

5
推荐指数
1
解决办法
1397
查看次数

非静态方法需要PropertyInfo.SetValue中的目标

好的,所以我正在学习泛型,我正试图让这个东西运行,但它一直在说我同样的错误.这是代码:

public static T Test<T>(MyClass myClass) where T : MyClass2
{
    var result = default(T);
    var resultType = typeof(T);
    var fromClass = myClass.GetType();
    var toProperties = resultType.GetProperties();

    foreach (var propertyInfo in toProperties)
    {
        var fromProperty = fromClass.GetProperty(propertyInfo.Name);
        if (fromProperty != null)
            propertyInfo.SetValue(result, fromProperty, null );
    }

    return result;
}
Run Code Online (Sandbox Code Playgroud)

c# generics propertyinfo setvalue visual-studio

5
推荐指数
1
解决办法
1万
查看次数

如何使用javascript设置文本框的值

我试图从查询字符串中获取值并将该值分配给文本框.我能够从查询字符串中获取值,但无法将其分配给文本框.

document.getElementByName('Contact0Email').Value = email;
Run Code Online (Sandbox Code Playgroud)

尝试上面的代码,但似乎没有工作.虽然电子邮件的警报给出了正确的价值.

javascript textbox setvalue

5
推荐指数
1
解决办法
6万
查看次数

在 Selenium 中,sendKeys() 和 setValue() 方法到底有何不同?

我都用过

WebElement.sendKeys('') 
Run Code Online (Sandbox Code Playgroud)

WebElement.setValue('')
Run Code Online (Sandbox Code Playgroud)

为了将文本输入到字段中。绝大多数时候,它们的行为似乎都是一样的,但我发现了一些setValue()有效但sendKeys()无效的情况。

我在 Selenium 文档中所能找到的就是sendKeys() “更准确地模仿用户输入”setValue()。有谁知道幕后到底发生了什么?

selenium setattribute sendkeys setvalue selenium-webdriver

5
推荐指数
1
解决办法
4279
查看次数

使用java反射设置数组的值

我使用java反射创建了通用的json解析器,但是有一个我无法解决的错误.

方法(在这个问题的底部),接收我的自定义Model类的子类.我遍历字段并从json设置值.如果子类包含某些其他类的数组属性(同样是Model的子类),我创建了小递归来填充这些对象.

例如.

class UserModel extends Model
{
    @JsonResponseParam(Name="userName")
    public String Name;

    @JsonResponseParam(Name="friends")
    public FriendModel[] Friends;
}
Run Code Online (Sandbox Code Playgroud)

最后,UserModel应该填充好友.(JsonResponseParam是自定义anotation,Name值用作从json获取值的属性)

此方法的结果是IllegalArgumentException,并且它被抛出

field.set(t, values.toArray());
Run Code Online (Sandbox Code Playgroud)

这是方法:

protected <T extends Model> T getModel(T t)
{
    Field[] fields = t.getClass().getFields();

    for (Field field : fields) {
        Annotation an = field.getAnnotation(JsonResponseParam.class);

        if(an != null){
            try 
            {               
                if(field.getType() == boolean.class)                
                    field.setBoolean(t, t.getBool(((JsonResponseParam)an).Name()));

                if(field.getType() == String.class)
                    field.set(t,  t.getString(((JsonResponseParam)an).Name()));

                if(field.getType() == int.class)
                    field.setInt(t,  t.getInt(((JsonResponseParam)an).Name()));

                if(field.getType() == Date.class)
                    field.set(t,  t.getDate(((JsonResponseParam)an).Name()));

                if(field.getType().isArray()){

                    ArrayList<Model> modelArray = t.getModelArray(((JsonResponseParam)an).Name());
                    ArrayList<Model> values = new ArrayList<Model>();

                    for …
Run Code Online (Sandbox Code Playgroud)

java arrays reflection setvalue illegalargumentexception

4
推荐指数
1
解决办法
4521
查看次数

如何用oracle在循环中设置变量?

我有一个循环和一个变量v_rownum,我想为它设置值:

        FOR donvi_rows IN v_donvi
        LOOP
            DECLARE
               v_rownum number;
            SELECT r
            INTO v_rownum
            FROM
            (SELECT ROWNUM AS r, k.Id
            FROM don_vi k
            WHERE k.ParentId = 1 )
            WHERE Id = donvi_rows.Id;

        END LOOP;
Run Code Online (Sandbox Code Playgroud)

但它抛出异常:

PLS-00103: Encountered the symbol "SELECT" when expecting one of the following:

   begin function pragma procedure subtype type <an identifier>
   <a double-quoted delimited-identifier> current cursor delete
   exists prior
The symbol "begin" was substituted for "SELECT" to continue.
Run Code Online (Sandbox Code Playgroud)

我正在学习Oracle.我不太了解它.请帮我解决我的问题.

oracle loops for-loop setvalue

3
推荐指数
1
解决办法
1万
查看次数

使用SetValue添加事件处理程序

这段代码有效

TextBlock tbTest = new TextBlock();
tbTest.MouseRightButtonDown += new MouseButtonEventHandler(cc_CopyToClip);
Run Code Online (Sandbox Code Playgroud)

但我需要用SetValue做同样的事情
这不起作用 - 编译错误

FrameworkElementFactory textblock = new FrameworkElementFactory(typeof(TextBlock));
textblock.SetValue(TextBlock.MouseRightButtonDownEvent, += new MouseButtonEventHandler(cc_CopyToClip));
Run Code Online (Sandbox Code Playgroud)

如何通过SetValue分配事件处理程序?

回答

textblock.AddHandler(TextBlock.MouseRightButtonDownEvent, new MouseButtonEventHandler(cc_CopyToClip));
Run Code Online (Sandbox Code Playgroud)

.net wpf event-handling setvalue

3
推荐指数
1
解决办法
2745
查看次数

setValue(true)时gwt checkbox fire handler

我有一个复选框,上面有一个valueChangeHandler.当用户选中复选框时,它可以工作.

出于某种原因,我需要在我的代码中为此复选框设置一个值,如下所示:

checkbox.setValue(true),复选框在视觉上完美检查,但我的问题是它不会触发我的valueChangeHandler.

checkBox.setValue(true);

checkBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
   @Override
   public void onValueChange(ValueChangeEvent<Boolean> event) {
     ...
   }
});
Run Code Online (Sandbox Code Playgroud)

我设置一个值时是否有另一个处理程序可以触发?还是另一种方式来点这个?

谢谢

编辑:我也尝试了checkbox.setValue(true,true),但它不起作用.

已解决:setValue必须在注册处理程序之后.谢谢

checkbox gwt handler valuechangelistener setvalue

3
推荐指数
1
解决办法
3227
查看次数

在哪里可以找到 Swift 中 setValue 函数的定义键

在尝试通过Swift设置电子邮件主题和内容时,UIActivityViewController我使用了该函数。.setValue设置主题的键很好找,但我找不到设置内容的键。

activityViewController.setValue("Subject", forKey: "Subject")

//Key "Content" is not defined
activityViewController.setValue("Content", forKey: "Content"
Run Code Online (Sandbox Code Playgroud)

在这种情况下,我搜索了包含所有可能键的“列表”,但我找不到任何内容(即使在Apple的API文档中https://developer.apple.com/documentation/objectivec/nsobject/1415969-setvalue) 。所以我想问一下一般在哪里可以找到这样的列表,与这种特殊情况无关。

setvalue swift

3
推荐指数
1
解决办法
1370
查看次数

角度材料自动完成可防止 setValue 的反应性工作

编辑:用 Jojofoulk 的评论解决。

当使用 angular-material 的自动完成组件时,我试图使用setValue输入表单,但它的[matAutocomplete]属性阻止setValue在输入中显示。

检查反应式控件会发现该值是正确的,删除[matAutocomplete]它可以使其工作,但它只是没有显示出来。

<mat-list-item role="listitem" *ngFor="let skill of curObj.skills;index as ind">
  <div>
    <mat-form-field>
      <input type="text" placeholder="choose skill" aria-label="Number" matInput [formControl]="skill.control" [matAutocomplete]="auto">
      <mat-autocomplete #auto="matAutocomplete" [displayWith]="displayFn" (optionSelected)="optSel($event.option.value,skill)">
        <mat-option *ngFor="let option of skill.filteredOptions | async" [value]="option">
          {{option.name}}
        </mat-option>
      </mat-autocomplete>
    </mat-form-field>
  </div>
</mat-list-item>
Run Code Online (Sandbox Code Playgroud)
skill.control.setValue("some new value");
Run Code Online (Sandbox Code Playgroud)

autocomplete setvalue angular-material angular angular-reactive-forms

3
推荐指数
1
解决办法
1797
查看次数