w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
c# - Is there any way to clone array with value type, without create new reference type?
Yes, you can use indexer (which is zero based) a[2] = 5; If you want to change whole array, then assign a new reference for it, like int[] a = new[] {1, 2, 10}; a = new[] {1,2,5}; Your original array will lose all the references to it and become subject to GC. The second line assigns a a reference to the new array.

Categories : C#

When to use a deep clone of an object reference? or How often?
The main purpose in object-oriented programming must be that an object gurantees that it is in a leagal state at any time. Thus when you return an object's reference you should think about: Is the returned object immutable? Does the current object that returns the reference (main object) has values that depend on the returned object? (derived or cached values) You can react to the answers of these questions in the following ways: The returned reference is an immutable object (String, BigDecimal, etc.) no action required The returned reference is a muttable object (array, Date, etc.), but the main object has NO derived values (e.g. only decorates it) no action required The returned reference is a muttable object (array, Date, etc.) and the main object has derived values Mak

Categories : C#

Why can't I type Clone() properly?
Part of the issue here is polymorphism. Creating a generic ICloneable<T> is trivial, but you get into problems when you have: Foo : ICloneable<Foo> Bar : Foo because now Bar needs to implement both ICloneable<Foo> and ICloneable<Bar>. Fortunately, you can use method hiding and polymorphism together to make this just about work, i.e. interface ICloneable<T> { T Clone(); } class Foo : ICloneable<Foo> { protected virtual object Clone() { /*...*/ } public Foo Clone() { return (Foo) Clone(); } } class Bar : Foo, ICloneable<Bar> { protected override object Clone() { /*...*/ } public new Bar Clone() { return (Bar) Clone(); } } However! As you can see, this quickly gets painful to maintain. Perhaps a better option is to use the in

Categories : C#

Javascript Clone throw Type Error
When your object is some other type of object besides a plain object (like a Date object), you aren't creating a cloned Date object, you're creating a plain object. Further when you copy properties to the cloned object, you are only copying properties directly on the object, not properties in the prototype chain as that is what Object.getOwnpPropertyNames() returns. Thus your cloned Date object has none of the Date methods. Per RobG's suggestion, add this first line right before the return: result.__proto__ = obj.__proto__; return result ;

Categories : Javascript

How to make Generic Type as out type if it is reference Type?
If you have an error with the return type of IEnumerable<IGrouping<string, MyClass>> in a generic class that has been declared using <T>, then I'm guessing that your return type should actually be IEnumerable<IGrouping<string, T>>... of course, without seeing your code, this can only be a guess.

Categories : C#

