0

//ここにいくつかのコード

    object target = Activator.CreateInstance(typeof(T));   

    PropertyInfo[] sourceProperties = sourceType.GetProperties();

    foreach (PropertyInfo pi in sourceProperties)
    {
         PropertyInfo targetPi = typeof(T).GetProperty(pi.Name); //returns null why?

         object piValue = pi.GetValue(source, null);

         try
         {
               if (targetPi != null)   // it doesnt work 
               {
                    targetPi.SetValue(target,piValue, null); // target has typeof(T)
               }
         }
         catch { }         
    }
    return(T)target;
}
4

1 に答える 1