Thank you for the link, although it seems what I need to achieve cannot be done - at least not with C#. Looks like I have to save the function definition in an attribute. D'oh
ezazazel
Posts
-
Possible to print definition of Func<> -
Possible to print definition of Func<>Hi fellows, a question from my side again! Would really need your expertise! Is therer a way (maybe with Reflection) to get the definition of a Function? Description: I have a self defined Function (yeah I know dynamic, but here it's really neccessary, would take too long to explain):
dynamic func = new Func((int i)=>{return 2*i;});
Chance to get to display the part {return 2*i;} programatically? (something like
MessageBox.Show("Function Code: {0}", functionCode);
(int i)=>{return 2*i;} would be fine as well, just if it makes any difference :-D Thank's in advance!
-
Passing object[] Elements as Parameters to Invoke()Thank you! Seems to work (just tried it with a short piece of code - going to check it within my project later).
-
Passing object[] Elements as Parameters to Invoke()Hi guys! Maybe anyone can help me with this: I have a object[] with values e.g.:
object[] obj = new object[]{"a",1};
Furthermore I have a dynamic method which is in reality for example a
Func function;
Is there a way to use the values of the object[] as parameters for the function? Or how can I invoke the method with the values from the object[]? ----------------- Why is this needed? I have classes which store Func<1..n> within a dynamic property e.g.
class A
public dynamic Algorithm;
Algorithm = new System.Func((x,y) => { return x + y; });class B
public dynamic Algorithm;
Algorithm = new System.Func((x,y) => { return x / y * z; });. By iterating through MethodInfo[] I get
Type inputType = parameter.ParameterType;
Type returnType = member.ReturnType;and can therefore create my UI. Now I can create objects out of this by using the Activator
object inputParameterObject = Activator.CreateInstance(inputType);
In the UI I fill in the values.
inputParameterObject1 = a;
inputParameterObject2 = 1;The inputParameterObjects are stored in an object[] Now I need to invoke the Func<1..n> by passing the values from the UI.
Algorithm.Invoke(inputParameterObjectArray);
does not work as it is not equal to
Algorithm.Invoke("a",1);
Or in other words
Algorithm.Invoke(object[]) != Algorithm.Invoke(string,int) || Algorithm.Invoke(object,object)
Help would be appreciated! So long,
-
Animation on ContentPresenter ContenSource ChangedHello! Could anyone please help me with this: XAML:
ViewModel
private UserControl navigation;
public UserControl Navigation{
get {return navigation;}
set {navigation = value; OnPropertyChanged(()=>Navigation);}
}void LoadControl(UserControl control)
{
//control can either be null or typeof(UserControl)
this.Navigation = control;
}What I want to do is create an animation which changes the Width of the ContentPresenter stepwise. If control != null step from 0 => control.Width else step from control.Width => 0 Any ideas how this can be done (can this be done in XAML soley)? Help, as always, would be highly appreciated.
-
Implementation of Generic Method in List<Class>That's pretty cool - thanks your your support. That and your first sample helped me to got it solved. First I used a few reflections for the type passing, but now I think I'm going to make use of your implementation. Thank you again!
-
Implementation of Generic Method in List<Class>As an alternative, is there a chance of storing different kind of functions in a property? Something like Func and Func? Guess it's the same problem,but better asking before throwing the idea over board. Do you have an approach on how this can be achieved? Something that didn't come into my mind? Thank you!
-
Implementation of Generic Method in List<Class>Thanks for the hint but no, this doesn't solve my problem:
public override TResult Calculate (params TInput[] input) // !! public override double Calculate(params int[] input)
{
int[] ints = input as int[];
double result = 0;
foreach (int item in ints) {
result += item;
}return (TResult)result; // !! ErrorMessage: Cannot convert type double to TResult }
-
Implementation of Generic Method in List<Class>Hi guys! I'm dealing with a problem I can't find a solution for. What I'm trying to do is this: I have a Model which should contain a generic method (generic input and return value). And furthermore these Models should be merged into a List. And here it gets complicated and I end up in a dead end. Here's the code which hopefully makes it more clear:
class MainClass
{
public static void Main (string[] args)
{
List containers = new List();
containers.Add(new ContainerA());
containers.Add(new ContainerB());} } abstract class ContainerBase { public string Name { get; set; } public abstract TResult Calculate(params TInput\[\] input); } class ContainerA : ContainerBase { #region implemented abstract members of Generics.ContainerBase public override TResult Calculate (params TInput\[\] input) // !! public override double Calculate(params int\[\] input) { int\[\] ints = input as int\[\]; double result = 0; return result; // !! throws an error return result as TResult; // !! doesn't work either } #endregion } class ContainerB : ContainerBase { #region implemented abstract members of Generics.ContainerBase public override TResult Calculate (params TInput\[\] input) // !! public override uint Calculate(params uint\[\] input) { throw new System.NotImplementedException (); } #endregion }
This is needed because I want to be able to combine different algorithms (presented by the Model), e.g. Algo 1: combine 3 integers, Algo 2: divide two integers, Algo 3: get the sort via Drag&Drop (in MVVM - hence the unified approach). An Alternative would be to store a whole Metod in a Property in the Model, but it needs to be generic as well. And I have no idea how to do that either. Help would be appreciated!
-
Word Interop Supress / Handle ErrorsHi guys! Am currently writing some code for creating Word files dynamically. Have to embed OLE Objects such as PDFs. This works fine up to the moment where I have a corrupted file which can not be embedded. Used try/catch by the InlineShapes.AddOleObject() Method, but a messagebox is presented and the program stops until I hit ok. Is there a chance to do the errorhandling for this? Thank you in advance!
-
Style.TargetType = Interface || abstract classHi folks! Is it possible to define the targettype of a style to be an interface or an abstract class. Something like this (in pseudo code)
Style s = new Style();
s.TargetType = class where inherit from baseclassor
Style s = new Style();
s.TargetType = class which implements given interfaceThis is needed for creating a generic dragdrop element, where the items in the source can be derived classes. e.g:
abstract class DDItem
{
public T Identifier {get;set;}
public Q DisplayableContent {get;set;}
}/*Doesn't work like that*/
<EventSetter Event="MouseLeftButtonDown" Handler="Drag"/>Would be fine to do this in plain c# as well. Help would be appreciated!
-
How to get value of child control?Do you mean something like this:
<TextBlock Text={Binding Path=Text, ElementName=tbOrderID} IsSynchronizedWithCurrentItem="True"/>
-
Preload ImageSource from URIThat's true, for sure - but as a matter of fact up to now wpf is doing the black magic (inclluding the dispatching), I'm just passing an uri. Can this be done with some sort of lazy loading (heard once of that during a dev training) or other obsurce xaml tags? Or is creating an image out of the uri (including the preloading) and passing it to the xaml as imagesource the better way? Won't the problem keep existing as the dispatcher has to deal with the pictures and their transformation-rotation anyway?
-
Preload ImageSource from URIHi folks! Is there a way to do some preloading of images in WPF? My Image has an URI as source (a URI property implementing INotifyPropertyChanged in the code behind) When I create the URI (points to a network share) and fire the NotifyPropertyChanged Event, my application freezes for a second or two. So how can I preload the image so the applicatio won't freeze? Here's some code: XAML:
And the CB:
public DataContextClass : INotifyPropertyChanged
{
private Uri image_1;
public Uri Image_1
{
get
{
}
set
{
image_1 = value;
PropertyHasChanged("Image_1");
}
}void Timer_Elapsed(object sender, EventArgs e)
{
Image_1 = CreateUri(GetFilePathFromNetworkShare());
}
}Thanks in advance! eza
-
Bind ASP.NET to a property of a classThank you! That did it:
'<%# DataBinder.Eval(DataItem.vm,"TestValue")%>'
and defining
public DefaultVM vm;
-
Bind ASP.NET to a property of a classHi folks! Maybe anyone can help me with this. I'm from WPF world and am used to bind to objects in other classes. I found many examples to bind to lists, but none how to bind to a property of another class. So here's the deal: Default.aspx.cs
private DefaultVM vm;
protected void Page_Load(object sender, EventArgs e)
{
this.vm = new DefaultVm();
}DefaultVM.cs
public int TestValue { get;set;}
public void DefaultVM()
{
TestValue = 10;
}Default.aspx
<asp:Label runat="server" Text='<%# DataBinder.Eval(vm,"TestValue")%>'/>
None of this works. Tried a few other things as well, but without result. What am I doing wrong?
-
ValidationRule bind two valuesHi folks! Can anyone please help me with this: I have two values (one manual input and one from a database) and I need to compare them/ validate them via ValidationRules and show errors if they do not match. LOGIC: V1 == V2 => OK V1 != V2 => NOK, Error
<TextBlock>
<TextBlock.Text>
<Binding ...>
<Binding.ValidationRules>
<localValidation:ValidateIt V1={Binding Path=...} V2={Binding Path=}/>
</Binding.ValidationRules/>
<TextBlock.Text/>
</TextBlock>where
public class ValidateIt : ValidationRule
public int V1 {get;set;}
public int V2 {get;set;}Unfortunately it tells me, that V1 and V2 cannot be bound due to the fact, that these are no DependencyProperties. I'm stuck... Thanks in advance, eza
-
Fast Inserting Values with Linq in a databaseHi guys! Can anyone please help me with this: I have a sdf Database used by LINQ. It is used for error logging. If I have multiple Errors at the same time, logs.ErrorTables.InsertOnSubmit(table); throws an error stating, that this operation is not allowed while SubmitChanges() is still working. How can I avoid this? Here's my code:
public void SetErrorMessage(ErrorMessage message)
{
if (logs == null)
logs = new Logs(@"Data Source=Log\Logs.sdf;Persist Security Info=False;");ErrorTable table = new ErrorTable() { ErrorDate = message.Time, ErrorThrower = message.ErrorThrower, ErrorMessageText = message.ErrorMessageText, ResponsibleDev = message.ResponsibleDev, ErrorPriority = Convert.ToInt32(message.ErrorPriority) }; logs.ErrorTables.InsertOnSubmit(table); logs.SubmitChanges(System.Data.Linq.ConflictMode.FailOnFirstConflict); }
Thanks in advance!
-
Playing with EnumerationsThanks for your reply. I just hoped it would be possible to separate the C2 logic from the UI with the lib B as link.
-
Playing with EnumerationsThanks for the hint, unfortunately I can't do this due to he fact, that lib C wasn't written by me.