dynamic

Change for loop index variable inside the loop

风流意气都作罢 提交于 2019-12-10 14:22:20
问题 I need to change my loop variable inside the iteration as I have to access array elements in the loop which is changing w.r.t size inside the loop. Here is my code snippet: que=[]; que=[2,3,4]; global len; len=size(que,2) x=4; for i=1:len if x<=10 que(x)= 5; len=size(que,2) x=x+1; end end que Array should print like: 2 3 4 5 5 5 5 5 5 5 But it is printed like this: 2 3 4 5 5 5 In Visual C++ the array is calculated correctly and whole array of 10 elements is printed, which increases at run

Removing a fields from a dynamic ModelForm

牧云@^-^@ 提交于 2019-12-10 14:10:39
问题 In a ModelForm, i have to test user permissions to let them filling the right fields : It is defined like this: class TitleForm(ModelForm): def __init__(self, user, *args, **kwargs): super(TitleForm,self).__init__(*args, **kwargs) choices = ['','----------------'] # company if user.has_perm("myapp.perm_company"): self.fields['company'] = forms.ModelChoiceField(widget=forms.HiddenInput(), queryset=Company.objects.all(), required=False) choices.append(1,'Company') # association if user.has_perm

Why do I get a RuntimeBinderException using json.net with dynamic when calling a method

删除回忆录丶 提交于 2019-12-10 14:05:34
问题 Why is it that when I use dynamic with json.net I get a runtime binding exception then calling a method without casting but I can do assignments not problem private static void Main() { dynamic json = JObject.Parse("{\"Test\":23}"); var t = json.Test; int a = t; //Success Prop = t; //Success Func(t); //RuntimeBinderException } private static void Func(int i){} private static int Prop { get; set; } When I cast it to the correct type there are no errors but I would prefer to not have to do that

how to create a dynamic class at runtime in Java

会有一股神秘感。 提交于 2019-12-10 14:01:18
问题 Is it possible to create a new Java file from an existing Java file after changing some of its attributes at runtime? Suppose I have a java file public class Student { private int rollNo; private String name; // getters and setters // constructor } Is it possible to create something like this, provided that rollNo is a key element for the table? public class Student { private StudentKey key; private String name; //getters and setters //constructor } public class StudentKey { private int

Why is the C# compiler claiming 'use of an unassigned variable' prior to 'yield return' and dynamic?

微笑、不失礼 提交于 2019-12-10 13:56:55
问题 The compiler complains that resultingThing in the code below is being used before being assigned to. private IEnumerable<IThing> FindThings(dynamic spec) { if (spec == null) yield break; IThing resultingThing; if (spec.Something > 0 && dictionary.TryGetValue(spec.Something, out resultingThing)) yield return resultingThing; else // ... } Why does it claim this? I have tried a different version of the method in which there are no yield usages (e.g. just return IEnumerable<IThing> ) but with the

Oracle 11g “Bind variable does not exist”

扶醉桌前 提交于 2019-12-10 13:56:32
问题 I am getting an "ORA01006 Bind variable does not exist at line 15 "error in the following code: DECLARE v_search_string varchar2(4000) := 'OK'; v_query_str VARCHAR2(4000); match_count integer; BEGIN FOR t IN (SELECT owner, table_name, column_name FROM all_tab_columns WHERE data_type in ('CHAR', 'VARCHAR2', 'NCHAR', 'NVARCHAR2') And TABLE_NAME = 'T1' And OWNER = 'O1') LOOP Begin v_query_str := 'SELECT COUNT(*) FROM '|| t.table_name || ' WHERE ' || t.column_name || ' Like ''' || '%:1%' || '''';

How to write String.Contains in Dynamic Linq

Deadly 提交于 2019-12-10 13:47:47
问题 I'm trying to write a dynamic linq query like: var q = obj.Where("message.Contains('hello')"); I know it works for var q = obj.Where(o => o.message.Contains('hello')); but i'm looking for dynamic linq solution Thanks. 回答1: Found my answer now. var q = obj.Where("message.Contains(@0)", "hello"); 回答2: I know this isn't what you are looking for, but just as a point to consider: Depending on how many various kinds of operation you expect to perform, I would create a switch statement to handle

Can't understand the Exception when using dynamic with generic collection in .net4

試著忘記壹切 提交于 2019-12-10 13:45:38
问题 check the code below please: static void Main(string[] args) { IList<dynamic> items = new List<dynamic>(); items.Add(3); items.Add("solid"); dynamic i = new ExpandoObject(); items.Add(i); //System.Collections.Generic.IList<object>' does not contain a definition for 'Add' Console.WriteLine(); } is this a bug in "dynamic" mechanism? 回答1: Looks like a bug (or is it a feature request?): https://connect.microsoft.com/VisualStudio/feedback/details/534288/ilist-dynamic-cannot-call-a-method-add

Is it possible to dynamically create form without having *.dfm and *.pas files?

穿精又带淫゛_ 提交于 2019-12-10 13:39:18
问题 is it possible to create and show TForm without having source files for it ? I want to create my forms at runtime and having the empty *.dfm and *.pas files seems to me useless. Thank you 回答1: Do you mean like this? procedure TForm1.Button1Click(Sender: TObject); var Form: TForm; Lbl: TLabel; Btn: TButton; begin Form := TForm.Create(nil); try Form.BorderStyle := bsDialog; Form.Caption := 'My Dynamic Form!'; Form.Position := poScreenCenter; Form.ClientWidth := 400; Form.ClientHeight := 200;

Apply attribute to return value - In F#

为君一笑 提交于 2019-12-10 12:57:53
问题 in C# it is possible to apply an attribute to the return of a method: [return: DynamicAttribute] public object Xyz() { return new ExpandoObject(); } Is this possible in F#? Background : I would like a method of a library written in F# which will be consumed in a language like C# to return "dynamic" from a method. If I look into a similarly defined method compiled from C# it seems like the return type is object and the DynamicAttribute is applied to the return value of the object. 回答1: Sure,