invalid initialization of non-const reference of type ‘std::vector&’ from an rvalue of type
Your return type of print is not a reference, so, you return a copy of a3. It's temporary and you can't bind it to a reference. You could fix this with: vector<double>& print(vector<double>& a3){ // ^ // note the ampersand here

Categories : C++

Why standard java classes's clone() return Object instead of actual type
One reason is backwards compatibility. The signature of the Object.clone() method was specified way back in Java 1.0, when there wasn't support for generics. If they changed this fundamental method as you suggested, it could break thousands of legacy programs where the clone() method might not return an object with the same type as this. See also: Would using covariant return type in clone really break compatibility?

Categories : Java

Does d3js data binding clone the data being bound or store a reference to it?
Yes you can expect them to update. With out more code it is hard to guess but you can use something like this: var els = d3.select("body").selectAll("div");//Cache elements els.style('background','blue')//Change background to blue; els.style('background','red')//Change background to red; els.style("width", function(d) { return d *1/3 + "px"; //Divide elements width by 3 }); DEMO

Categories : Javascript

Variable store function as primitive type or reference type?
The value of f2 is, like f1, a reference to the same function. You can use the fact that functions are objects to prove it : var f1 = function(){} var f2 = f1; f1.a = 3; console.log(f2.a); // logs 3 But as you can't change a function core, there is little practical use in knowing this, apart the fact you don't use much memory if you duplicate a function reference.

Categories : Javascript

How to reference an already existing type variable in a haskell type spec?
Check http://www.haskell.org/haskellwiki/Scoped_type_variables From the link: Scoped Type Variables are an extension to Haskell's type system that allow free type variables to be re-used in the scope of a function.

Categories : Haskell

How to get a reference to an object via one of it's own properties?
Sorry, but its impossible. You can't get Car instance from String (its Brand name) value. car.Brand is not a property (say, PropertyInfo) in your code, it's just a value of String. Just imagine: // Test(car.Brand); String brandName = car.Brand; // <- Just a string, nothing special Test(brandName); Even when we use Reflection, we can't get Object instance, the only thing we can get is class (Type): PropertyInfo pi = typeof(Car).GetProperty("Brand"); ... Type tp = pi.ReflectedType; // <- Car; Type only, not instance Instead, you can pass Car instance and get all properties you want: public static void Main(string[] args) { Car car = new Car(); car.Brand = "Porsche"; car.Color = "Yellow"; Test(car); } public static void Test(Car value) { Conso

Categories : C#

Reference to object properties
Your solution is perfectly fine, as long as the contents in ExportColumnData are correct. If these are computed dynamically at runtime, you're fine. Otherwise, or alternatively, you can do the following: use Type.GetProperties to get a list of PropertyInfo objects. You can then use these instead of a mere String to extract property values in your loop: Dim o As Object = item.PropertyInfo.GetValue(p, Nothing)

Categories : Vb.Net

Are data types in php categorized into reference type and value type? Like C#
Yes, essentialy objects are stated to be reference type while everything else is value type. However, the former is not completely true and might be better described as 'pointer type'. To give an example: $a = new stdClass(); # <-- Obj1 $a->foo = 'foo'; $b = $a; $b->foo = 'bar'; echo $b->foo; # outputs 'bar' echo $a->foo; # outputs 'bar' As you can see, it would seem that $a is being passed by reference; it is, however, actually a copy of the identifier of that object that is being passed. As such, updating a property will affect the original, but updating the value of the variable will not. This contrast with a true PHP reference as follows: $c =& $a; $c = new stdClass(); # <-- Obj2 $c->foo = 'foo'; echo $b->foo; # outputs 'bar' echo $a->foo; # outputs

Categories : C#

Why does capGetDriverDescription accept a buffer as a value type instead of a reference type?
I'll start by saying I don't know much about this subject (marshaling data can be a deep subject), but I think Default Marshaling for Strings (MSDN) may help you. Scroll down to the part that says Fixed-Length String Buffers. According to this, when a string is marshaled to the API, even if passed byRef, it can't be modified by the callee. I haven't tested, but according to the MSDN example, to get a value back from your function, the definition would become Declare Function capGetDriverDescriptionA Lib "avicap32.dll" (ByVal wDriver As Short, _ ByVal lpszName As StringBuilder, ByVal cbName As Integer, ByVal lpszVer As String, _ ByVal cbVer As Integer) As Boolean Changing lpszName from String to StringBuilder. Apparently StringBuilder will work as a buffer to get the string back from th

Categories : Vb.Net

Is there a way to reference a class's properties by index rather than by name?
You can use reflection to iterate over properties, this will not give you an indexed access but I think the properties are returned in a deterministic order. Type type = obj.GetType(); BindingFlags flags = BindingFlags.Public | BindingFlags.Instance; PropertyInfo[] properties = type.GetProperties(flags); foreach (PropertyInfo property in properties) { Console.WriteLine("Name: " + property.Name + ", Value: " + property.GetValue(obj, null)); }

Categories : C#

Using Json.Net ContractResolver and inner reference properties
Eventually I found out that the ContractResolver is called for each referenced object within my model as well. Which is nice in part, however somewhat problematic, since it only passes the type of the object being parsed to JSON and no information about the depth or where it has found the object. public class ConverterContractResolver : DefaultContractResolver { protected override IList<JsonProperty> CreateProperties(Type type, Newtonsoft.Json.MemberSerialization memberSerialization) { //filter the properties and return back the final list } } By adding a counter to the number of times the CreateProperties is being called, I managed to recognize which call is for the main model and which subsequent calls are for referenced objects. This

Categories : C#

Clone dynamically added html content with JQuery clone() method
First of all, you should use $('a#modify1'), since modify1 is ID and not class. You are running showModal, without checking if load method completed, and so it couldnt find any <form> to clone. Try putting showModal as a callback to the load function: $('a#modify').click(function() { $('#formContainer).load('getuserupdateform.php?user_id=X', function(){ return showModal($(#formContainer)); }); }); This way, showModal will run ONLY when the load request has completed. Detailed explanation on how callback works : http://api.jquery.com/load/

Categories : Jquery

Project reference properties - Version number
You have 2 versions of strongly named assembly. It is by design behavior for other projects that where compiled against one version of such assembly to fail to load assembly with different version. The reasoning is that version change denotes API change. Otherwise it would be in-place update with the same version - so older code may not be able to function correctly with newer DLL. Options: If there is no API changes - don't change version of assembly. It means you may deprecate methods, but no add/remove of methods/classes or change in behavior. If you control all projects depending on that assembly - rebuild all with new reference and stop supporting older version (if possible). Provide publisher policy in settings to redirect request for older version to new one. This assumes your ne

Categories : C#

jQuery clone a div and increment the ID but limit the clone to 3 times
Just add a check to see if you already reached your third element with id=2 $('#btn').click(function(){ if(current_id < 2) nextElement($('#Outer_00')); }); Demo fiddle

Categories : Jquery

How to clone/copy a sql record with CakePhp, and then grab the ID of the clone?
you can also get the last inserted record id in these ways. $cloneId = $this->Contract->id; or $cloneId = $this->Contract->getLastInsertID(); or $contract = $this->Contract->save($contract); $cloneId = $contract['Contract']['id']

Categories : PHP

Git: Remote Branch Availability on Clone of Clone
You and #2 will have the Gatekeeper repo as a remote, and fetch from that. When you do you will only get the state of the local branches of Gatekeeper, at their current respective commit. So, Gatekeeper would need to git pull relevant branches to get up to date changes from the Developer repo. Then you can pull from Gatekeeper to get the latest changes. It seems inconvenient to me, since it depends on the Gatekeeper regularly pulling so that you can pull. Also, what is Gatekeeper supposed to do if there is a change he does not like? git revert it? A possibly better alternative to your workflow, would be the Integration-Manager Workflow. The Gatekeeper could be the integration manager, and you, #2 and Developer could be contributors. What is best depends a lot on the role of Gatekeeper

Categories : GIT

is null in c# value type or reference type
Neither. null is the default value for reference types, but it does not have a type itself. Nullable value types are actually implemented as value types themselves - there are just compiler and library tricks to make them behave as expected when compared to null.

Categories : C#

Is object a reference type or value type?
It is a reference type Doing an example with string isn't very illuminating, because string is also a reference type (as is SampleClass, obviously); your example contains zero "boxing". if object is reference type then why obj2 value is still "OldString" Why wouldn't it be? When you create a new string, that doesn't change old references to point at the new string. Consider:  object obj1 = "OldString"; // create a new string; assign obj1 the reference to that new string "OldString" object obj2 = obj1; // copy the reference from obj1 and assign into obj2; obj2 now refers to // the same string instance obj1 = "NewString"; // create a new string and assign that new reference to obj1; note we haven't // changed obj2 - that still points to the original string, "OldString"

Categories : C#

How to maintain collection type across a web service (using Web Reference not Service Reference)
AFAIK you cannot. Web reference doesn't allow List. However if you change that to service reference you can do that by going to properties and specifying the collection type you want to use.

Categories : C#

g++ gives error : invalid initialization of reference of type ‘char&’ from expression of type ‘unsigned char’
Why isn't it possible to initialize 'char &' with a variable of type 'unsigned char' while it is possible to initialize 'const char &' with it? Because the latter creates a temporary to bind to the const reference when the unsigned char is converted to a char, something you can't do with non-const references. char, signed char, and unsigned char are three distinct types, as explained in C++11 § 3.9.1: Plain char, signed char, and unsigned char are three distinct types

Categories : C++

Does reading a volatile reference to an object guarantee atomic reads of the latest values of its properties?
In short no. The volatile keyword only applies to the foo reference, not to the fields of the underlying object. So you would need to mark bar as volatile too to achieve the result your describe.

Categories : Java

Clone dataset > Change column type > Populate dataset
assuming you have only one table in the data set, you can do something like this. int ColumnIndex = 0; //Column index of your data you want to copy for (int i = 0; i < dataset_original.Tables[0].Rows.Count; i++) { dataset_cloned.Tables[0].Rows[i].SetField(ColumnIndex, dataset_original.Tables[0].Rows[ColumnIndex].ItemArray[0].ToString()); } in the same for loop you can copy remaining columns data

Categories : Asp Net

initialization of non-const reference of type 'char*&' from a temporary of type 'char*'
Because the type of c is char[4], i.e. an aray of four chars. Your reference needs a char*, i.e. a pointer to char. Arrays are not pointers. In most cases, they decay to a pointer to first element when used, but that decay-produced pointer is temporary. As such, it cannot bind to a non-const reference. Why is your function taking a reference in the first place? It would be perfectly fine taking char*.

Categories : C++

invalid initialization of reference of type 'delai_assemblage*&' from expression of type 'delai_assemblage'
If this is really C, not C++, then rename your file to have a .c extension, not .cpp. C and C++ are two different languages, and you should not be compiling .cpp files as C code. You'll also need to remove all reference types (types with a & in them, before the identifier), since C does not have references. For example: void demande_usine_stockage( entrepot *u_s, fournisseur f[], int *demande, delai_appro *d_a, // Reference (&) changed to pointer (*) delai_ass *d_ass, // Reference (&) changed to pointer (*) usine_ass *u_a, int *attente_stockage, int *attente_assemblage, int *debut_stockage, int *fin_stockage, int *debut_assemblage, int *fin_assemblage, int periode) { ... }

Categories : C++

Map properties of type CultureInfo
They simply can't be mapped directly because no database supports those types so you will have to create another type in your domain model (probably a Complex Object) that holds the properties of CultureInfo you are interested in or the second option would be to store the type in the database as binary data and for this you can convert CultureInfo to a stream of bytes, check this for more info.

Categories : Entity Framework

Is it possible to clone a git repository, and split the clone repo, keeping track of the changes from original repo?
Sparse checkouts may be of help here. You need to clone the repository A. You then have to configure sparse checkout (after cloning): git config core.sparsecheckout true echo project1/ > .git/info/sparse-checkout Then you need to call git read-tree -m -u HEAD Notes However the sparse checkout is not truly independent. Let us say you want only project1. Changes introduced by project2 or project3 in your case will suggest that your sparse checkout has changed. References Checkout sub directories in git

Categories : GIT

C# Properties not found on object of type
Edit Completely misunderstood requirement. If you're trying to create this setting at run time, then read it again later, here are the code changes: //ensures no runtime errors if you try and view the setting before its created private bool _customSettingExists = false; public Form1() { InitializeComponent(); } private void radButton1_Click(object sender, EventArgs e) { //You're saving your CustomSetting to properties, so you should read it from Default.Properties if (_customSettingExists) radTextBox1.Text = Properties.Settings.Default.Properties["CustomSetting"].ToString(); } private void radButton2_Click(object sender, EventArgs e) { System.Configuration.SettingsProperty property = new System.Configuration.SettingsProperty("CustomSetting"); property.Ser

Categories : C#

Using dynamic type instead of none-possible generic properties
As the answer in the comment indicated, you can do this with a base class or an interface: class DataGridForm {} class DataGridForm<TData, TGrid> : DataGridForm {} class GridConfigurator { public DataGridForm DataGrid { get; private set; } public DataGridForm<TData, TGrid> GridConfig<TData, TGrid>() where TData : class { return DataGrid = new DataGridForm<TData, TGrid>(); } } A ton of types and interfaces in C# were expanded this way when generics were added. However, I would probably re-evaluate your design so that perhaps whatever called GridConfig() was caching the DataGridForm since it knows the types. As an example, I do a very similar thing in my code: class Vector<T> { ... } static class Vector { public static Vector<

Categories : C#

Reference type in C#
You have changed person2 to reference null, but person1 isn't referencing there. What I mean is that if we look at person2 and person1 before the assignment then both reference the same object. Then you assign person2 = null, so person 2 is now referencing a different type. It did not delete the object that person2 was referenced to. I've created this gif to illustrate it:

Categories : C#

Accessing and Setting Array-Type Properties
You can just expose the property getter, and use it: class MyOtherClass { public MyOtherClass() { myProperty = new int[3, 3]; } public int[,] myProperty { get; private set; } }

Categories : C#

get properties using reflections for generic type object
Reflection on typeof(T) works fine; here's a simpler example based on yours, but (importantly) runnable. It outputs: ShopName TargetVehicleName code: using System; using System.Collections.Generic; public class CsvReport { public string ShopName { get; set; } public string TargetVehicleName { get; set; } } class ExportToCsv<T> { List<T> data; public ExportToCsv(List<T> obj) { data = obj; } public void WritePropNames() { foreach (var prop in typeof(T).GetProperties()) { Console.WriteLine(prop.Name); } } } static class Program { static void Main() { var obj = new List<CsvReport>(); obj.Add(new CsvReport { ShopName = "Foo", TargetVehicleName = "Bar" });

Categories : C#

how to add properties to class without changing return type in c#
If you cannot change the signature of the method, your callers would need to do some casting. This is not optimal, but you can still do it: public class NameWithEmail : Name { public string EMail {get;set;} } ... public Name LoadName() { ... return new NameWithEmail(); // OK because NameWithEmail extends Name } Now the caller would need to know the new type, do a cast, and access the email through it: NameWithEmail name = Details.LoadName() as NameWithEmail; if (name != null) { Console.WriteLine("{0} {1} : {2}", name.FirstName, name.LastName, name.EMail); } The trickiest part is binding the new property to a data grid. This answer explains how this can be done.

Categories : C#

JAXB/MOXy use same Entity-type for several properties
You can use EclipseLink JAXB (MOXy)'s @XmlNamedObjectGraph extension to support this use case. What @XmlNamedObjectGraph allows you to do is create multiple views on your data. Person Below we will use @XmlNamedObjectGraph to create a view on the Person class that only exposes 2 fields (firstName and lastName). import javax.xml.bind.annotation.*; import org.eclipse.persistence.oxm.annotations.*; @XmlNamedObjectGraph( name = "simple", attributeNodes = { @XmlNamedAttributeNode("firstName"), @XmlNamedAttributeNode("lastName") } ) @XmlAccessorType(XmlAccessType.FIELD) public class Person { private int clientId; private String firstName; private String lastName; private String email; public void setClientId(int clientId) { this.c

Categories : Java

EF Code First, map two navigation properties to the same object type
Entity Framework creates relationships with Cascade Delete on by default. Creating two relationships from one entity to another type tries to create two cascade-delete relationships, which the database will throw the error you saw for. Use the Code-First Fluent Configuration to remove the Cascade Delete on one or both of the relationships: modelBuilder.Entity<User>() .HasOptional(u => u.UserPreference) .WithMany() .WillCascadeOnDelete(false); modelBuilder.Entity<User>() .HasOptional(u => u.SecondaryUserPreference) .WithMany() .WillCascadeOnDelete(false);

Categories : Entity Framework

Draggable helper -> drop clone at position of mouseup -> draggable clone
Here is a starting point: fiddle but this is a very general solution, so in case you have a more specific use case let me know ! .js $("#container").droppable({ // accept draggables only from #toolbox, // this will prevent cloning of the draggables(inside drop event handler), // that already have been dropped inside #container accept: "#toolbox .draggable", drop: function (event, ui) { // when a draggable is dropped: // 1: clone it's helper // 2: Make the helper draggable // 3: set containment to #container $(this).append($(ui.helper).clone().draggable({ containment: "parent" })); } }); $(".draggable").draggable({ revert: "invalid", helper: "clone" }); .html <div id="toolbox"> <div class="draggable">drag&l

Categories : Javascript



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.