Is there any way to implement abstract validator for something like this?
public class AddOrUpdateMeasurementCommandValidator : AbstractValidator<AddOrUpdateMeasurementCommand<MainMeasurement>>
// or more precise
public class AddOrUpdateMeasurementCommandValidator<T> : AbstractValidator<AddOrUpdateMeasurementCommand<T>> where T : MainMeasurement
Model looks like this :
ChoiceMeasurement : MainMeasurement
TrueOrFalseMeasurement : MainMeasurement
TextMeasurement : MainMeasurement
public class AddOrUpdateMeasurementCommand<T> : ICommand where T : MainMeasurement
in code there is called by this :
var command = new AddOrUpdateMeasurementCommand<NumericMeasurement>
{
// values
};
_serviceTools.CommandBus.SendCommand(command);
Related
Please see the code below:
public partial class MyContentPage : ContentPage
{
public CreditCardView()
{
InitializeComponent();
}
}
It works as expected. Now say I want to inject a dependancy:
public partial class MyContentPage : ContentPage
{
private readonly IMyService _myService;
public CreditCardView(IMyService myService)
{
InitializeComponent();
_myService=myService;
}
}
With the second excerpt of code I see a compilation error: "The given key was not present in the dictionary". What is the problem? I have registered the dependancy.
I have the following classes contained by Geography.framework (a Swift framework project):
public class Contact : NSObject
{
public static let Table: String = "contacts"
public class Fields : NSObject
{
public static let Id: String = "_id"
public static let Name: String = "name"
static let rawId: String = "rawId"
}
}
public class Country : NSObject
{
public class Fields : NSObject
{
public static let Id: String = "_id"
public static let Prefix: String = "prefix"
static let rawId: String = "rawId"
}
}
In my swift app using this framework everything works smoothly:
import geography
func setFields()
{
var contactName:String = Contact.Fields.Name
var countryPrefix:String = Country.Fields.Prefix
var contactsTable: String = Country.Table
}
Well, if I use the same Geography.framework in ObjectiveC, I see Contact and Country class but the nested classes Fields are not seen. Also the value of Contact.Table is not seen.
What I need to do in order to have same library structure and library usage in ObjectiveC?
Thank you,
You have to be explicit here with definition for ObjC.
public class Country: NSObject {
#objc(CountryFields) public class Fields: NSObject {
// ...
}
}
This should expose your Switf's Country.Fields for your ObjC as CountryFields. I haven't tested it but I believe you don't have to be explicit about inheriting from NSObject. #objc attribute should do it for you when compiling.
Update for Swift 3:
Looks like this was broken in Swift 3 and won't be fixed. https://bugs.swift.org/browse/SR-2267?focusedCommentId=21033&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-21033
You can use a trick with typealias to have the same syntax when using it :
public class Contact : NSObject
{
public static let Table: String = "contacts"
typealias Fields = ContactFields
}
#objcMembers
public class ContactFields : NSObject
{
public static let Id: String = "_id"
public static let Name: String = "name"
static let rawId: String = "rawId"
}
public class Country : NSObject
{
typealias Fields = CountryFields
}
#objcMembers
public class CountryFields : NSObject
{
public static let Id: String = "_id"
public static let Prefix: String = "prefix"
static let rawId: String = "rawId"
}
Is it possible to create a simple convention to modify the polymorphism mode of a class, if there is a joined-subclass ?
Doing this :
public class EntityMap : ClassMap<EntityBase>
{
public EntityMap()
{
Polymorphism.Explicit();
}
}
but inside a convention. Using IClassConvention doesn't work, as the Polymorphism property is read only :
public class TestConvention : IClassConvention
{
public void Apply(IClassInstance instance)
{
// read only property !
instance.Polymorphism = Polymorphism.Explicit;
}
}
Try
instance.Polymorphism.Explicit();
Is it possible to do inheritance with NHibernates component? A quick google returned only a hand full of appropriate results (all blogs) and all were written some time ago so was wondering if it is available yet?
if not how do you handle it instead?
It's not currently possible. If you need inheritance, you have to map an entity.
In addition to what Diego had said, there is also an option to implement custom hydration/dehydration for hierarchy using IUserType. See this article for details (its Java but the same mechanism can be used in C#).
And Hibernate feature request is here. NHibernate version is here, please vote.
Yes.
public class A { }
public class B : A { }
public sealed class C : B { }
public abstract class BaseAMap<T> : ComponentMap<T> where T : A {
public BaseAMap() {
// Map A here
}
}
public class AMap : BaseAMap<A> {
}
public class BaseBMap<T> : BaseAMap<T> where T : B {
public BaseBMap () {
// Map B (excluding A)
}
}
public class BMap : BaseBMap<B> {
}
public sealed class CMap : BaseBMap<B> {
public CMap () {
// Map C (excluding B)
}
}
I have an abstract class as follow:
class BaseReturnType { }
class DerivedReturnType : BaseReturnType { }
abstract class BaseClass<T> where T : BaseReturnType
{
public abstract T PolymorphicMethod();
}
class DerivedClass : BaseClass<DerivedReturnType>
{
public override DerivedReturnType PolymorphicMethod()
{
return new DerivedReturnType();
}
}
So if add exta parrameter for Generic called T2 how do I put extrac constraining on this?
abstract class BaseClass<T, **T2**> where T : BaseReturnType ???
{
public abstract T PolymorphicMethod();
}
abstract class BaseClass<T, **T2**> where T : BaseReturnType where T2 : BaseTypeForT2
{
public abstract T PolymorphicMethod();
}
as per here.