Click here to Skip to main content
15,888,968 members
Home / Discussions / C#
   

C#

 
QuestionSound player Pin
Morgs Morgan15-Jan-09 9:50
Morgs Morgan15-Jan-09 9:50 
AnswerRe: Sound player Pin
EliottA15-Jan-09 10:03
EliottA15-Jan-09 10:03 
QuestionServiceControllerInfo Pin
spiritboy15-Jan-09 8:54
spiritboy15-Jan-09 8:54 
AnswerRe: ServiceControllerInfo [modified] Pin
Luc Pattyn15-Jan-09 9:14
sitebuilderLuc Pattyn15-Jan-09 9:14 
GeneralRe: ServiceControllerInfo Pin
spiritboy15-Jan-09 18:57
spiritboy15-Jan-09 18:57 
GeneralEarning While You Learning Pin
purshottam15-Jan-09 7:34
purshottam15-Jan-09 7:34 
GeneralRe: Earning While You Learning Pin
EliottA15-Jan-09 7:42
EliottA15-Jan-09 7:42 
QuestionNeed help with understanding Reflection Pin
madhatter84gn15-Jan-09 7:05
madhatter84gn15-Jan-09 7:05 
I have never used reflection before and I have been tasked with a project to tranform object data into 1 long string for a mainframe. I am trying to use an xml document as a reference for the information need to tranform to the mainframe. Below is an example of 1 element of that XML. What I am trying to accomplish is read in the schema and use reflection to build a string. Below the XML I have what I think is correct, but can not seem to get it working. Any point in the right direction would be great. businessType always comes back null and I can't seem to get the value


<MainframeField>
    <MainframeKeyword>POLNO</MainframeKeyword>
    <MainframeKeywordDescription>Policy Number</MainframeKeywordDescription>
    <BusinessEntityDetails>
      <Namespace></Namespace>
      <EntityName>HealthPlanDetails</EntityName>
      <PropertyName>PolicyNumber</PropertyName>
    </BusinessEntityDetails>
    <MaximumLength>2</MaximumLength>
    <DataType>STRING</DataType>
    <IsRequired>TRUE</IsRequired>
    <TransformationDetails>
      <MainframeTransformationEntity></MainframeTransformationEntity>
      <Namespace></Namespace>
      <MethodToCall></MethodToCall>
      <Inputs>
        <Input></Input>
        <Input></Input>
      </Inputs>
    </TransformationDetails>
  </MainframeField>



