Search Results

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

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

  • What is the .NET equivalent of PHP var_dump?

    - by George Mauer
    I remember seeing a while ago that there is some method in maybe the Reflection namespace that would recursively run ToString() on all of an object's properties and format it nicely for display. Yes, I know everything I could want will be accessible through the debugger, but I'm wondering if anyone knows that command?

    Read the article

  • Can C# Attributes access the Target Class?

    - by Heka
    I want to access the properties of a class from the attribute class by using reflection. Is it possible? For example: class MyAttribute : Attribute { private void AccessTargetClass() { // Do some operations } } [MyAttribute] class TargetClass { }

    Read the article

  • modify a method/function at runtime

    - by mononym
    I've been looking at the php reflection methods, what i want to do is inject some code after the method is opened and before any return value, for example i want to change: function foo($bar) { $foo = $bar ; return $foo ; } And inject some code into it like: function foo($bar) { //some code here $foo = $bar ; //some code here return $foo ; } possible?

    Read the article

  • C# equivalent of typeof for fields

    - by rwallace
    With reflection, you can look up a class from a string at run time, but you can also say typeof(Foo) and get compile time type checking, auto completion etc. If what you want is a field not a class, you can look it up from a string at runtime, but if you want compile time type checking etc., is there anyway to say something like fieldof(Foo.Bar)? I know the name of both the class and the field in advance, and I want to be able to refer to the field at compile time rather than with a run-time string lookup.

    Read the article

  • Be notified of method calls in .NET

    - by Alex
    Basically, what I want to do is to be notified whenever a specific method has been called. I was hoping I could accomplish this using Reflection, but my attempts haven't gotten me anywhere yet, so I'm hoping that perhaps somebody else with the same need has accomplished this before and can enlighten me. I figured using MethodInfo was the way to go, but like I said, I found nothing there that could help me accomplish what I wanted to do. Any suggestions, hints or solutions would be greatly appreciated.

    Read the article

  • VB .NET DirectCast and Type Reflection

    - by msarchet
    The application that I am working on has a generic Parent Form called RSChild, that is used to perform some operations depending on whether or not the control that is contained within it is in a MdiTabManager or inside of its own modal form. Then the actual User Controls contained within Inherit from a Interface Called ObjectEdit (Objects that we allow to be edited). At a point in my code I am doing this. Public Function doesTabExist(ByVal id As Integer, ByVal recordType As Enums.eRecordType) As Boolean Dim alikePages As Object = (From tabs In DirectCast(Control.FromHandle(MainForm.SharedHandle), MainForm).XtraTabbedMdiManager1.Pages Where DirectCast(tabs.MdiChild, RSChild).RSObject.RecordType = recordType Select tabs) For Each page As DevExpress.XtraTabbedMdi.XtraMdiTabPage In alikePages Select Case recordType Case Enums.eRecordType.Doctor If id = DirectCast(castTabPageToRSChild(page).RSObject, UI.Doctor).ID Then pageToActive(page) Return True End If 'rest of the cases so the case block is repeated 10 times' End Function And my castTabPageToRSChild(page) is a lambda function as Such Dim castTabPageToRSChild As Func(Of DevExpress.XtraTabbedMdi.XtraMdiTabPage, RSChild) = Function(page) DirectCast(page.MdiChild, RSChild) So my Question is, I have about 10 case statements, all because I can't seem to find a way to use reflection to get the underlying Type of the RSObject Object. So I have the whole If block repeated over and over. I tried doing castTabPageToRSChild(page)RSObject.GetType and using that in the DirectCast and I also tried creating another object that was separate from that and doing the same thing. My code works as intended I'm just trying to see if there is a manner in which I didn't have a lot of replicated code. My vision would be to do something like For Each page As XtraMdiTabPage In alikePages If id = DirectCast(castTabPageToRSchild(page).RSObject, TypeOfThatObject).Id Then Return True Next However I have a feeling this is not possible due to the behavior of DirectCast.

    Read the article

  • ImageMagick Reflection

    - by dbruns
    Brief: convert ( -size 585x128 gradient: ) NewImage.png How do I change the above ImageMagick command so it takes the width and height from an existing image? I need it to remain a one line command. Details: I'm trying to programatically create an image reflection using ImageMagick. The effect I am looking for is similar to what you would see when looking at an object on the edge of a pool of water. There is a pretty good thread on what I am trying to do here but the solution isn't exactly what I am looking for. Since I will be calling ImageMagick from a C#.Net application I want to use one call without any temp files and return the image through stdout. So far I have this... convert OriginalImage.png ( OriginalImage.png -flip -blur 3x5 \ -crop 100%%x30%%+0+0 -negate -evaluate multiply 0.3 \ -negate ( -size 585x128 gradient: ) +matte -compose copy_opacity -composite ) -append NewImage.png This works ok but doesn't give me the exact fade I am looking for. Instead of a nice solid fade from top to bottom it is giving me a fade from top left to bottom right. I added the (-negate -evaluate multiply 0.3 -negate) section in to lighten it up a bit more since I wasn't getting the fade I wanted. I also don't want to have to hard code in the size of the image when creating the gradient ( -size 585x128 gradient: ) I'm also going to want to keep the original image's transparency if possible. To go to stdout I plan on replacing "NewImage.png" with "-"

    Read the article

  • Implicit Type Conversions in Reflection

    - by bradhe
    So I've written a quick bit of code to help quickly convert between business objects and view models. Not to pimp my own blog, but you can find the details here if you're interested or need to know. One issue I've run in to is that I have a custom collection type, ProductCollection, and I need to turn that in to a string[] in on my model. Obviously, since there is no default implicit cast, I'm getting an exception in my contract converter. So, I thought I would write the next little bit of code and that should solve the problem: public static implicit operator string[](ProductCollection collection) { var list = new List<string>(); foreach (var product in collection) { if (product.Id == null) { list.Add(null); } else { list.Add(product.Id.ToString()); } } return list.ToArray(); } However, it still fails with the same cast exception. I'm wondering if it has something to do with being in reflection? If so, is there anything that I can do here?? I'm open to architectural solutions, too!

    Read the article

  • Listbox - selected item to call the class method directly using reflection

    - by Karan
    I have a problem scenario like this:- 1) Listbox with values like Car, Scooter and Bike. A button to click. <div> <asp:ListBox ID="lst" runat="server"> <asp:ListItem Text="Bike" Value="Bike"></asp:ListItem> <asp:ListItem Text="Car" Value="Car"></asp:ListItem> <asp:ListItem Text="Scooter" Value="Scooter"></asp:ListItem> </asp:ListBox> <br /> <br /> <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Invoke" /> </div> 2) Now i have three different class like below:- class Car { static string getData() { return "I like cars"; } } class Bike { static string getData() { return "I like Bike"; } } class Scooter { static string getData() { return "I dont like scooter"; } } 3) Now on the button click event handler "Button1_Click", i want to call the getData() method based on the selected value from the listbox using the REFLECTION only. Please help me out.

    Read the article

  • Reflection to access advanced telephony features

    - by Tyler
    I am trying to use reflection to access some advanced features of the telephony api not published. Currently I am having trouble instantiating a serviceManager object that is needed to get the "phone" service as a binder which I can then use to instantiate a telephony object which is needed to make a call, end call, etc... currently when I make the call serviceManagerObject = tempInterfaceMethod.invoke(null, new Object[] { new Binder() }); it returns a nullPointerException. I believe this has to due with creating a new Binder instead of sending the appropriate binder (which I am unsure of which one is appropriate) public void placeReflectedCall() throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, InstantiationException { String serviceManagerName = "android.os.IServiceManager"; String serviceManagerNativeName = "android.os.ServiceManagerNative"; String telephonyName = "com.android.internal.telephony.ITelephony"; Class telephonyClass; Class telephonyStubClass; Class serviceManagerClass; Class serviceManagerStubClass; Class serviceManagerNativeClass; Class serviceManagerNativeStubClass; Method telephonyCall; Method telephonyEndCall; Method telephonyAnswerCall; Method getDefault; Method[] temps; Constructor[] serviceManagerConstructor; // Method getService; Object telephonyObject; Object serviceManagerObject; String number = "1111111111"; telephonyClass = Class.forName(telephonyName); telephonyStubClass = telephonyClass.getClasses()[0]; serviceManagerClass = Class.forName(serviceManagerName); serviceManagerNativeClass = Class.forName(serviceManagerNativeName); Method getService = // getDefaults[29]; serviceManagerClass.getMethod("getService", String.class); Method tempInterfaceMethod = serviceManagerNativeClass.getMethod( "asInterface", IBinder.class); // this does not work serviceManagerObject = tempInterfaceMethod.invoke(null, new Object[] { new Binder() }); IBinder retbinder = (IBinder) getService.invoke(serviceManagerObject, "phone"); Method serviceMethod = telephonyStubClass.getMethod("asInterface", IBinder.class); telephonyObject = serviceMethod .invoke(null, new Object[] { retbinder }); telephonyCall = telephonyClass.getMethod("call", String.class); telephonyEndCall = telephonyClass.getMethod("endCall"); telephonyAnswerCall = telephonyClass.getMethod("answerRingingCall"); telephonyCall.invoke(telephonyObject, number); } Thanks in advance for any answers.

    Read the article

  • Unable to execute a function using reflection

    - by Steven
    hi, i am developing a eclipse plugin . In this plugin i am using reflection to execute a function in a class present in another project which is a hibernate project.Whenever the invoke is used i.e mymethod.invoke(myobj); it is giving this exception java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37) at java.lang.reflect.Method.invoke(Method.java:599) at packagesearch.DummyExecution.execution(DummyExecution.java:154) at packagesearch.HelloWorldAction.run(HelloWorldAction.java:48) at org.eclipse.ui.internal.PluginAction.runWithEvent(PluginAction.java:251) at org.eclipse.ui.internal.WWinPluginAction.runWithEvent(WWinPluginAction.java:229) at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:583) at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:500) at org.eclipse.jface.action.ActionContributionItem$6.handleEvent(ActionContributionItem.java:452) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3823) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3422) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2384) at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2348) at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2200) at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:495) at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:288) at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:490) at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149) at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:113) at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:193) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:386) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37) at java.lang.reflect.Method.invoke(Method.java:599) at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:549) at org.eclipse.equinox.launcher.Main.basicRun(Main.java:504) at org.eclipse.equinox.launcher.Main.run(Main.java:1236) at org.eclipse.equinox.launcher.Main.main(Main.java:1212) Caused by: java.lang.NoClassDefFoundError: org.dom4j.DocumentException at java.lang.J9VMInternals.verifyImpl(Native Method) at java.lang.J9VMInternals.verify(J9VMInternals.java:72) at java.lang.J9VMInternals.initialize(J9VMInternals.java:134) at test.Example.demo1(Example.java:38) ... 36 more Caused by: java.lang.ClassNotFoundException: org.dom4j.DocumentException at java.net.URLClassLoader.findClass(URLClassLoader.java:419) at java.lang.ClassLoader.loadClass(ClassLoader.java:643) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:345) at java.lang.ClassLoader.loadClass(ClassLoader.java:609) ... 40 more what is the exact problem . i have used loader to load the class.Help

    Read the article

  • Unable to execute a function usnig reflection

    - by Steven
    hi, i am developing a eclipse plugin . In this plugin i am using reflection to execute a function in a class present in another project which is a hibernate project.Whenever the invoke is used i.e mymethod.invoke(myobj); it is giving this exception java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37) at java.lang.reflect.Method.invoke(Method.java:599) at packagesearch.DummyExecution.execution(DummyExecution.java:154) at packagesearch.HelloWorldAction.run(HelloWorldAction.java:48) at org.eclipse.ui.internal.PluginAction.runWithEvent(PluginAction.java:251) at org.eclipse.ui.internal.WWinPluginAction.runWithEvent(WWinPluginAction.java:229) at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:583) at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:500) at org.eclipse.jface.action.ActionContributionItem$6.handleEvent(ActionContributionItem.java:452) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3823) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3422) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2384) at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2348) at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2200) at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:495) at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:288) at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:490) at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149) at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:113) at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:193) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:386) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37) at java.lang.reflect.Method.invoke(Method.java:599) at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:549) at org.eclipse.equinox.launcher.Main.basicRun(Main.java:504) at org.eclipse.equinox.launcher.Main.run(Main.java:1236) at org.eclipse.equinox.launcher.Main.main(Main.java:1212) Caused by: java.lang.NoClassDefFoundError: org.dom4j.DocumentException at java.lang.J9VMInternals.verifyImpl(Native Method) at java.lang.J9VMInternals.verify(J9VMInternals.java:72) at java.lang.J9VMInternals.initialize(J9VMInternals.java:134) at test.Example.demo1(Example.java:38) ... 36 more Caused by: java.lang.ClassNotFoundException: org.dom4j.DocumentException at java.net.URLClassLoader.findClass(URLClassLoader.java:419) at java.lang.ClassLoader.loadClass(ClassLoader.java:643) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:345) at java.lang.ClassLoader.loadClass(ClassLoader.java:609) ... 40 more what is the exact problem . i have used loader to load the class.Help

    Read the article

  • Reflect on an ExpandoObject

    - by Water Cooler v2
    I have written a nifty function that will accept a system.object, reflect on its properties and serialize the object into a JSON string. It looks like this: public class JSONSerializer { public string Serialize(object obj) Now, I want to be able to do this to serialize a dynamic/ExpandoObject, but because my serializer uses reflection, it isn't able to do it. What's the workaround? public class Test { public dynamic MakeDynamicCat() { dynamic newCat = new ExpandoObject(); newCat.Name = "Polly"; newCat.Pedigree = new ExpandoObject(); newCat.Pedigree.Breed = "Whatever"; return newCat; } public void SerializeCat() { new JSONSerializer().Serialize(MakeDynamicCat()); } }

    Read the article

  • Does Powershell have an "eval" equivalent? Is there a better way to see a list of properties and val

    - by glenatron
    I'm doing a bit of Powershell scripting ( for the first time ) to look at some stuff in a Sharepoint site and what I would like to be able to do is to go through a list of properties of an object and just output their values in a "property-name = value" kind of format. Now I can find the list of elements using this: $myObject | get-member -membertype property Which will return a list of all the properties in a very clear and readable fashion. But what I need is to find a value for those properties. In some scripting languages I could have a kind of eval( "$myObject.$propertyName" ) call - where I have extracted $propertyName from the get-member output - and have it evaluate the string as code, which for the kind of quick-and-dirty solution I need would be fine. Does this exist in Powershell or is there a more convenient way to do it? Should I be using reflection instead?

    Read the article

  • Can I programatically get hold of the Autos/local variables that is shown when debugging?

    - by Stefan
    Im trying to build an error-logger that loggs running values that is active in the function that caused the error. (just for fun so its not a critical problem) When going in break-mode and looking at the locals-tab and autos-tab you can see all active variables (name, type and value), it would be useful to get hold of that for logging purposes when an error occur and on some other occasions. For my example, I just want to find all local variables that are of type string and integer and store the name and value of them. Is this possible with reflection? Any tips or pointers that get me closer to my goal would be very appreciated. I have toyed with using expression on a specifik object (a structure) to create an automapper against a dataset, but I have not done anything like what I ask for above, so please make me happy and say its possible. Thanks.

    Read the article

  • Need to call COM component using reflections in C#.NET

    - by Usman
    Hello, I need to determin the COM component(unmanaged code) type and invoke the exposed interface's methods using reflection in C#.NET at runtime. 1 -- First What member of "Type" tells that type is COM component and we can take CLSID at runtime? Is Type.COMObject? 2 -- I need to call methods of exposed interfaces as they called in unmanaged code using CoCreateInstance by passing CLSID and REFID ... I am using InvokeMember but it returns null or 0 as out parameter. How to pass out parameter in this case.? Is there any need to pass out parameter? As all my COM unamanged code suppose to take las parameter as an OUT parameter and after executing it puts the result into that out param. But I've converted all my unmanged COM code to .NET managed assemblies using tlbimp.exe. Regards Usman

    Read the article

  • Java getMethod with superclass parameters in method

    - by Jonathon
    Given: class A { public void m(List l) { ... } } Let's say I want to invoke method m with reflection, passing an ArrayList as the parameter to m: List myList = new ArrayList(); A a = new A(); Method method = A.class.getMethod("m", new Class[] { myList.getClass() }); method.invoke(a, Object[] { myList }); The getMethod on line 3 will throw NoSuchMethodException because the runtime type of myList is ArrayList, not List. Is there a good generic way around this that doesn't require knowledge of class A's parameter types?

    Read the article

  • C# Printing Properties

    - by Mark
    I have a class like this with a bunch of properties: class ClassName { string Name {get; set;} int Age {get; set;} DateTime BirthDate {get; set;} } I would like to print the name of the property and it's value using the value's ToString() method and the Property's name like this: ClassName cn = new ClassName() {Name = "Mark", Age = 428, BirthData = DateTime.Now} cn.MethodToPrint(); // Output // Name = Mark, Age = 428, BirthDate = 12/30/2010 09:20:23 PM Reflection is perfectly okay, in fact I think it is probably required. I'd also be neat if it could somehow work on any class through some sort of inheritance. I'm using 4.0 if that matters.

    Read the article

  • how iterate over class members java (app-engine)

    - by Alexandre H. Tremblay
    Hello, I am using the java version of the google app engine. I would like to create a function that can receive as parameters many types of objects. I would like to print out the members of the object. Each objects may be different and the function must work for all objects. Do I have to use reflection - if so, what kind of code do I need to write? public class dataOrganization { private String name; private String contact; private PostalAddress address; public dataOrganization(){} } public int getObject(Object obj){ // This function prints out the name of every // member of the object, the type and the value // In this example, it would print out "name - String - null", // "contact - String - null" and "address - PostalAddress - null" } How would I write the function getObject?

    Read the article

  • 2D Gaming - How to reflect a ball off the bat?

    - by sid
    Hi there I am pretty new to XNA & game dev and am stuck at ball reflection. My ball is reflecting once it hits the bat, but only in one angle, no matter which angle the bat is at. Here's the code: if (BallRect.Intersects(BatRect)) { Vector2 NormBallVelocity = Ball.velocity; NormBallVelocity.Normalize(); NormBallVelocity = Vector2.Reflect(Ball.velocity, NormBallVelocity); Ball.velocity = NormBallVelocity; } The ball is retracting its way back. How do I make it look like the ball is reflecting off the bat? I have seen other posts but they are on 3D front I am too new to translate it to 2D terms... Thanks Sid

    Read the article

  • Resolving the metadata token of a generic type parameter

    - by 280Z28
    Is there any way the .NET 4.0 (or earlier) reflection API to resolve a generic type parameter? See the two lines after my ArgumentException comment for my current attempt. [TestMethod] public void TestGenericParameterTokenResolution() { Type genericParameter = typeof(List<>).GetGenericArguments()[0]; Assert.IsTrue(genericParameter.IsGenericParameter); int metadataToken = genericParameter.MetadataToken; // make sure the metadata token is a GenericParam Assert.AreEqual(metadataToken & 0xFF000000, 0x2A000000); Module module = typeof(List<>).Module; // the following both throw an ArgumentException. Type resolvedParameter = module.ResolveType(metadataToken); resolvedParameter = (Type)module.ResolveMember(metadataToken); Assert.AreSame(genericParameter, resolvedParameter); }

    Read the article

  • check for naming convention in java.

    - by Vivart
    through java reflection how to check that method name is in camelCase? e.g. import java.lang.reflect.*; public class TestClass { private int simpleMethod( Object p, int x) throws NullPointerException { if (p == null) throw new NullPointerException(); return x; } public static void main(String args[]) { try { Class cls = Class.forName("method1"); Method methlist[] = cls.getDeclaredMethods(); for (int i = 0; i < methlist.length; i++) { Method m = methlist[i]; System.out.println("name= " + m.getName()); } } catch (Throwable e) { System.err.println(e); } } } here i am getting method names simpleMethod and main i have to check that these names are in camelCase.

    Read the article

  • OpenGL render vs. own Phong Illumination Implementation

    - by Myx
    Hello: I have implemented a Phong Illumination Scheme using a camera that's centered at (0,0,0) and looking directly at the sphere primitive. The following are the relevant contents of the scene file that is used to view the scene using OpenGL as well as to render the scene using my own implementation: ambient 0 1 0 dir_light 1 1 1 -3 -4 -5 # A red sphere with 0.5 green ambiance, centered at (0,0,0) with radius 1 material 0 0.5 0 1 0 0 1 0 0 0 0 0 0 0 0 10 1 0 sphere 0 0 0 0 1 The resulting image produced by OpenGL. The image that my rendering application produces. As you can see, there are various differences between the two: The specular highlight on my image is smaller than the one in OpenGL. The diffuse surface seems to not diffuse in the correct way, resulting in the yellow region to be unneccessarily large in my image, whereas in OpenGL there's a nice dark green region closer to the bottom of the sphere The color produced by OpenGL is much darker than the one in my image. Those are the most prominent three differences that I see. The following is my implementation of the Phong illumination: R3Rgb Phong(R3Scene *scene, R3Ray *ray, R3Intersection *intersection) { R3Rgb radiance; if(intersection->hit == 0) { radiance = scene->background; return radiance; } R3Vector normal = intersection->normal; R3Rgb Kd = intersection->node->material->kd; R3Rgb Ks = intersection->node->material->ks; // obtain ambient term R3Rgb intensity_ambient = intersection->node->material->ka*scene->ambient; // obtain emissive term R3Rgb intensity_emission = intersection->node->material->emission; // for each light in the scene, obtain calculate the diffuse and specular terms R3Rgb intensity_diffuse(0,0,0,1); R3Rgb intensity_specular(0,0,0,1); for(unsigned int i = 0; i < scene->lights.size(); i++) { R3Light *light = scene->Light(i); R3Rgb light_color = LightIntensity(scene->Light(i), intersection->position); R3Vector light_vector = -LightDirection(scene->Light(i), intersection->position); // calculate diffuse reflection intensity_diffuse += Kd*normal.Dot(light_vector)*light_color; // calculate specular reflection R3Vector reflection_vector = 2.*normal.Dot(light_vector)*normal-light_vector; reflection_vector.Normalize(); R3Vector viewing_vector = ray->Start() - intersection->position; viewing_vector.Normalize(); double n = intersection->node->material->shininess; intensity_specular += Ks*pow(max(0.,viewing_vector.Dot(reflection_vector)),n)*light_color; } radiance = intensity_emission+intensity_ambient+intensity_diffuse+intensity_specular; return radiance; } Here are the related LightIntensity(...) and LightDirection(...) functions: R3Vector LightDirection(R3Light *light, R3Point position) { R3Vector light_direction; switch(light->type) { case R3_DIRECTIONAL_LIGHT: light_direction = light->direction; break; case R3_POINT_LIGHT: light_direction = position-light->position; break; case R3_SPOT_LIGHT: light_direction = position-light->position; break; } light_direction.Normalize(); return light_direction; } R3Rgb LightIntensity(R3Light *light, R3Point position) { R3Rgb light_intensity; double distance; double denominator; if(light->type != R3_DIRECTIONAL_LIGHT) { distance = (position-light->position).Length(); denominator = light->constant_attenuation + light->linear_attenuation*distance + light->quadratic_attenuation*distance*distance; } switch(light->type) { case R3_DIRECTIONAL_LIGHT: light_intensity = light->color; break; case R3_POINT_LIGHT: light_intensity = light->color/denominator; break; case R3_SPOT_LIGHT: R3Vector from_light_to_point = position - light->position; light_intensity = light->color*( pow(light->direction.Dot(from_light_to_point), light->angle_attenuation)); break; } return light_intensity; } I would greatly appreciate any suggestions as to any implementation errors that are apparent. I am wondering if the differences could be occurring simply because of the gamma values used for display by OpenGL and the default gamma value for my display. I also know that OpenGL (or at least tha parts that I was provided) can't cast shadows on objects. Not that this is relevant for the point in question, but it just leads me to wonder if it's simply display and capability differences between OpenGL and what I am trying to do. Thank you for your help.

    Read the article

  • adhoc struct/class in C#?

    - by acidzombie24
    Currently i am using reflection with sql. I find if i want to make a specialize query it is easiest to get the results by creating a new class inheriting from another and adding the 2 members/columns for my specialized query. Then due to reflections in the lib in my c# code i can write foreach(var v in list) { v.AnyMember and v.MyExtraMember) Now instead of having the class scattered around or modifying my main DB.cs file can i define a class inside a function? I know i can create an anonymous object by writing new {name=val, name2=...}; but i need a to pass this class in a generic function func(query, args);

    Read the article

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