|
you want to download the javascript ?
|
|
|
|
|
No, i want see full HTML after work all script. When user see on screen after load. In my example it`s online-shop and price maked JS. I see true price on screen, but other price in wb.Document.Body.OuterHtml or other method. In developer tools Chrome is all OK
|
|
|
|
|
We have 2 files with settings in them.
The first is a constants file that has all kinds of data in it:
public struct General
{
public static float FAIL_CODE = -999999;
public static int BayPort = 0xc000;
}
public struct Thermal
{
public static float Gi = 1;
public static float Gv = 4.0875f;
public static int Resistance = 1;
public static int Temp = 0;
}
public struct BlisterMotor
{
public static uint MIN_BLISTER_POSITION = 0;
public static uint MAX_BLISTER_POSITION = 56250;
}
The other is an embedded xml file resource:
<Parameter>
<Name>Effector</Name>
<Value>150</Value>
</Parameter>
<Parameter>
<Name>SampleHeaterSetPoint</Name>
<Value>66</Value>
</Parameter>
<Parameter>
<Name>SampleHeaterSamples</Name>
<Value>18</Value>
</Parameter>
We want to make all of this user editable with a UI, so I want to serialize all of them to XML.
I'm trying to find a way to do this with generics, so...
public class Setting<T>
{
public T SettingValue { get; set; }
public T MinValue { get; set; }
public T MaxValue { get; set; }
public string Key { get; set; }
public string Description { get; set; }
}
Then a class to hold all of them:
public List<Setting> MySettings { get; set; }
But this won't compile because the Setting class in the List<> requires a type argument.
But I don't see how this would work with generics. That really only leave overriding the base class with a different type for each:
public List<SettingBase> MySettings { get; set; }
public class SettingBase
{
public string Key { get; set; }
public string Description { get; set; }
}
public class SettingInt : SettingBase
{
public int SettingValue { get; set; }
public int MinValue { get; set; }
public int MaxValue { get; set; }
}
public class SettingDouble : SettingBase
{
public double SettingValue { get; set; }
public double MinValue { get; set; }
public double MaxValue { get; set; }
}
Anyone have a better idea?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Too fine-grained / over-engineered. When you start "coding against it", you will know what I mean (and as you are already experiencing).
Just use a single class with all your "parm properties"; serialize / deserialize that; and bind selected parts to one or more "views" based on context.
You can even have different "instances" of your "parm class" for test vs production; etc.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
One of the best answers I've read!
Regards,
Rob Philpott.
|
|
|
|
|
wow ... this is also my preferred approach for settings: serializing / deserializing a composed object to XML, like a tree. Each component can have indeed its GUI view - a property grid or conventional GUI elements ... (btw, I upvoted your answer ...)
|
|
|
|
|
Thank you!
And each "property" of the "parm class" can have "intelligence"; versus what amounts to "name / value" pairs.
I've swung to adding many "getters" to my classes to simplify running "Fahrenheit versus Centigrade"; 3rd party test versus production credentials; "automatic" units conversion; "Developer / back door" mode; etc.
The "getters" know what context they are running under and return the appropriate values.
One's code starts to look like pseudo-english and becomes very robust (.IsXxxx; .HasXxxx; etc).
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Just off the top of my head:
public abstract class SettingBase
{
public string Key { get; set; }
public string Description { get; set; }
}
public abstract SettingBase<T> : SettingBase
{
public T SettingValue { get; set; }
public T MinValue { get; set; }
public T MaxValue { get; set; }
}
public class SettingDouble : SettingBase<double>
{
}
public class SettingInt : SettingBase<int>
{
}
...
public List<SettingBase> MySettings { get; set; } This doesn't remove the need for your base classes, but it does remove some of the duplication you have in your codebase.
This space for rent
|
|
|
|
|
Works great! Thanks Pete
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
No problem. Glad I could help.
This space for rent
|
|
|
|
|
Ah, the reason I like coding against interfaces instead of abstracts!
I've used this for getters before, but not setters, so that bit is a little up to you. The setter implementation isn't exactly tested.
public interface ISetting
{
object SettingValue { get; set; }
object MinValue { get; set; }
object MaxValue { get; set; }
string Key { get; set; }
string Description { get; set; }
}
public class Setting<T> : ISetting
{
public T SettingValue { get; set; }
public T MinValue { get; set; }
public T MaxValue { get; set; }
public string Key { get; set; }
public string Description { get; set; }
object ISetting.SettingValue
{
get => SettingValue;
set {
var xlate = value as T;
if(xlate != null)
{
SettingValue = t;
}
else
{
throw new Exception($"Invalid type assignment for Setting<{typeof(T)}>.SettingValue ");
}
}
}
object ISetting.MinValue
{
get => MinValue;
set {
var xlate = value as T;
if(xlate != null)
{
MinValue = t;
}
else
{
throw new Exception($"Invalid type assignment for Setting<{typeof(T)}>.MinValue");
}
}
}
object ISetting.MaxValue
{
get => MaxValue;
set {
var xlate = value as T;
if(xlate != null)
{
MaxValue= t;
}
else
{
throw new Exception($"Invalid type assignment for Setting<{typeof(T)}>.MaxValue");
}
}
}
}
public List<ISetting> MySettings { get; set; }
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
var xlate = value as T;
This won't work with his struct types. Have to use is or .GetType() and then a hard cast to T .
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Thanks, I just threw the setter portion together without much thought or coffee; it's not in my usual use case.
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
Kevin Marois wrote:
Anyone have a better idea? The Newtonsoft serializer has no problems with that stucture. Does it have to be XML? And if so, what advantages do you expect from it versus JSON?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Not sure if I'm looking this correctly, but it seems that you only have key/value pairs perhaps with categorization.
So if the goal is only to let the user edit the values in UI and save them, why not define a data table and load/save it in order to persist the changes. For example, have a look at DataTable.ReadXml Method (String) (System.Data)
|
|
|
|
|
See my previous post
Now in the base class I want to add a method that return all Data Types that match the generic type:
public List<DataType<T>> GetTypes(T typeToGet)
{
return DataTypes.Where(x => x.ConvestionType == typeToGet).ToList();
}
but this fails to compile on the "x.ConvestionType == typeToGet".
The error is "Operator '==' cannot be applied to operands of type 'T' and 'T'".
Not sure why this doesn't work. The 'typeToGet' param is of the same type as the class. What's wrong here?
Thanks!
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Yes you cannot use == on instances of fully generic types. == may not exist for all value types for example, and even if it did, it would exist in a way that is not useful in the context of generics.
For example,
static bool equals<T>(T a, T b)
{
return a == b;
}
This doesn't work either. But this does: (using fairly rare syntax to constraint T to be a reference type, will use reference-equality regardless of how appropriate that is)
static bool equals<T>(T a, T b) where T : class
{
return a == b;
}
Other methods of comparison may be more suitable, for example:
static bool equals<T>(T a, T b)
{
return EqualityComparer<T>.Default.Equals(a, b);
}
|
|
|
|
|
Thanks! Ya learnt me somethin!
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
I'm trying to create a generic abstract class:
The base class:
public abstract class DotNetlTypeConverterBase<T>
{
private List<DataType<T>> _dataTypes;
public List<DataType<T>> DataTypes
{
get { return _dataTypes; }
private set { _dataTypes = value; }
}
public DotNetlTypeConverterBase()
{
DataTypes = new List<DataType<T>>();
Load();
}
protected abstract void Load();
public class DataType<T>
{
public DotNetTypes DotNetType { get; private set; }
public T ConvestionType { get; private set; }
public DataType(DotNetTypes dotNetType, T convestionType)
{
DotNetType = dotNetType;
ConvestionType = convestionType;
}
}
}
A subclass:
public class DotNetToSqlTypeConverter<SqlDbType> : DotNetlTypeConverterBase<SqlDbType>
{
protected override void Load()
{
DataTypes.Add(new DataType<SqlDbType>(DotNetTypes.Short, SqlDbType.SmallInt));
DataTypes.Add(new DataType<SqlDbType>(DotNetTypes.Double, SqlDbType.Double));
}
}
In the subclass I get a compile error on second param to the ctor of DataType. The word "SqlDbType" is erroring, yet that's the type I've specified.
The error is "'SqlDbType' is a type parameter, which is not valid in the given context"
What am i doing wrong here?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
modified 31-Oct-17 11:24am.
|
|
|
|
|
This:
public class DotNetToSqlTypeConverter<SqlDbType> ..overrides the meaning of SqlDbType as the enumeration type - it's now a generic type name, like T in the base class.
You could fix that theoretically by doing this:
public class DotNetToSqlTypeConverter<SqlDbType> : DotNetlTypeConverterBase<System.Data.SqlDbType>
{
protected override void Load()
{
DataTypes.Add(new DataType<System.Data.SqlDbType>(DotNetTypes.Short, System.Data.SqlDbType.SmallInt));
DataTypes.Add(new DataType<System.Data.SqlDbType>(DotNetTypes.Double, System.Data.SqlDbType.Float));
}
} But you don't actually want that. Instead change the class to being non-generic:
public class DotNetToSqlTypeConverter : DotNetlTypeConverterBase<SqlDbType>
{
protected override void Load()
{
DataTypes.Add(new DataType<SqlDbType>(DotNetTypes.Short, SqlDbType.SmallInt));
DataTypes.Add(new DataType<SqlDbType>(DotNetTypes.Double, SqlDbType.Float));
}
}
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
That did it!
I'm getting old. Totally missed that
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
I want to create a WPF dll( assembly),so that I can use it in some other C# or VC++ application.
Please help.
|
|
|
|
|
Why does it have to be a WPF dll, the only reason to use WPF is for the UI, probably not valid to use such a DLL in c++.
Otherwise just create a WPF library application.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
You will have to describe what you want your assembly to contain before you get a definitive answer. There are a number of assumptions that I could make about what you want here that possibly wouldn't be valid. For instance, do you want it to contain WPF screens? Does it just need to be the data and business logic?
This space for rent
|
|
|
|
|
Open VS.
Either open your existing solution and use the Solution Explorer pane to add a new project, or create a new project.
Select the "Visual C#" ... "Windows Desktop" project types from the menu on the left of the New Project dialog.
In the middle panel, select "WPF User Control Library"
Give it an appropriate name.
Press OK.
Now you can create the controls and code for your Assembly.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|