Search Results

Search found 1575 results on 63 pages for 'reflection'.

Page 14/63 | < Previous Page | 10 11 12 13 14 15 16 17 18 19 20 21  | Next Page >

  • Compute hash of class code at runtime (C#)?

    - by Breck Fresen
    Is it possible to compute the hash of a class at runtime in C# (presumably through reflection)? To be clear, I don't want to compute the hashcode of an instance of said class, I want to compute the hash of the class code itself (if a function in the class changes, I'd expect a different hash code to be computed). Ideally this would only be sensitive to changes in the object code (and not just a hash of the string representation of the code itself). Thanks in advance for your help, -- Breck

    Read the article

  • What is the best way get and hold property reference by name in c#

    - by Jeff Weber
    I want to know if there is a better way (than what I'm currently doing) to obtain and hold a reference to a property in another object using only the object and property string names. Particularly, is there a better way to do this with the new dynamic functionality of .Net 4.0? Here is what I have right now. I have a "PropertyReference<T>" object that takes an object name and property name in the constructor. An Initialize() method uses reflection to find the object and property and stores the property Getter as an Action<T> and the property Setter as an Func<T>. When I want to actually call the property I do something like this: int x = _propertyReference.Get(); or _propertyReference.Set(2); Here is my PropertyReference<T> code. Please dissect and make suggestions for improvement. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Reflection; using System.Xml; namespace WindowsFormsApplication2 { public class PropertyReference<T> : IPropertyReference { public string ComponentName { get; set; } public string PropertyName { get; set; } public bool IsInitialized { get { return (_action != null && _func != null); } } Action<T> _action; Func<T> _func; public PropertyReference() { } public PropertyReference(string componentName, string propertyName) { ComponentName = componentName; PropertyName = propertyName; } public void Initialize(IEntity e) { Object component = e.GetByName(ComponentName); if (component == null) return; Type t = e.GetByName(ComponentName).GetType(); PropertyInfo pi = t.GetProperty(PropertyName); _action = (T a) => pi.SetValue(component, a, null); _func = () => (T)pi.GetValue(component, null); } public void Reset() { _action = null; _func = null; } public void Set(T value) { _action.Invoke(value); } public T Get() { return _func(); } } } Note: I can't use the "Emit" functionality as I need this code to work on the new Windows Phone 7 and that does not support Emit.

    Read the article

  • Call private method in Flex, Actionscript.

    - by core07
    I need it in FlexUnit to test private methods. Is there any possibility to do this via reflection by using describeType or maybe flexUnit has some build in facility? I dislike artificial limitation that i cannot test private functions, it greatly reduces flexibility. Yes it is good design for me to test private functions, so please do not advise me to refactor my code. I do not want to break the encapsulation for the sake of unit testing.

    Read the article

  • Adding metadata attributes to MySQL table

    - by Jack
    I would like to add custom attributes to a MySQL table which I can read via php. These attributes are not to interfere with the table itself - they are primarily accessed by php code during code generation time and these attributes HAVE to reside in the DB itself. Something similar in concept to .NET reflection. Does MySQL support anything like this? Thanks.

    Read the article

  • c# - How do you get a variable's name as it was physically typed in its declaration?

    - by Petras
    The class below contains the field city. I need to dynamically determine the field's name as it is typed in the class declaration i.e. I need to get the string "city" from an instance of the object city. I have tried to do this by examining its Type in DoSomething() but can't find it when examining the contents of the Type in the debugger. Is it possible? public class Person { public string city = "New York"; public Person() { } public void DoSomething() { Type t = city.GetType(); string field_name = t.SomeUnkownFunction(); //would return the string "city" if it existed! } } Some people in their answers below have asked me why I want to do this. Here's why. In my real world situation, there is a custom attribute above city. [MyCustomAttribute("param1", "param2", etc)] public string city = "New York"; I need this attribute in other code. To get the attribute, I use reflection. And in the reflection code I need to type the string "city" MyCustomAttribute attr; Type t = typeof(Person); foreach (FieldInfo field in t.GetFields()) { if (field.Name == "city") { //do stuff when we find the field that has the attribute we need } } Now this isn't type safe. If I changed the variable "city" to "workCity" in my field declaration in Person this line would fail unless I knew to update the string if (field.Name == "workCity") //I have to make this change in another file for this to still work, yuk! { } So I am trying to find some way to pass the string to this code without physically typing it. Yes, I could declare it as a string constant in Person (or something like that) but that would still be typing it twice. Phew! That was tough to explain!! Thanks Thanks to all who answered this * a lot*. It sent me on a new path to better understand lambda expressions. And it created a new question.

    Read the article

  • Get interface constant name using its value

    - by Ravisha
    This might not have a major usecase in projects ,but i was just trying a POC kind of project where in i get the key code,and using its value i want to print the key name on screen so i want to relive myself off writing switch cases ,so thinking of going by reflection. Is there a way to get the constant integer of interface's name using its value?

    Read the article

  • Reflect and Load code at design time in Visual Studio

    - by Stacey
    I have an XML file that lists a series of items, and the items are often referenced by their name in code. Is there any way to use reflection within Visual Studio to make this list 'accessible' sort of like intellisence? I've seen it done before - and I'm pretty sure it's ridiculously difficult, but I figure it can't hurt to at least ask.

    Read the article

  • What is this <Module> Type in an assembly

    - by LightX
    Each time I open an assembly in reflector, I see this special <Module> type that shows up. Recently, I came across an assembly that has a static method defined in this type and I want to invoke it through reflection. Is this possible? Btw, this method has privatescope hidebysig method attributes

    Read the article

  • How can I retrieve the instance of an attribute's associated object?

    - by Brandon Linton
    I'm writing a PropertiesMustMatch validation attribute that can take a string property name as a parameter. I'd like it to find the corresponding property by name on that object and do a basic equality comparison. What's the best way to access this through reflection? Also, I checked out the Validation application block in the Enterprise Library and decided its PropertyComparisonValidator was way too intense for what we need.

    Read the article

  • Replacing deprecated <:< Manifest type witness in Scala 2.10

    - by Josh
    Can someone point me at what I should be doing under scala 2.10 in place of this deprecated type witness on Manifest? reflect.ClassManifest.singleType(foo) <:< barManifest Honestly, my goal here is just to replace it with something that doesn't raise a deprecation warning. I'm happy to use the new reflection API. Here's the code in question in context, if that's important: https://github.com/azavea/geotrellis/blob/master/src/main/scala/geotrellis/feature/op/geometry/geometry.scala#L45

    Read the article

  • How can I get the assembly last modified date?

    - by Juan Manuel Formoso
    I want to render (for internal debugging/info) the last modified date of an assembly, so I know when was a certain website deployed. Is it possible to get it though reflection? I get the version like this, I'm looking for something similar: Assembly.GetExecutingAssembly().GetName().Version.ToString(); ie: I don't want to open the physical file, get its properties, or something like that, as I'll be rendering it in the master page, and don't want that kind of overhead.

    Read the article

  • Get Const / Static Name from Function / Method Call.

    - by Mark Tomlin
    I want to find the token's name passed by augment into a function. class Norm { const STR_NORM = 0; const INT_NORM = 0; } function foo($Arg1, $Arg2 = NULL) { getConstName($Arg1); # Should Return STR_NORM; return $Arg1, $Arg2; } echo foo(Norm::STR_NORM); Is there any way to impalement getConstName via the PHP Reflection API?

    Read the article

  • What are the suggested alternatives for Class<T>.isAssignableFrom(Class<?> cls)?

    - by Wing C. Chen
    Currently I am doing the profiling to a piece of code. During the profiling, I discovered that this very method call, Class<T>.isAssignableFrom(Class<?> cls) takes up to quite amount of the entire time. Because this is a method from reflection, it takes a lot of time compared to normal keywords or method calls. I am wondering if there are some good alternatives for this method calls?

    Read the article

  • C# Type Casting at Runtimefor Array.SetValue

    - by sprocketonline
    I'm trying to create an array using reflection, and insert values into it. I'm trying to do this for many different types so would like a createAndFillArray function capable of this : Type t1 = typeof(A); Type t2 = typeof(B); double exampleA = 22.5; int exampleB = 43; Array arrA = createAndFillArray(t1, exampleA); Array arrB = createAndFillArray(t2, exampleB); private Array createAndFillArray(Type t, object val){ Array arr = Array.CreateInstance( t, 1); //length 1 in this example only, real-world is of variable length. arr.SetValue( val, 0 ); //this causes the following error: "System.InvalidCastException : Object cannot be stored in an array of this type." return arr; } with the class A being as follows: public class A{ public A(){} private double val; public double Value{ get{ return val; } set{ this.val = value; } } public static implicit operator A(double d){ A a = new A(); a.Value = d; return a; } } and class B being very similar, but with int: public class B{ public B(){} private double val; public double Value{ get{ return val; } set{ this.val = value; } } public static implicit operator B(double d){ B b = new B(); b.Value = d; return b; } } I hoped that the implicit operator would have ensured that the double be converted to class A, or the int to class B, and the error avoided; but this is obviously not so. The above is used in a custom deserialization class, which takes data from a custom data format and fills in the corresponding .Net object properties. I'm doing this via reflection and at runtime, so I think both are unavoidable. I'm targeting the C# 2.0 framework. I've dozens, if not hundreds, of classes similar to A and B, so would prefer to find a solution which improved on the createAndFillArray method rather than a solution which altered these classes.

    Read the article

  • Is there a C# equivalent of typeof for properties/methods/members?

    - by David
    A classes Type metadata can be obtained in several ways. Two of them are: var typeInfo = Type.GetType("MyClass") and var typeInfo = typeof(MyClass) The advantage of the second way is that typos will be caught by the compiler, and the IDE can understand what I'm talking about (allowing features like refactoring to work without silently breaking the code) Does there exist an equivalent way of strongly referencing members/properties/methods for metadata and reflection? Can I replace: var propertyInfo = typeof(MyClass).GetProperty("MyProperty") with something like: var propertyInfo = property(MyClass.MyProperty)

    Read the article

< Previous Page | 10 11 12 13 14 15 16 17 18 19 20 21  | Next Page >