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

  • SEARCH
  • Home
  • 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 4105918
In Process

The Archive Base Latest Questions

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

See the following code. The test passed when using AutoMapper, but failed when using

  • 0

See the following code. The test passed when using AutoMapper, but failed when using ValueInjecter:

using NetFwTypeLib;

[TestClass]
public class UnitTest1
{
    [TestMethod]
    public void TestMethod1()
    {
        INetFwPolicy2 policy = (INetFwPolicy2)Activator.CreateInstance(
                Type.GetTypeFromProgID("HNetCfg.FwPolicy2"));
        INetFwRules fwRules = policy.Rules;
        Rule rule = new Rule();

        foreach (INetFwRule fwRule in fwRules)
        {
            if (fwRule.Name == "HomeGroup Out")
            {
                //AutoMapper.Mapper.CreateMap<INetFwRule, Rule>();
                //AutoMapper.Mapper.Map(fwRule, rule);
                rule.InjectFrom(fwRule);
                break;
            }
        }
        Assert.IsTrue(rule.Name == "HomeGroup Out");
    }
}

public class Rule
{
    public string Name { get; set; }
}

Any ideas? Thanks.

Edit:

Based on Omu’s answer, it seems the problem is related to COM objects, not only FirewallAPI.dll classes. So I changed title from “Can’t get ValueInjecter to map FirewallAPI.dll classes” to “Can’t get ValueInjecter to map COM objects“.

  • 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-20T21:18:35+00:00Added an answer on May 20, 2026 at 9:18 pm

    it doesn’t work because doing:

    fwRule.GetType().GetProperties().Count()// is 0 
    

    or doing the same using PropertyDescriptor also return zero, it’s like the object doesn’t has properties

    the solution is to write an injection that will take the type from where to get the properties:

    public class Same<T> : ValueInjection
    {
       protected override void Inject(object source, object target)
       {
           var props = typeof (T).GetInfos().ToArray();
           var tp = target.GetInfos().ToArray();
           for (var i = 0; i < props.Count(); i++)
           {
              var prop = props[i];
              for (var j = 0; j < tp.Count(); j++)
              {
                if(prop.Name == tp[j].Name && prop.PropertyType == tp[j].PropertyType)
                tp[j].SetValue(target,prop.GetValue(source, null),null);
              }
            }
          }
      }
    

    and the usage:

    rule.InjectFrom<Same<INetFwRule>>(fwRule);
    

    this is the same as the default InjectFrom() but it reads the target properties from the supplied Type

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

Sidebar

Related Questions

I have following code class Test { public: int &ref; int a; Test(int &x)
Please see the following code: #include <iostream> #include <string> using namespace std; enum dataType
(resolved: see bottom) I have the following code snippet: Protected Sub SqlDataSource1_Inserted(ByVal sender As
I see lots of TDD practitioners following this cycle: 1) Write your test as
I see in a header that I didn't write myself the following: class MonitorObjectString:
From time to time I see an enum like the following: [Flags] public enum
The following code is a test to test what I have already done with
The following code waits for data over UDP. I have a test function that
I'm trying to test the following code : http://github.com/mobilemelting/nvpolyline . When I run the
I have the following code in a stand-alone Cocoa test app: - (void)applicationDidFinishLaunching:(NSNotification *)aNotification

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.