Part of my problem is I am not sure how to set the applicationEntity.HealthPlanDetails equal to the object created using reflection to get back the value.
Code:
public static string BuildMainframeString(ApplicationEntity applicationEntity)
       {
           //Load XML from file
           XDocument xmlMainframeOutput = XDocument.Load(@"C:\_XsdGen\Gen\Mainframexml.xml");
           var mainframeOutputs = from mainframeField in xmlMainframeOutput.Descendants("MainframeField")
                                  let mainframeKeyword = mainframeField.Element("MainframeKeyword")
                                  let mainframeKeywordDescription = mainframeField.Element("MainframeKeywordDescription")
                                  let businessEntityProperty = mainframeField.Element("BusinessEntityProperty")
                                  let maximumLength = mainframeField.Element("MaximumLength")
                                  let dataType = mainframeField.Element("DataType")
                                  let isRequired = mainframeField.Element("IsRequired")

                                  let businessEntityDetails = mainframeField.Element("BusinessEntityDetails")
                                  let businessEntityNamespace = businessEntityDetails.Element("Namespace")
                                  let businessEntityName = businessEntityDetails.Element("EntityName")
                                  let businessEntityPropertyName = businessEntityDetails.Element("PropertyName")

                                  let mainframeTransformationDetails = mainframeField.Element("TransformationDetails")
                                  let mainframeTransformationEntity = mainframeTransformationDetails.Element("MainframeTransformationEntity")

                                  let mainframeTransformationNamespace = mainframeTransformationDetails.Element("Namespace")
                                  let mainframeTransformationEntityMethodToCall = mainframeTransformationDetails.Element("MethodToCall")
                                  let inputs = mainframeTransformationDetails.Descendants("Input")

                                  select new
                                  {
                                      MainframeKeyword = mainframeKeyword.Value,
                                      MainframeKeywordDescription = mainframeKeywordDescription.Value,
                                      BusinessEntityNamespace = businessEntityNamespace.Value,
                                      BusinessEntityName = businessEntityName.Value,
                                      BuisnessEntityPropertyName = businessEntityPropertyName.Value,
                                      MaximumLength = maximumLength.Value,
                                      DataType = dataType.Value,
                                      IsRequired = isRequired.Value,
                                      MainframeTransformationEntity = mainframeTransformationEntity.Value,

                                      MainframeTransformationNamespace = mainframeTransformationNamespace.Value,
                                      MainframeTransformationMethodToCall = mainframeTransformationEntityMethodToCall.Value,
                                      Inputs = (from input in inputs
                                                select input.Value).ToList<string>()
                                  };
           StringBuilder mainframeOutputString = new StringBuilder();

           foreach (var mainframeField in mainframeOutputs)
           {
               string businessEntityName = mainframeField.BusinessEntityName;
               string businessEntityNamespace = mainframeField.BusinessEntityNamespace;
               string businessEntityPropertyName = mainframeField.BuisnessEntityPropertyName;

               string mainframeTransformationEntityName = mainframeField.MainframeTransformationEntity;
               string mainframeTransformationMethodToCall = mainframeField.MainframeTransformationMethodToCall;


               if (businessEntityName.Length > 0)
               {
                   Type businessType = Type.GetType(BUSINESS_ENTITY_CLASS_PATH + businessEntityName);
                   PropertyInfo pi = businessType.GetType().GetProperty(businessEntityPropertyName);
                   mainframeOutputString.Append(mainframeField.MainframeKeyword);
                   mainframeOutputString.Append("=");
                   mainframeOutputString.Append(pi.GetValue(businessType, null));
                   mainframeOutputString.Append(";");
               }
               else
               {
                   Type mainframeType = Type.GetType(MAINFRAME_TRANFORMATION_CLASS_PATH + mainframeTransformationEntityName);
                   MethodInfo mi = mainframeType.GetMethod(mainframeTransformationMethodToCall);
                   mainframeOutputString.Append(mainframeField.MainframeKeyword);
                   mainframeOutputString.Append("=");
                   mainframeOutputString.Append(mi.Invoke(mainframeType, null));
                   mainframeOutputString.Append(";");

               }

           }

AnswerRe: Need help with understanding Reflection Pin
Scott Dorman15-Jan-09 7:45
professionalScott Dorman15-Jan-09 7:45 
GeneralRe: Need help with understanding Reflection Pin
madhatter84gn15-Jan-09 8:06
madhatter84gn15-Jan-09 8:06 
Question[Message Deleted] Pin
hkjghkj115-Jan-09 6:01
hkjghkj115-Jan-09 6:01 
AnswerRe: No background, just *.png with shadow Pin
Henry Minute15-Jan-09 6:38
Henry Minute15-Jan-09 6:38 
QuestionData Grid View Pin
Michael Bookatz15-Jan-09 5:41
Michael Bookatz15-Jan-09 5:41 
AnswerRe: Data Grid View Pin
EliottA15-Jan-09 5:43
EliottA15-Jan-09 5:43 
GeneralRe: Data Grid View Pin
Michael Bookatz15-Jan-09 5:48
Michael Bookatz15-Jan-09 5:48 
GeneralRe: Data Grid View Pin
Douglas Troy15-Jan-09 8:36
Douglas Troy15-Jan-09 8:36 
QuestionHi adding data's to datatable, Pin
Hema Bairavan15-Jan-09 5:37
Hema Bairavan15-Jan-09 5:37 
GeneralRe: Hi adding data's to datatable, Pin
nelsonpaixao15-Jan-09 5:56
nelsonpaixao15-Jan-09 5:56 
GeneralRe: Hi adding data's to datatable, Pin
Hema Bairavan15-Jan-09 6:04
Hema Bairavan15-Jan-09 6:04 
GeneralRe: Hi adding data's to datatable, Pin
Henry Minute15-Jan-09 6:43
Henry Minute15-Jan-09 6:43 
GeneralRe: Hi adding data's to datatable, Pin
nelsonpaixao15-Jan-09 15:58
nelsonpaixao15-Jan-09 15:58 
QuestionPhilisophical question Pin
Gary Wheeler15-Jan-09 4:38
Gary Wheeler15-Jan-09 4:38 
AnswerRe: Philisophical question [modified] Pin
Douglas Troy15-Jan-09 5:03
Douglas Troy15-Jan-09 5:03 
GeneralRe: Philisophical question Pin
S. Senthil Kumar16-Jan-09 4:32
S. Senthil Kumar16-Jan-09 4:32 
AnswerRe: Philisophical question Pin
#realJSOP15-Jan-09 5:50
mve#realJSOP15-Jan-09 5:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.