Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7020629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:20:34+00:00 2026-05-27T23:20:34+00:00

I have come across a slight issue with my class design and I am

  • 0

I have come across a slight issue with my class design and I am having trouble with dealing with it. Having searched the web to no avail I am hoping someone here would be kind enough to point me in the right direction. I have posted the entire code so in theory, should be able to do a simple copy and paste in VS and visualise the error.

Thanks in advance, Onam.

Full error:
The type ‘Complainant’ cannot be used as type parameter ‘T’ in the generic type or method ‘Person’. There is no implicit reference conversion from ‘Complainant’ to ‘ObjectFactory’.

#region : Complainant :
public class Complainant : Person<Complainant>
{
    #region Properties...

    #region ComplainantId
    public Int64 ComplainantId { get; private set; }
    #endregion

    #region IsApproachable
    public bool IsApproachable { get; set; }
    #endregion

    #endregion

    #region Constructors...
    public Complainant()
    {
    }
    #endregion

    #region Methods...

    #region Load
    public void Load(Int64 objectId)
    {
        base.Hydrate(objectId);
    }
    #endregion

    #endregion
}
#endregion

#region : Person :
public class Person<T> : ObjectFactory<T>
{
    #region Properties...

    #region PersonId
    public Int64 PersonId { get; protected set; }
    #endregion

    #region DOB
    public DateTime DOB { get; set; }
    #endregion

    #region Email
    public string Email { get; set; }
    #endregion

    #region Forename
    public string Forename { get; set; }
    #endregion

    #region Fullname
    public string Fullname { get { return Forename + " " + Surname; } }
    #endregion

    #region HomeTel
    public string HomeTel { get; set; }
    #endregion

    #region Initials
    public string Initials { get; set; }
    #endregion

    #region Mobile
    public string Mobile { get; set; }
    #endregion

    #region Surname
    public string Surname { get; set; }
    #endregion

    #region WorkTel
    public string WorkTel { get; set; }
    #endregion

    #endregion

    #region Constructor
    public Person()
    {
    }
    #endregion
}
#endregion

#region : Property :
public class Property
{
    #region Properties...

    #region Inherits
    [XmlAttribute("Inherits")]
    public string Inherits { get; set; }
    #endregion

    #region IsPrimaryKey
    [XmlAttribute("IsPrimaryKey")]
    public bool IsPrimaryKey { get; set; }
    #endregion

    #region Name
    [XmlAttribute("Name")]
    public string Name { get; set; }
    #endregion

    #endregion

    #region Constructors...

    public Property(string name, bool isPrimaryKey)
    {
        this.Name = name;
        this.IsPrimaryKey = isPrimaryKey;
    }

    public Property()
    {
    }

    #endregion

    #region Methods


    #endregion
}
#endregion

#region : ObjectFactory :
public class ObjectFactory<T> where T : new()
{
    #region Members...
    static Expression<Func<T>> __x = () => new T();
    static Func<T> __function = __x.Compile();
    static Dictionary<Type, List<Property>> __cache = new Dictionary<Type, List<Property>>();
    #endregion

    #region Constructors
    public ObjectFactory()
    {
        Type _type = typeof(T);

        if (!__cache.ContainsKey(_type))
        {
            __cache.Add(_type, Deserialize(_type.Name));
        }
    }
    #endregion

    #region Methods

    #region Build
    public static T Build()
    {
        return __function();
    }
    #endregion

    #region Deserialize
    private List<Property> Deserialize(string objectName)
    {
        XmlSerializer _serializer = new XmlSerializer(typeof(List<Property>));
        using (Stream _stream = File.OpenRead(String.Format(@"C:\_XMLFiles\{0}.xml", objectName)))
        {
            return (List<Property>)_serializer.Deserialize(_stream);
        }
    }
    #endregion

    #region Hydrate
    protected void Hydrate(Int64 objectId)
    {
        List<Property> _properties = new List<Property>();

        if (__cache.TryGetValue(typeof(T), out _properties))
        {
            object[] o = typeof(T).GetProperties();
            foreach (PropertyInfo pi in typeof(T).GetProperties())
            {
                string s = pi.Name;
                //if (pi.Name == name)
                //{
                    //pi.SetValue(this, value, null);
                //}
            }
        }
    }
    #endregion

    #endregion
}
#endregion
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:20:35+00:00Added an answer on May 27, 2026 at 11:20 pm

    I’m not 100% sure if this is the reason – but you should maintain the generic parameter constraints on the Person<T> class. So add the where T : new() to the Person<T> class.

    EDIT

    After compiling your code, I get the error:

    Error 1 ‘T’ must be a non-abstract type with a public parameterless constructor in order to use it as parameter ‘T’ in the generic type or method ‘Reflection.ObjectFactory’ SomeClass.cs 67 18 Reflection

    This error is solved by the addition of the where clause I mentioned above. After that point, I get no compilation errors.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have come across a class which is non-static, but all the methods and
I have come across code in the form: MyClass.class.getName(); Is .class a property? Is
I have come across this issue a few times now, and each time I
I have come across a very strange issue in python. (Using python 2.4.x) In
I'm learning Silverlight for WP7 and have come across a slight problem: I want
I have come across a strange behavior... In class A, at the viewDidLoad method
I have come across a lot of optimization tips which say that you should
I have come across the following type of code many a times, and I
I have come across what must be a common problem. When I have an
We have come across a scenario where we need to track the setting and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.