Search Results

Search found 6357 results on 255 pages for 'generic relations'.

Page 34/255 | < Previous Page | 30 31 32 33 34 35 36 37 38 39 40 41  | Next Page >

  • Control XML serialization of generic types

    - by Luca
    I'm investigating about XML serialization, and since I use lot of dictionary, I would like to serialize them as well. I found the following solution for that (I'm quite proud of it! :) ). [XmlInclude(typeof(Foo))] public class XmlDictionary<TKey, TValue> { /// <summary> /// Key/value pair. /// </summary> public struct DictionaryItem { /// <summary> /// Dictionary item key. /// </summary> public TKey Key; /// <summary> /// Dictionary item value. /// </summary> public TValue Value; } /// <summary> /// Dictionary items. /// </summary> public DictionaryItem[] Items { get { List<DictionaryItem> items = new List<DictionaryItem>(ItemsDictionary.Count); foreach (KeyValuePair<TKey, TValue> pair in ItemsDictionary) { DictionaryItem item; item.Key = pair.Key; item.Value = pair.Value; items.Add(item); } return (items.ToArray()); } set { ItemsDictionary = new Dictionary<TKey,TValue>(); foreach (DictionaryItem item in value) ItemsDictionary.Add(item.Key, item.Value); } } /// <summary> /// Indexer base on dictionary key. /// </summary> /// <param name="key"></param> /// <returns></returns> public TValue this[TKey key] { get { return (ItemsDictionary[key]); } set { Debug.Assert(value != null); ItemsDictionary[key] = value; } } /// <summary> /// Delegate for get key from a dictionary value. /// </summary> /// <param name="value"></param> /// <returns></returns> public delegate TKey GetItemKeyDelegate(TValue value); /// <summary> /// Add a range of values automatically determining the associated keys. /// </summary> /// <param name="values"></param> /// <param name="keygen"></param> public void AddRange(IEnumerable<TValue> values, GetItemKeyDelegate keygen) { foreach (TValue v in values) ItemsDictionary.Add(keygen(v), v); } /// <summary> /// Items dictionary. /// </summary> [XmlIgnore] public Dictionary<TKey, TValue> ItemsDictionary = new Dictionary<TKey,TValue>(); } The classes deriving from this class are serialized in the following way: <XmlProcessList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <Items> <DictionaryItemOfInt32Foo> <Key/> <Value/> </DictionaryItemOfInt32XmlProcess> <Items> This give me a good solution, but: How can I control the name of the element DictionaryItemOfInt32Foo What happens if I define a Dictionary<FooInt32, Int32> and I have the classes Foo and FooInt32? Is it possible to optimize the class above? THank you very much!

    Read the article

  • Compile time error: cannot convert from specific type to a generic type

    - by Water Cooler v2
    I get a compile time error with the following relevant code snippet at the line that calls NotifyObservers in the if construct. public class ExternalSystem<TEmployee, TEventArgs> : ISubject<TEventArgs> where TEmployee : Employee where TEventArgs : EmployeeEventArgs { protected List<IObserver<TEventArgs>> _observers = null; protected List<TEmployee> _employees = null; public virtual void AddNewEmployee(TEmployee employee) { if (_employees.Contains(employee) == false) { _employees.Add(employee); string message = FormatMessage("New {0} hired.", employee); if (employee is Executive) NotifyObservers(new ExecutiveEventArgs { e = employee, msg = message }); else if (employee is BuildingSecurity) NotifyObservers(new BuildingSecurityEventArgs { e = employee, msg = message }); } } public void NotifyObservers(TEventArgs args) { foreach (IObserver<TEventArgs> observer in _observers) observer.EmployeeEventHandler(this, args); } } The error I receive is: The best overloaded method match for 'ExternalSystem.NotifyObservers(TEventArgs)' has some invalid arguments. Cannot convert from 'ExecutiveEventArgs' to 'TEventArgs'. I am compiling this in C# 3.0 using Visual Studio 2008 Express Edition.

    Read the article

  • Find the class of the generic object

    - by Mgccl
    Suppose I have the following class. public class gen<T> { public gen(){ } Class<T> class(){ //something that figures out what T is. } } How can I implement the class() function without pass any additional information? What I did is here, but I have to pass a object of T into the object gen. public class gen<T> { public gen(){ } Class<T> class(T var){ return (Class<T>) var.getClass(); } }

    Read the article

  • Using Custom Generic Collection faster with objects than List

    - by Kaminari
    I'm iterating through a List<> to find a matching element. The problem is that object has only 2 significant values, Name and Link (both strings), but has some other values which I don't want to compare. I'm thinking about using something like HashSet (which is exactly what I'm searching for -- fast) from .NET 3.5 but target framework has to be 2.0. There is something called Power Collections here: http://powercollections.codeplex.com/, should I use that? But maybe there is other way? If not, can you suggest me a suitable custom collection?

    Read the article

  • Logic: Best way to sample & count bytes of a 100MB+ file

    - by Jami
    Let's say I have this 170mb file (roughly 180 million bytes). What I need to do is to create a table that lists: all 4096 byte combinations found [column 'bytes'], and the number of times each byte combination appeared in it [column 'occurrences'] Assume two things: I can save data very fast, but I can update my saved data very slow. How should I sample the file and save the needed information? Here're some suggestions that are (extremely) slow: Go through each 4096 byte combinations in the file, save each data, but search the table first for existing combinations and update it's values. this is unbelievably slow Go through each 4096 byte combinations in the file, save until 1 million rows of data in a temporary table. Go through that table and fix the entries (combine repeating byte combinations), then copy to the big table. Repeat going through another 1 million rows of data and repeat the process. this is faster by a bit, but still unbelievably slow This is kind of like taking the statistics of the file. NOTE: I know that sampling the file can generate tons of data (around 22Gb from experience), and I know that any solution posted would take a bit of time to finish. I need the most efficient saving process

    Read the article

  • Why can I derived from a templated/generic class based on that type in C# / C++

    - by stusmith
    Title probably doesn't make a lot of sense, so I'll start with some code: class Foo : public std::vector<Foo> { }; ... Foo f; f.push_back( Foo() ); Why is this allowed by the compiler? My brain is melting at this stage, so can anyone explain whether there are any reasons you would want to do this? Unfortunately I've just seen a similar pattern in some production C# code and wondered why anyone would use this pattern.

    Read the article

  • Show composition/aggregation/association relations between objects in Visual Paradigm UML diagrams?

    - by ajsie
    I have Netbeans installed with Visual Paradigm plugin. I have converted my php code into UML diagrams (modeling - instant reverse). I can see relations (drawn lines) between superclass and subclasses. However, i cannot see relations between objects inside objects (composition/aggregation/association)? The code looks like: class Thread { private $tag = ''; public function __construct($tagObject) { $this->tag = $tagObject; } } I know its possible using Java cause i've read about it. Im using PHP, is this still possible?

    Read the article

  • C#, Generic Lists and Inheritance

    - by Andy
    I have a class called Foo that defines a list of objects of type A: class Foo { List<A> Items = new List<A>(); } I have a class called Bar that can save and load lists of objects of type B: class Bar { void Save(List<B> ComplexItems); List<B> Load(); } B is a child of A. Foo, Bar, A and B are in a library and the user can create children of any of the classes. What I would like to do is something like the following: Foo MyFoo = new Foo(); Bar MyBar = new Bar(); MyFoo.Items = MyBar.Load(); MyBar.Save(MyFoo.Items); Obviously this won't work. Is there a clever way to do this that avoids creating intermediate lists? thanks, Andy

    Read the article

  • How to bind a List<DateTime> to a DataGridView/ListBox .NET C#

    - by nat
    Hi there I have a List that I want to bind to a DataGridView in a windows forms app. however, I cannot for the life of me find the DataPropertyName I need to show what I want. I have had similar problems with binding this list to a listbox. what i really want is to show .ToString("dddd, dd MMMM yyyy HH:mm"), or certainly more than the standard 'date' part of the datetime - do i need to add a property of my own? public partial class DateTime{ public string myFormat{ get{return this.ToString("dddd dd MMM yyyy HH:mm");} } } or some such? thanks nat

    Read the article

  • Writing a generic function that can take a Writer as well as an OutputStream

    - by ebruchez
    I wrote a couple of functions that look like this: def myWrite(os: OutputStream) = {} def myWrite(w: Writer) = {} Now both are very similar and I thought I would try to write a single parametrized version of the function. I started with a type with the two methods that are common in the Java OutputStream and Writer: type Writable[T] = { def close() : Unit def write(cbuf: Array[T], off: Int, len: Int): Unit } One issue is that OutputStream writes Byte and Writer writes Char, so I parametrized the type with T. Then I write my function: def myWrite[T, A[T] <: Writable[T]](out: A[T]) = {} and try to use it: val w = new java.io.StringWriter() myWrite(w) Result: <console>:9: error: type mismatch; found : java.io.StringWriter required: ?A[ ?T ] Note that implicit conversions are not applicable because they are ambiguous: both method any2ArrowAssoc in object Predef of type [A](x: A)ArrowAssoc[A] and method any2Ensuring in object Predef of type [A](x: A)Ensuring[A] are possible conversion functions from java.io.StringWriter to ?A[ ?T ] myWrite(w) I tried a few other combinations of types and parameters, to no avail so far. My question is whether there is a way of achieving this at all, and if so how. (Note that the implementation of myWrite will need, internally, to know the type T that parametrizes the write() method, because it needs to create a buffer as in new ArrayT.)

    Read the article

  • ASP.NET MVC Generic Partial

    - by gnome
    Is is possible to have a partial view inherit more than one model? I have three models (Contacts, Clients, Vendors) that all have address information (Address). In the interest of being DRY I pulled the address info into it's own model, Addresses. I created a partial create / update view of addresses and what to render this in other other three model's create / update views.

    Read the article

  • C++ Generic List Assignment

    - by S73417H
    I've clearly been stuck in Java land for too long... Is it possible to do the C++ equivalent of the following Java code: // Method List<Bar> getBars() { return new LinkedList<Bar>(); } // Assignment statement. List<Foo> stuff = getBars(); Where Foo is a sub-class of Bar. So in C++.... std::list<Bar> & getBars() { std::list<Bar> bars; return bars; } std::list<Foo> stuff = getBars(); Hope that makes sense....

    Read the article

  • WPF Converter to look up in generic list

    - by user310046
    I have a list of data where I keep e.g. countries with code, name and some other data. List<Country> countries = <deserialized objects from file> which consist of objects like this: public class Country { public string Code { get; set;} public string Name { get; set;} } The object which use as a DataContext may look like this: public class Address { public string StreetName{ get; set;} public string CountryCode { get; set;} } Then in my XAML I want to do something like this to show the name of the country <TextBlock Text="{Binding Path=CountryCode, Converter={StaticResource CountryNameLookupConverter}}"/> But how can I make the CountryNameLookupConverter use the countries list I read from the xml file?

    Read the article

  • Is the method that I am using for retrieval in my generic list optimized

    - by fishhead
    At some time there will be a large amount of records, about 50,000. with that in mind is the method GetEquipmentRecord up to the task. thanks for you opinions. public enum EquipShift { day, night }; public class EquipStatusList : List<EquipStatus> { string SerialFormat = "yyyyMMdd"; int _EquipmentID; string _DateSerial; EquipShift _Shift; public EquipStatus GetEquipmentRecord(int equipmentID, EquipShift shift, DateTime date) { _DateSerial = date.ToString(SerialFormat); _Shift = shift; _EquipmentID = equipmentID; return this.Find(checkforEquipRecord); } bool checkforEquipRecord(EquipStatus equip) { if ((equip.EquipmentID == _EquipmentID) && (equip.Shift == _Shift) && (equip.Date.ToString(SerialFormat) == _DateSerial)) return true; else return false; } }

    Read the article

  • Reflection for Class of generic parameter in Java?

    - by hatboysam
    Imagine the following scenario: class MyClass extends OtherClass<String>{ String myName; //Whatever } class OtherClass<T> { T myfield; } And I am analyzing MyClass using reflection specifically (MyClass.class).getDeclaredFields(), in this case I will get the following fields (and Types, using getType() of the Field): myName --> String myField --> T I want to get the actual Type for T, which is known at runtime due to the explicit "String" in the extends notation, how do I go about getting the non-genetic type of myField?

    Read the article

  • Generic Func<> as parameter to base method

    - by WestDiscGolf
    I might be losing the plot, but I hope someone can point me in the right direction. What am I trying to do? I'm trying to write some base methods which take Func< and Action so that these methods handle all of the exception handling etc. so its not repeated all over the place but allow the derived classes to specify what actions it wants to execute. So far this is the base class. public abstract class ServiceBase<T> { protected T Settings { get; set; } protected ServiceBase(T setting) { Settings = setting; } public void ExecAction(Action action) { try { action(); } catch (Exception exception) { throw new Exception(exception.Message); } } public TResult ExecFunc<T1, T2, T3, TResult>(Func<T1, T2, T3, TResult> function) { try { /* what goes here?! */ } catch (Exception exception) { throw new Exception(exception.Message); } } } I want to execute an Action in the following way in the derived class (this seems to work): public void Delete(string application, string key) { ExecAction(() => Settings.Delete(application, key)); } And I want to execute a Func in a similar way in the derived class but for the life of me I can't seem to workout what to put in the base class. I want to be able to call it in the following way (if possible): public object Get(string application, string key, int? expiration) { return ExecFunc(() => Settings.Get(application, key, expiration)); } Am I thinking too crazy or is this possible? Thanks in advance for all the help.

    Read the article

  • Generic Database table design

    - by Gazeth
    Just trying to figure out the best way to design my table for the following scenario: I have several areas in my system (documents, projects, groups and clients) and each of these can have comments logged against them. My question is should I have one table like this: CommentID DocumentID ProjectID GroupID ClientID etc Where only one of the ids will have data and the rest will be NULL or should I have a seperate CommentType table and have my comments table like this: CommentID CommentTypeID ResourceID (this being the id of the project/doc/client) etc My thoughts are that option 2 would be more efficient from an indexing point of view?

    Read the article

  • How to manage a BorderLayout with generic JPanel()

    - by Nick G.
    Im not sure how to reference to JPanel when it was declared like this, I had someone else help me on JPanels and this is the code he used: final JFrame frame = new JFrame("CIT Test Program"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setPreferredSize(new Dimension(350, 250)); frame.add(new JPanel() {{ Not sure how to reference to JPanel to use BorderLayout. How would I go about doing this?

    Read the article

  • c# ProcessCmdKey overload, match generic combination

    - by leo
    Hi all, On some control, I want ProcessCmdKey to return true if the keys pressed by the user were ALT and any letter of the alphabet. I'm able to return true if the user presses Alt with the following code, but how can I add the condition of a letter also pressed ? protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { if ((keyData & Keys.Alt) != 0) { return true; } } Thanks.

    Read the article

  • Invoking static methods containing Generic Parameters using Reflection.

    - by AJP
    While executing the following code i gets this error "Late bound operations cannot be performed on types or methods for which ContainsGenericParameters is true." class Program { static void Main(string[] args) { MethodInfo MI = typeof(MyClass).GetMethod("TestProc"); MI.MakeGenericMethod(new [] {typeof(string)}); MI.Invoke(null, new [] {"Hello"}); } } class MyClass { public static void TestProc<T>(T prefix) { Console.WriteLine("Hello"); } } Please help.

    Read the article

  • C#, Using Custom Generic Collection faster with objects than List

    - by Kaminari
    Hello, I'm using for now List< to iterate through some object collection and find matching element, The problem is that object has only 2 significant values Name and Link (strings) but has some other values wich I dont want to compare. I'm thinkig about using something like HashSet (wich is exactly what I'm searching for - fast) from .NET 3.5 but target framework has to be 2.0. There is something called Power Collections here: http://powercollections.codeplex.com/ But maybe there is other way? If not, can you suggest me a suitable custom collection?

    Read the article

  • A strange error in java generic.

    - by ???
    This is ok: Class<? extends String> stringClass = "a".getClass(); But this gets error: <T> void f(T obj) { Class<? extends T> objClass = obj.getClass(); } I know I can cast it like: <T> void f(T obj) { @SuppressWarnings("unchecked") Class<? extends T> objClass = (Class<? extends T>) obj.getClass(); } But why the previous error? Will the next release of Java 7 will support such usage?

    Read the article

  • Overriding inherited generic methods

    - by jess
    I have this code in base class protected virtual bool HasAnyStuff<TObject>(TObject obj) where TObject:class { return false; } In child class I am overriding protected override bool HasAnyStuff<Customer>(Customer obj) { //some stuff if Customer.sth etc return false; } I am getting this error '''Type parameter declaration must be an identifier not a type''' What is it I am doing wrong here?

    Read the article

< Previous Page | 30 31 32 33 34 35 36 37 38 39 40 41  | Next Page >